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.structure.*;
9   import net.kwfgrid.gworkflowdl.protocol.calls.*;
10  import net.kwfgrid.gworkflowdl.protocol.xml.GWDLNamespace;
11  import net.kwfgrid.gworkflowdl.protocol.util.StructureUtils;
12  
13  /***
14   * Protocol implementation of Transition.
15   */
16  public class ProtocolTransition extends AbstractChildObject implements Transition, GWDLNamespace {
17      /*** The namespace of this object. Used for event notification. */
18      public static final String NAMESPACE = GWDL_NS;
19      /*** The namespace of the properties of this object. Used for event notification. */
20      public static final String NAMESPACE_PROPERTIES = GWDL_ATTRIBUTE_NS;
21      /*** The name of this object. Used for event notification. */
22      public static final String NAME = "transition";
23      /*** The name of the ID property of this object. Used for event notification. */
24      public static final String NAME_ID = "ID";
25      /*** The name of the description property of this object. Used for event notification. */
26      public static final String NAME_DESCRIPTION = "description";
27      /*** The name of the condition children of this object. Used for event notification. */
28      public static final String NAME_CONDITION = "condition";
29  
30      protected Transition _delegate;
31  
32      protected ProtocolTransition(Transition delegate) {
33  	super();
34  	_delegate = delegate;
35  	((ProtocolProperties)_delegate.getProperties()).setParent(this);
36      }
37  
38      /// 
39      /// Standard Set API
40      /// ....................................................................................................
41      
42      public void setID(String id) { 
43  	getMethodCallStrategy().execute(new TransitionSetID(this, id));
44      }
45  
46      public void setDescription(String description) { 
47  	getMethodCallStrategy().execute(new TransitionSetDescription(this, description));
48      }
49  
50      public void setProperties(GenericProperties props) { 
51  	getMethodCallStrategy().execute(new TransitionSetProperties(this, (ProtocolProperties)props));
52      }
53  
54      public void addReadEdge(Edge edge) {
55          getMethodCallStrategy().execute(new TransitionAddReadEdge(this, (ProtocolEdge)edge));
56      }
57  
58      public void removeReadEdge(int i) {
59          getMethodCallStrategy().execute(new TransitionRemoveReadEdge(this, i));
60      }
61  
62      public void removeReadEdge(String placeID) {
63          getMethodCallStrategy().execute(new TransitionRemoveReadEdge(this, placeID));
64      }
65  
66      public void setReadEdges(Edge[] edges) {
67          getMethodCallStrategy().execute(new TransitionSetReadEdges(this, (ProtocolEdge[])StructureUtils.castArray(ProtocolEdge.class, edges)));
68      }
69  
70      public void setInEdges(Edge[] edges) {
71  	getMethodCallStrategy().execute(new TransitionSetInEdges(this, (ProtocolEdge[])StructureUtils.castArray(ProtocolEdge.class, edges)));
72      }
73  
74      public void addInEdge(Edge edge) { 
75  	getMethodCallStrategy().execute(new TransitionAddInEdge(this, (ProtocolEdge)edge));
76      }
77  
78      public void removeInEdge(int i) { 
79  	getMethodCallStrategy().execute(new TransitionRemoveInEdge(this, i));
80      }
81  
82      public void removeInEdge(String placeID) { 
83  	getMethodCallStrategy().execute(new TransitionRemoveInEdge(this, placeID));
84      }
85  
86      public void addWriteEdge(Edge edge) {
87          getMethodCallStrategy().execute(new TransitionAddWriteEdge(this, (ProtocolEdge)edge));
88      }
89  
90      public void removeWriteEdge(int i) {
91          getMethodCallStrategy().execute(new TransitionRemoveWriteEdge(this, i));
92      }
93  
94      public void removeWriteEdge(String placeID) {
95          getMethodCallStrategy().execute(new TransitionRemoveWriteEdge(this, placeID));
96      }
97  
98      public void setWriteEdges(Edge[] edges) {
99          getMethodCallStrategy().execute(new TransitionSetWriteEdges(this, (ProtocolEdge[])StructureUtils.castArray(ProtocolEdge.class, edges)));
100     }
101 
102     public void setOutEdges(Edge[] edges) {
103 	getMethodCallStrategy().execute(new TransitionSetOutEdges(this, (ProtocolEdge[])StructureUtils.castArray(ProtocolEdge.class, edges)));
104     }
105 
106     public void addOutEdge(Edge edge) { 
107 	getMethodCallStrategy().execute(new TransitionAddOutEdge(this, (ProtocolEdge)edge));
108     }
109 
110     public void removeOutEdge(int i) { 
111 	getMethodCallStrategy().execute(new TransitionRemoveOutEdge(this, i));
112     }
113 
114     public void removeOutEdge(String placeID) {
115 	getMethodCallStrategy().execute(new TransitionRemoveOutEdge(this, placeID));
116     }
117 
118     public void setConditions(String[] conditions) { 
119 	getMethodCallStrategy().execute(new TransitionSetConditions(this, conditions));
120     }
121 
122     public void addCondition(String condition) { 
123 	getMethodCallStrategy().execute(new TransitionAddCondition(this, condition));
124     }
125 
126     public void removeCondition(int i) { 
127 	getMethodCallStrategy().execute(new TransitionRemoveCondition(this, i));
128     }
129 
130     public void setOperation(Operation operation) { 
131 	getMethodCallStrategy().execute(new TransitionSetOperation(this, (ProtocolOperation)operation));
132     }
133 
134     ///
135     /// Set API called Protocol internally
136     /// ....................................................................................................
137 
138     /***
139        This method is only to be used by the protocol.        
140      */
141     public void __setID(String id) { 
142 	_delegate.setID(id);
143 	firePropertyChanged(NAMESPACE_PROPERTIES, NAME_ID, id);
144     }
145 
146     /***
147        This method is only to be used by the protocol.        
148      */
149     public void __setDescription(String description) { 
150 	_delegate.setDescription(description);
151 	firePropertyChanged(NAMESPACE_PROPERTIES, NAME_DESCRIPTION, description);
152     }
153 
154     /***
155        This method is only to be used by the protocol.        
156      */
157     public void __setProperties(ProtocolProperties props) { 
158 	ProtocolProperties old = (ProtocolProperties)_delegate.getProperties();	
159 	_delegate.setProperties(props);
160 	old.setParent(null);
161 	fireObjectRemoved(ProtocolProperties.NAMESPACE, ProtocolProperties.NAME, old);
162 	props.setParent(this);
163 	fireObjectAdded(ProtocolProperties.NAMESPACE, ProtocolProperties.NAME, props);	
164     }
165 
166     /***
167        This method is only to be used by the protocol.
168      */
169     public void __setReadEdges(ProtocolEdge[] edges) {
170 	Edge[] old = _delegate.getReadEdges();
171 	_delegate.setReadEdges(edges);
172 	if (old.length > 0) {
173 	    StructureUtils.setParent(old, null);
174 	    fireObjectsRemoved(ProtocolEdge.NAMESPACE, ProtocolEdge.NAME_READPLACE, old);
175 	}
176 	if (edges.length > 0) {
177 	    StructureUtils.setParent(edges, this);
178 	    fireObjectsAdded(ProtocolEdge.NAMESPACE, ProtocolEdge.NAME_READPLACE, edges);
179 	}
180     }
181 
182     /***
183        This method is only to be used by the protocol.
184      */
185     public void __addReadEdge(ProtocolEdge edge) {
186 	_delegate.addReadEdge(edge);
187 	((ProtocolEdge)edge).setParent(this);
188 	fireObjectAdded(ProtocolEdge.NAMESPACE, ProtocolEdge.NAME_READPLACE, edge);
189     }
190 
191     /***
192        This method is only to be used by the protocol.
193      */
194     public void __removeReadEdge(int i) {
195 	ProtocolEdge old = (ProtocolEdge)_delegate.getReadEdges()[i];
196 	_delegate.removeReadEdge(i);
197 	old.setParent(null);
198 	fireObjectRemoved(ProtocolEdge.NAMESPACE, ProtocolEdge.NAME_READPLACE, old);
199     }
200 
201     /***
202        This method is only to be used by the protocol.
203      */
204     public void __removeReadEdge(String placeID) throws NullPointerException {
205 	ProtocolEdge old = (ProtocolEdge)_delegate.getReadEdge(placeID);
206 	_delegate.removeReadEdge(placeID);
207 	old.setParent(null);
208 	fireObjectRemoved(ProtocolEdge.NAMESPACE, ProtocolEdge.NAME_READPLACE, old);
209     }
210 
211     /***
212        This method is only to be used by the protocol.        
213      */
214     public void __setInEdges(ProtocolEdge[] edges) { 
215 	Edge[] old = _delegate.getInEdges();
216 	_delegate.setInEdges(edges);
217 	if (old.length > 0) {
218 	    StructureUtils.setParent(old, null);
219 	    fireObjectsRemoved(ProtocolEdge.NAMESPACE, ProtocolEdge.NAME_INPUTPLACE, old);
220 	}
221 	if (edges.length > 0) {
222 	    StructureUtils.setParent(edges, this);
223 	    fireObjectsAdded(ProtocolEdge.NAMESPACE, ProtocolEdge.NAME_INPUTPLACE, edges);
224 	}
225     }
226 
227     /***
228        This method is only to be used by the protocol.        
229      */
230     public void __addInEdge(ProtocolEdge edge) { 
231 	_delegate.addInEdge(edge);
232 	((ProtocolEdge)edge).setParent(this);
233 	fireObjectAdded(ProtocolEdge.NAMESPACE, ProtocolEdge.NAME_INPUTPLACE, edge);
234     }
235 
236     /***
237        This method is only to be used by the protocol.        
238      */
239     public void __removeInEdge(int i) { 
240 	ProtocolEdge old = (ProtocolEdge)_delegate.getInEdges()[i];
241 	_delegate.removeInEdge(i);
242 	old.setParent(null);
243 	fireObjectRemoved(ProtocolEdge.NAMESPACE, ProtocolEdge.NAME_INPUTPLACE, old);
244     }
245 
246     /***
247        This method is only to be used by the protocol.        
248      */
249     public void __removeInEdge(String placeID) throws NullPointerException { 
250 	ProtocolEdge old = (ProtocolEdge)_delegate.getInEdge(placeID);
251 	_delegate.removeInEdge(placeID);
252 	old.setParent(null);
253 	fireObjectRemoved(ProtocolEdge.NAMESPACE, ProtocolEdge.NAME_INPUTPLACE, old);
254     }
255 
256     /***
257        This method is only to be used by the protocol.
258      */
259     public void __setWriteEdges(ProtocolEdge[] edges) {
260 	Edge[] old = _delegate.getWriteEdges();
261 	_delegate.setWriteEdges(edges);
262 	if (old.length > 0) {
263 	    StructureUtils.setParent(old, null);
264 	    fireObjectsRemoved(ProtocolEdge.NAMESPACE, ProtocolEdge.NAME_WRITEPLACE, old);
265 	}
266 	if (edges.length > 0) {
267 	    StructureUtils.setParent(edges, this);
268 	    fireObjectsAdded(ProtocolEdge.NAMESPACE, ProtocolEdge.NAME_WRITEPLACE, edges);
269 	}
270     }
271 
272     /***
273        This method is only to be used by the protocol.
274      */
275     public void __addWriteEdge(ProtocolEdge edge) {
276 	_delegate.addWriteEdge(edge);
277 	((ProtocolEdge)edge).setParent(this);
278 	fireObjectAdded(ProtocolEdge.NAMESPACE, ProtocolEdge.NAME_WRITEPLACE, edge);
279     }
280 
281     /***
282        This method is only to be used by the protocol.
283      */
284     public void __removeWriteEdge(int i) {
285 	ProtocolEdge old = (ProtocolEdge)_delegate.getWriteEdges()[i];
286 	_delegate.removeWriteEdge(i);
287 	old.setParent(null);
288 	fireObjectRemoved(ProtocolEdge.NAMESPACE, ProtocolEdge.NAME_WRITEPLACE, old);
289     }
290 
291     /***
292        This method is only to be used by the protocol.
293      */
294     public void __removeWriteEdge(String placeID) throws NullPointerException {
295 	ProtocolEdge old = (ProtocolEdge)_delegate.getWriteEdge(placeID);
296 	_delegate.removeWriteEdge(placeID);
297 	old.setParent(null);
298 	fireObjectRemoved(ProtocolEdge.NAMESPACE, ProtocolEdge.NAME_WRITEPLACE, old);
299     }
300 
301 
302     /***
303        This method is only to be used by the protocol.        
304      */
305     public void __setOutEdges(ProtocolEdge[] edges) { 
306 	Edge[] old = _delegate.getOutEdges();
307 	_delegate.setOutEdges(edges);
308 	if (old.length > 0) {
309 	    StructureUtils.setParent(old, null);
310 	    fireObjectsRemoved(ProtocolEdge.NAMESPACE, ProtocolEdge.NAME_OUTPUTPLACE, old);
311 	}
312 	if (edges.length > 0) {
313 	    StructureUtils.setParent(edges, this);
314 	    fireObjectsAdded(ProtocolEdge.NAMESPACE, ProtocolEdge.NAME_OUTPUTPLACE, edges);
315 	}
316     }
317 
318     /***
319        This method is only to be used by the protocol.        
320      */
321     public void __addOutEdge(ProtocolEdge edge) { 
322 	_delegate.addOutEdge(edge);
323 	((ProtocolEdge)edge).setParent(this);
324 	fireObjectAdded(ProtocolEdge.NAMESPACE, ProtocolEdge.NAME_OUTPUTPLACE, edge);
325     }
326 
327     /***
328        This method is only to be used by the protocol.        
329      */
330     public void __removeOutEdge(int i) { 
331 	ProtocolEdge old = (ProtocolEdge)_delegate.getOutEdges()[i];
332 	_delegate.removeOutEdge(i);
333 	old.setParent(null);
334 	fireObjectRemoved(ProtocolEdge.NAMESPACE, ProtocolEdge.NAME_OUTPUTPLACE, old);
335     }
336 
337     /***
338        This method is only to be used by the protocol.        
339      */
340     public void __removeOutEdge(String placeID) { 
341 	ProtocolEdge old = (ProtocolEdge)_delegate.getOutEdge(placeID);
342 	_delegate.removeOutEdge(placeID);
343 	old.setParent(null);	
344 	fireObjectRemoved(ProtocolEdge.NAMESPACE, ProtocolEdge.NAME_OUTPUTPLACE, old);
345     }
346 
347     /***
348        This method is only to be used by the protocol.        
349      */
350     public void __setConditions(String[] conditions) { 
351 	String[] old = _delegate.getConditions();
352 	_delegate.setConditions(conditions);	
353 	if (old.length > 0) {
354 	    fireObjectsRemoved(NAMESPACE, NAME_CONDITION, old);
355 	}
356 	if (conditions.length > 0) {
357 	    fireObjectsAdded(NAMESPACE, NAME_CONDITION, conditions);
358 	}
359     }
360 
361     /***
362        This method is only to be used by the protocol.        
363      */
364     public void __addCondition(String condition) { 
365 	_delegate.addCondition(condition);
366 	fireObjectAdded(NAMESPACE, NAME_CONDITION, condition);
367     }
368 
369     /***
370        This method is only to be used by the protocol.        
371      */
372     public void __removeCondition(int i) { 
373 	String old = _delegate.getConditions()[i];
374 	_delegate.removeCondition(i);
375 	fireObjectRemoved(NAMESPACE, NAME_CONDITION, old);
376     }
377 
378     /***
379        This method is only to be used by the protocol.        
380      */
381     public void __setOperation(ProtocolOperation operation) { 
382 	ProtocolOperation old = (ProtocolOperation)_delegate.getOperation();
383 	_delegate.setOperation(operation);
384 	if (old!=null) {
385 	    old.setParent(null);
386 	    fireObjectRemoved(ProtocolOperation.NAMESPACE, ProtocolOperation.NAME, old);
387 	}
388 	if (operation!=null) {
389 	    operation.setParent(this);
390 	    fireObjectAdded(ProtocolOperation.NAMESPACE, ProtocolOperation.NAME, operation);
391 	}
392     }
393 
394     ///
395     /// Get API and additional Methods.
396     /// ....................................................................................................
397 
398     public String getID() { 
399 	return _delegate.getID();
400     }
401 
402     public String getDescription() { 
403 	return _delegate.getDescription();
404     }
405 
406     public GenericProperties getProperties() { 
407 	return _delegate.getProperties();
408     }
409 
410     public Edge[] getReadEdges() {
411         return _delegate.getReadEdges();
412     }
413 
414     public Edge[] getInEdges() {
415 	return _delegate.getInEdges();
416     }
417 
418     public Edge[] getWriteEdges() {
419         return _delegate.getWriteEdges();
420     }
421 
422     public Edge[] getOutEdges() {
423 	return _delegate.getOutEdges();
424     }
425 
426     public Operation getOperation() { 
427 	return _delegate.getOperation();
428     }
429 
430     public String[] getConditions() { 
431 	return _delegate.getConditions();
432     }
433 
434     public void setStatus(int status) { 
435 	_delegate.setStatus(status);
436     }
437 
438     public int getStatus() { 
439 	return _delegate.getStatus();
440     }
441 
442     public Edge getInEdge(String placeID) { 
443 	return _delegate.getInEdge(placeID);
444     }
445 
446     public Edge getReadEdge(String placeID) {
447         return _delegate.getReadEdge(placeID);
448     }
449 
450     public Edge getWriteEdge(String placeID) {
451         return _delegate.getWriteEdge(placeID);
452     }
453 
454     public Edge getOutEdge(String placeID) {
455 	return _delegate.getOutEdge(placeID);
456     }
457 
458     public int getAbstractionLevel() { 
459 	return _delegate.getAbstractionLevel();
460     }
461 
462     public boolean isEnabled() { 
463 	return _delegate.isEnabled();
464     }
465 }