View Javadoc

1   package fr.in2p3.jsaga.impl.resource.description;
2   
3   import fr.in2p3.jsaga.impl.attributes.AbstractAttributesImpl;
4   
5   import org.apache.log4j.Logger;
6   import org.ogf.saga.error.AuthenticationFailedException;
7   import org.ogf.saga.error.AuthorizationFailedException;
8   import org.ogf.saga.error.BadParameterException;
9   import org.ogf.saga.error.DoesNotExistException;
10  import org.ogf.saga.error.IncorrectStateException;
11  import org.ogf.saga.error.NoSuccessException;
12  import org.ogf.saga.error.NotImplementedException;
13  import org.ogf.saga.error.PermissionDeniedException;
14  import org.ogf.saga.error.TimeoutException;
15  import org.ogf.saga.resource.description.ResourceDescription;
16  
17  import java.util.ArrayList;
18  import java.util.Map.Entry;
19  import java.util.Collection;
20  import java.util.Properties;
21  
22  /* ***************************************************
23   * *** Centre de Calcul de l'IN2P3 - Lyon (France) ***
24   * ***             http://cc.in2p3.fr/             ***
25   * ***************************************************/
26  public class AbstractResourceDescriptionImpl extends AbstractAttributesImpl implements ResourceDescription {
27      
28      private Logger m_logger = Logger.getLogger(AbstractResourceDescriptionImpl.class);
29  //    protected ResourceDescriptionAttributes m_attributes;
30      private Collection<String> m_scalarAttributes;
31      private Collection<String> m_vectorAttributes;
32      
33      /** constructor for ResourceFactory.createDescription() */
34      public AbstractResourceDescriptionImpl() {
35          super(null, true);      //isExtensible=true
36  //        m_attributes = new ResourceDescriptionAttributes(this);
37          m_scalarAttributes = this.getScalarAttributes();
38          m_vectorAttributes = this.getVectorAttributes();
39      }
40  
41      protected Collection<String> getScalarAttributes() {
42          Collection<String> c = new ArrayList<String>();
43          c.add(ResourceDescription.TYPE);
44          c.add(ResourceDescription.PLACEMENT);
45          c.add(ResourceDescription.DYNAMIC);
46          c.add(ResourceDescription.START);
47          c.add(ResourceDescription.END);
48          c.add(ResourceDescription.DURATION);
49          return c;
50      }
51  
52      protected Collection<String> getVectorAttributes() {
53          Collection<String> c = new ArrayList<String>();
54          c.add(ResourceDescription.TEMPLATE);
55          return c;
56      }
57      /** constructor for ResourceManager.getTemplate() */
58      public AbstractResourceDescriptionImpl(Properties properties) {
59          super(null, true);      //isExtensible=true
60          m_scalarAttributes = this.getScalarAttributes();
61          m_vectorAttributes = this.getVectorAttributes();
62          for (Entry<Object, Object> entrySet: properties.entrySet()) {
63              try {
64                  if (entrySet.getValue() instanceof String) {
65                      this.setAttribute((String)entrySet.getKey(), (String)entrySet.getValue());
66                  } else if (entrySet.getValue() instanceof String[]) {
67                      this.setVectorAttribute((String)entrySet.getKey(), (String[])entrySet.getValue());
68                  }
69              } catch (Exception e) {
70                  m_logger.error("Could not setAtrribute", e);
71              }
72          }
73  //        m_attributes = new ResourceDescriptionAttributes(this);
74  //        if (properties.containsKey(ResourceDescription.TEMPLATE)) {
75  //            if (properties.get(ResourceDescription.TEMPLATE) instanceof String) {
76  //                m_attributes.m_template.setObjects(new String[]{(String)properties.get(ResourceDescription.TEMPLATE)});
77  //            } else {
78  //                m_attributes.m_template.setObjects((String[])properties.get(ResourceDescription.TEMPLATE));
79  //            }
80  //        }
81  //        m_attributes.m_placement.setObject(properties.getProperty(ResourceDescription.PLACEMENT));
82      }
83  
84      @Override
85      public void setAttribute(String key, String value) throws NotImplementedException, AuthenticationFailedException, AuthorizationFailedException, PermissionDeniedException, IncorrectStateException, BadParameterException, DoesNotExistException, TimeoutException, NoSuccessException {
86          if (m_vectorAttributes.contains(key)) {
87              throw new IncorrectStateException("Attribute is a vector attribute: "+key);
88          }
89          super.setAttribute(key, value);
90      }
91  
92      @Override
93      public String getAttribute(String key) throws NotImplementedException, AuthenticationFailedException, AuthorizationFailedException, PermissionDeniedException, IncorrectStateException, DoesNotExistException, TimeoutException, NoSuccessException {
94          if (m_vectorAttributes.contains(key)) {
95              throw new IncorrectStateException("Attribute is a vector attribute: "+key);
96          }
97          return super.getAttribute(key);
98      }
99  
100     @Override
101     public void setVectorAttribute(String key, String[] values) throws NotImplementedException, AuthenticationFailedException, AuthorizationFailedException, PermissionDeniedException, IncorrectStateException, BadParameterException, DoesNotExistException, TimeoutException, NoSuccessException {
102         if (m_scalarAttributes.contains(key)) {
103             throw new IncorrectStateException("Attribute is a scalar attribute: "+key);
104         }
105         super.setVectorAttribute(key, values);
106     }
107 
108     @Override
109     public String[] getVectorAttribute(String key) throws NotImplementedException, AuthenticationFailedException, AuthorizationFailedException, PermissionDeniedException, IncorrectStateException, DoesNotExistException, TimeoutException, NoSuccessException {
110         if (m_scalarAttributes.contains(key)) {
111             throw new IncorrectStateException("Attribute is a scalar attribute: "+key);
112         }
113         return super.getVectorAttribute(key);
114     }
115 }