View Javadoc

1   package fr.in2p3.jsaga.impl.job.description;
2   
3   import fr.in2p3.jsaga.adaptor.language.SAGALanguageAdaptor;
4   import fr.in2p3.jsaga.impl.attributes.AbstractAttributesImpl;
5   import org.ogf.saga.error.*;
6   import org.ogf.saga.job.JobDescription;
7   import org.w3c.dom.Document;
8   import org.w3c.dom.Element;
9   
10  import java.util.Arrays;
11  import java.util.Collection;
12  
13  /* ***************************************************
14  * *** Centre de Calcul de l'IN2P3 - Lyon (France) ***
15  * ***             http://cc.in2p3.fr/             ***
16  * ***************************************************
17  * File:   AbstractJobDescriptionImpl
18  * Author: Sylvain Reynaud (sreynaud@in2p3.fr)
19  * Date:   26 oct. 2007
20  * ***************************************************
21  * Description:                                      */
22  /**
23   *
24   */
25  public abstract class AbstractJobDescriptionImpl extends AbstractAttributesImpl implements JobDescription {
26      private Collection<String> m_scalarAttributes;
27      private Collection<String> m_vectorAttributes;
28  
29      /** constructor */
30      public AbstractJobDescriptionImpl() {
31          super(null, true);  //isExtensible=true
32          m_scalarAttributes = Arrays.asList(SAGALanguageAdaptor.OPTIONAL_PROPERTY_NAMES);
33          m_vectorAttributes = Arrays.asList(SAGALanguageAdaptor.OPTIONAL_VECTOR_PROPERTY_NAMES);
34      }
35  
36      public abstract Document getAsDocument() throws NoSuccessException;
37  
38      public Document getJSDL() throws NoSuccessException {
39          Document jobDesc = this.getAsDocument();
40  
41          // check it is JSDL
42          Element root = jobDesc.getDocumentElement();
43          if ("http://schemas.ggf.org/jsdl/2005/11/jsdl".equals(root.getNamespaceURI()) &&
44              "JobDefinition".equals(root.getLocalName()))
45          {
46              return jobDesc;
47          } else {
48              throw new NoSuccessException("[INTERNAL ERROR] Job description is not a JSDL document: "+root.getLocalName());
49          }
50      }
51  
52      @Override
53      public void setAttribute(String key, String value) throws NotImplementedException, AuthenticationFailedException, AuthorizationFailedException, PermissionDeniedException, IncorrectStateException, BadParameterException, DoesNotExistException, TimeoutException, NoSuccessException {
54          if (m_vectorAttributes.contains(key)) {
55              throw new IncorrectStateException("Attribute is a vector attribute: "+key);
56          }
57          super.setAttribute(key, value);
58      }
59  
60      @Override
61      public String getAttribute(String key) throws NotImplementedException, AuthenticationFailedException, AuthorizationFailedException, PermissionDeniedException, IncorrectStateException, DoesNotExistException, TimeoutException, NoSuccessException {
62          if (m_vectorAttributes.contains(key)) {
63              throw new IncorrectStateException("Attribute is a vector attribute: "+key);
64          }
65          return super.getAttribute(key);
66      }
67  
68      @Override
69      public void setVectorAttribute(String key, String[] values) throws NotImplementedException, AuthenticationFailedException, AuthorizationFailedException, PermissionDeniedException, IncorrectStateException, BadParameterException, DoesNotExistException, TimeoutException, NoSuccessException {
70          if (m_scalarAttributes.contains(key)) {
71              throw new IncorrectStateException("Attribute is a scalar attribute: "+key);
72          }
73          super.setVectorAttribute(key, values);
74      }
75  
76      @Override
77      public String[] getVectorAttribute(String key) throws NotImplementedException, AuthenticationFailedException, AuthorizationFailedException, PermissionDeniedException, IncorrectStateException, DoesNotExistException, TimeoutException, NoSuccessException {
78          if (m_scalarAttributes.contains(key)) {
79              throw new IncorrectStateException("Attribute is a scalar attribute: "+key);
80          }
81          return super.getVectorAttribute(key);
82      }
83  }