View Javadoc

1   /*
2    * Copyright (c) 2005, The K-Wf Grid Consortium
3    * Fraunhofer Institute for Computer Architecture and Software Technology
4    * See http://www.kwfgrid.eu and http://www.first.fraunhofer.de for more details.
5    */
6   package net.kwfgrid.gworkflowdl.protocol.structure;
7   
8   import net.kwfgrid.gworkflowdl.protocol.calls.OperationClassRemoveOperationCandidate;
9   import net.kwfgrid.gworkflowdl.protocol.calls.OperationClassSetOperationCandidates;
10  import net.kwfgrid.gworkflowdl.protocol.calls.OperationClassSetName;
11  import net.kwfgrid.gworkflowdl.protocol.calls.OperationClassAddOperationCandidate;
12  import net.kwfgrid.gworkflowdl.protocol.util.StructureUtils;
13  import net.kwfgrid.gworkflowdl.protocol.xml.OperationClassNamespace;
14  import net.kwfgrid.gworkflowdl.structure.OperationCandidate;
15  import net.kwfgrid.gworkflowdl.structure.OperationClass;
16  
17  /***
18   * Protocol implementation of operationClass.
19   */
20  public class ProtocolOperationClass extends ProtocolChildOwls implements OperationClass, OperationClassNamespace {
21      /***
22       * The namespace of this object. Used for event notification.
23       */
24      public static final String NAMESPACE = OPERATIONCLASS_NS;
25      /***
26       * The name of this object. Used for event notification.
27       */
28      public static final String NAME = "operationClass";
29      /***
30       * The name of the of the owl children of this object. Used for event notification.
31       */
32      public static final String NAME_OWL = "owl";
33  
34      protected OperationClass _delegate;
35  
36      protected ProtocolOperationClass(OperationClass delegate) {
37          super(delegate);
38          _delegate = delegate;
39      }
40  
41      /// ----------------------------------------------------------------------------------------------------
42  
43      public String getOwlNamespace() {
44          return NAMESPACE;
45      }
46  
47      public String getOwlName() {
48          return NAME_OWL;
49      }
50  
51      /// 
52      /// Standard Set API
53      /// ....................................................................................................
54  
55      /***
56       * Set the name attribute of this operation class.
57       */
58      public void setName(String name) {
59          getMethodCallStrategy().execute(new OperationClassSetName(this, name));
60      }
61  
62      /***
63       * Set the candidates of this operation class.
64       *
65       * @param ocs
66       */
67      public void setOperationCandidates(OperationCandidate[] ocs) {
68          getMethodCallStrategy().execute(new OperationClassSetOperationCandidates(this, (ProtocolOperationCandidate[]) StructureUtils.castArray(ProtocolOperationCandidate.class, ocs)));
69      }
70  
71      /***
72       * Remove the i-th concrete operation candidate from operations list.
73       *
74       * @param i The index of the concrete operation.
75       */
76      public void removeOperationCandidate(int i) {
77          getMethodCallStrategy().execute(new OperationClassRemoveOperationCandidate(this, i));
78      }
79  
80      /***
81       * Add an additional concrete operation to the candidates.
82       *
83       * @param operation The concrete operation.
84       */
85      public void addOperationCandidate(OperationCandidate operationCandidate) {
86          getMethodCallStrategy().execute(new OperationClassAddOperationCandidate(this, (ProtocolOperationCandidate) operationCandidate));
87      }
88  
89      ///
90      /// Set API called Protocol internally
91      /// ....................................................................................................
92  
93      /***
94       * This method is only to be used by the protocol.
95       */
96      public void __setName(String name) {
97          _delegate.setName(name);
98          firePropertyChanged(NAMESPACE,  "name", name);
99      }
100 
101     /***
102      * This method is only to be used by the protocol.
103      */
104     public void __setOperationCandidates(ProtocolOperationCandidate[] operationCandidates) {
105         OperationCandidate[] old = _delegate.getOperationCandidates();
106         _delegate.setOperationCandidates(operationCandidates);
107         if (old != null && old.length > 0) {
108             StructureUtils.setParent(old, null);
109             fireObjectsRemoved(NAMESPACE, ((ProtocolOperationCandidate) old[0]).getNAME(), old);
110         }
111         if (operationCandidates != null && operationCandidates.length > 0) {
112             StructureUtils.setParent(operationCandidates, this);
113             fireObjectsAdded(NAMESPACE, (operationCandidates[0]).getNAME(), operationCandidates);
114         }
115     }
116 
117     /***
118      * This method is only to be used by the protocol.
119      */
120     public void __removeOperationCandidate(int i) {
121         if (_delegate.getOperationCandidates() == null) return;
122         ProtocolOperationCandidate old = (ProtocolOperationCandidate) _delegate.getOperationCandidates()[i];
123         _delegate.removeOperationCandidate(i);
124         old.setParent(null);
125         fireObjectRemoved(NAMESPACE, old.getNAME(), old);
126     }
127 
128     /***
129      * This method is only to be used by the protocol.
130      */
131     public void __addOperationCandidate(ProtocolOperationCandidate o) {
132         _delegate.addOperationCandidate(o);
133         o.setParent(this);
134         fireObjectAdded(NAMESPACE, o.getNAME(), o);
135     }
136 
137     ///
138     /// Get API
139     /// ....................................................................................................
140 
141     public int getOperationCount() {
142         return _delegate.getOperationCount();
143     }
144 
145     public String getName() {
146         return _delegate.getName();
147     }
148 
149     public OperationCandidate[] getOperationCandidates() {
150         return _delegate.getOperationCandidates();
151     }
152 
153     public int getAbstractionLevel() {
154         return _delegate.getAbstractionLevel();
155     }
156 
157 }