1 package fr.in2p3.jsaga.impl.context;
2
3 import fr.in2p3.jsaga.impl.attributes.*;
4 import fr.in2p3.jsaga.impl.context.attrs.*;
5 import fr.in2p3.jsaga.impl.monitoring.MetricMode;
6 import fr.in2p3.jsaga.impl.monitoring.MetricType;
7 import org.ogf.saga.context.Context;
8 import org.ogf.saga.error.DoesNotExistException;
9 import org.ogf.saga.error.IncorrectStateException;
10
11
12
13
14
15
16
17
18
19
20
21
22
23 public class ContextAttributes implements Cloneable {
24 AttributeScalar m_type;
25 AttributeScalar m_urlPrefix;
26 BaseUrlPatternAttribute m_baseUrlIncludes;
27 BaseUrlPatternAttribute m_baseUrlExcludes;
28 JobServiceConfigAttribute m_jobServiceAttributes;
29 DataServiceConfigAttribute m_dataServiceAttributes;
30 ResourceServiceConfigAttribute m_resourceServiceAttributes;
31
32
33 ContextAttributes(ContextImpl context) {
34 m_type = context._addAttribute(new ScalarAttributeImpl<String>(
35 Context.TYPE,
36 "type of context",
37 MetricMode.Final,
38 MetricType.String,
39 "Unknown"));
40 m_urlPrefix = context._addAttribute(new UrlPrefixAttribute());
41 m_baseUrlIncludes = (BaseUrlPatternAttribute) context._addVectorAttribute(new BaseUrlPatternAttribute(
42 ContextImpl.BASE_URL_INCLUDES,
43 "array of URL patterns accepted for this context"));
44 m_baseUrlExcludes = (BaseUrlPatternAttribute) context._addVectorAttribute(new BaseUrlPatternAttribute(
45 ContextImpl.BASE_URL_EXCLUDES,
46 "array of URL patterns rejected for this context"));
47 m_jobServiceAttributes = (JobServiceConfigAttribute) context._addVectorAttribute(new JobServiceConfigAttribute());
48 m_dataServiceAttributes = (DataServiceConfigAttribute) context._addVectorAttribute(new DataServiceConfigAttribute());
49 m_resourceServiceAttributes = (ResourceServiceConfigAttribute) context._addVectorAttribute(new ResourceServiceConfigAttribute());
50 }
51
52
53 public ContextAttributes clone() throws CloneNotSupportedException {
54 ContextAttributes clone = (ContextAttributes) super.clone();
55 clone.m_type = m_type;
56 clone.m_urlPrefix = m_urlPrefix;
57 clone.m_baseUrlIncludes = m_baseUrlIncludes;
58 clone.m_baseUrlExcludes = m_baseUrlExcludes;
59 clone.m_jobServiceAttributes = m_jobServiceAttributes;
60 clone.m_dataServiceAttributes = m_dataServiceAttributes;
61 clone.m_resourceServiceAttributes = m_resourceServiceAttributes;
62 return clone;
63 }
64
65 public AttributeScalar getScalarAttribute(String key) throws DoesNotExistException, IncorrectStateException {
66 if (m_type.getKey().equals(key)) {
67 return m_type;
68 } else if (m_urlPrefix.getKey().equals(key)) {
69 return m_urlPrefix;
70 } else if (m_baseUrlIncludes.getKey().equals(key)) {
71 throw new IncorrectStateException("Operation not allowed on vector attribute: "+key);
72 } else if (m_baseUrlExcludes.getKey().equals(key)) {
73 throw new IncorrectStateException("Operation not allowed on vector attribute: "+key);
74 } else if (m_jobServiceAttributes.getKey().equals(key)) {
75 throw new IncorrectStateException("Operation not allowed on vector attribute: "+key);
76 } else if (m_dataServiceAttributes.getKey().equals(key)) {
77 throw new IncorrectStateException("Operation not allowed on vector attribute: "+key);
78 } else if (m_resourceServiceAttributes.getKey().equals(key)) {
79 throw new IncorrectStateException("Operation not allowed on vector attribute: "+key);
80 } else {
81 throw new DoesNotExistException("[INTERNAL ERROR] This exception should have been catched");
82 }
83 }
84
85 public AttributeVector getVectorAttribute(String key) throws DoesNotExistException, IncorrectStateException {
86 if (m_type.getKey().equals(key)) {
87 throw new IncorrectStateException("Operation not allowed on scalar attribute: "+key);
88 } else if (m_urlPrefix.getKey().equals(key)) {
89 throw new IncorrectStateException("Operation not allowed on scalar attribute: "+key);
90 } else if (m_baseUrlIncludes.getKey().equals(key)) {
91 return m_baseUrlIncludes;
92 } else if (m_baseUrlExcludes.getKey().equals(key)) {
93 return m_baseUrlExcludes;
94 } else if (m_jobServiceAttributes.getKey().equals(key)) {
95 return m_jobServiceAttributes;
96 } else if (m_dataServiceAttributes.getKey().equals(key)) {
97 return m_dataServiceAttributes;
98 } else if (m_resourceServiceAttributes.getKey().equals(key)) {
99 return m_resourceServiceAttributes;
100 } else {
101 throw new DoesNotExistException("[INTERNAL ERROR] This exception should have been catched");
102 }
103 }
104 }