View Javadoc

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  * *** Centre de Calcul de l'IN2P3 - Lyon (France) ***
13  * ***             http://cc.in2p3.fr/             ***
14  * ***************************************************
15  * File:   ContextAttributes
16  * Author: Sylvain Reynaud (sreynaud@in2p3.fr)
17  * Date:   23 janv. 2008
18  * ***************************************************
19  * Description:                                      */
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  
31      /** constructor */
32      ContextAttributes(ContextImpl context) {
33          m_type = context._addAttribute(new ScalarAttributeImpl<String>(
34                  Context.TYPE,
35                  "type of context",
36                  MetricMode.Final,
37                  MetricType.String,
38                  "Unknown"));
39          m_urlPrefix = context._addAttribute(new UrlPrefixAttribute());
40          m_baseUrlIncludes = (BaseUrlPatternAttribute) context._addVectorAttribute(new BaseUrlPatternAttribute(
41                  ContextImpl.BASE_URL_INCLUDES,
42                  "array of URL patterns accepted for this context"));
43          m_baseUrlExcludes = (BaseUrlPatternAttribute) context._addVectorAttribute(new BaseUrlPatternAttribute(
44                  ContextImpl.BASE_URL_EXCLUDES,
45                  "array of URL patterns rejected for this context"));
46          m_jobServiceAttributes = (JobServiceConfigAttribute) context._addVectorAttribute(new JobServiceConfigAttribute());
47          m_dataServiceAttributes = (DataServiceConfigAttribute) context._addVectorAttribute(new DataServiceConfigAttribute());
48      }
49  
50      /** clone */
51      public ContextAttributes clone() throws CloneNotSupportedException {
52          ContextAttributes clone = (ContextAttributes) super.clone();
53          clone.m_type = m_type;
54          clone.m_urlPrefix = m_urlPrefix;
55          clone.m_baseUrlIncludes = m_baseUrlIncludes;
56          clone.m_baseUrlExcludes = m_baseUrlExcludes;
57          clone.m_jobServiceAttributes = m_jobServiceAttributes;
58          clone.m_dataServiceAttributes = m_dataServiceAttributes;
59          return clone;
60      }
61  
62      public AttributeScalar getScalarAttribute(String key) throws DoesNotExistException, IncorrectStateException {
63          if (m_type.getKey().equals(key)) {
64              return m_type;
65          } else if (m_urlPrefix.getKey().equals(key)) {
66              return m_urlPrefix;
67          } else if (m_baseUrlIncludes.getKey().equals(key)) {
68              throw new IncorrectStateException("Operation not allowed on vector attribute: "+key);
69          } else if (m_baseUrlExcludes.getKey().equals(key)) {
70              throw new IncorrectStateException("Operation not allowed on vector attribute: "+key);
71          } else if (m_jobServiceAttributes.getKey().equals(key)) {
72              throw new IncorrectStateException("Operation not allowed on vector attribute: "+key);
73          } else if (m_dataServiceAttributes.getKey().equals(key)) {
74              throw new IncorrectStateException("Operation not allowed on vector attribute: "+key);
75          } else {
76              throw new DoesNotExistException("[INTERNAL ERROR] This exception should have been catched");
77          }
78      }
79  
80      public AttributeVector getVectorAttribute(String key) throws DoesNotExistException, IncorrectStateException {
81          if (m_type.getKey().equals(key)) {
82              throw new IncorrectStateException("Operation not allowed on scalar attribute: "+key);
83          } else if (m_urlPrefix.getKey().equals(key)) {
84              throw new IncorrectStateException("Operation not allowed on scalar attribute: "+key);
85          } else if (m_baseUrlIncludes.getKey().equals(key)) {
86              return m_baseUrlIncludes;
87          } else if (m_baseUrlExcludes.getKey().equals(key)) {
88              return m_baseUrlExcludes;
89          } else if (m_jobServiceAttributes.getKey().equals(key)) {
90              return m_jobServiceAttributes;
91          } else if (m_dataServiceAttributes.getKey().equals(key)) {
92              return m_dataServiceAttributes;
93          } else {
94              throw new DoesNotExistException("[INTERNAL ERROR] This exception should have been catched");
95          }
96      }
97  }