KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jbpm > bpel > def > Sequence


1 package org.jbpm.bpel.def;
2
3 import org.jbpm.graph.def.Transition;
4
5 /**
6  * A sequence activity contains one or more activities that are performed sequentially,
7  * in the order in which they are listed within the <sequence> element.
8  * @see "WS-BPEL 2.0 &sect;12.1"
9  * @author Juan Cantú
10  * @version $Revision: 1.4 $ $Date: 2005/06/03 00:13:42 $
11  */

12 public class Sequence extends StructuredActivity {
13
14   private static final long serialVersionUID = 1L;
15
16   public Sequence() {
17     super();
18   }
19   
20   public Sequence(String JavaDoc name) {
21     super(name);
22   }
23   
24   public boolean isChildInitial(Activity activity) {
25     return activity.equals(getNodes().get(0));
26   }
27   
28   // children management /////////////////////////////////////////////////////////////////////////////
29

30   protected void addImplicitTransitions(Activity activity) {
31     if(nodes == null || nodes.size() == 0) {
32       //connect the sequence start to the new one
33
start.connect(activity);
34     }
35     else {
36       //connect the last child of the sequence with the new one
37
Activity last = (Activity) nodes.get(nodes.size() - 1);
38       Transition leavingTransition = last.getDefaultLeavingTransition();
39       end.removeArrivingTransition( leavingTransition );
40       activity.addArrivingTransition( leavingTransition );
41     }
42     
43     //connect the new node with the sequence end
44
activity.connect(end);
45   }
46   
47   protected void removeImplicitTransitions(Activity activity) {
48     Transition leaving = activity.getDefaultLeavingTransition();
49     Transition arriving = activity.getDefaultArrivingTransition();
50     
51     Activity successor = (Activity) leaving.getTo();
52
53     activity.removeArrivingTransition(arriving);
54     activity.removeLeavingTransition(leaving);
55     
56     successor.removeArrivingTransition(leaving);
57     successor.addArrivingTransition(arriving);
58   }
59   
60   // javadoc description in NodeCollection
61
public void reorderNode(int oldIndex, int newIndex) {
62     if (nodes!=null) {
63       //remove the node from old position and remove its incoming and outgoing connections
64
Activity reorderedObject = (Activity) nodes.remove(oldIndex);
65       removeImplicitTransitions(reorderedObject);
66       
67       //add the node to the new position and connect to its new predecessors and successors
68
Activity predecessor = (newIndex == 0 ? start : (Activity) nodes.get(newIndex - 1) );
69       Activity successor = (newIndex == nodes.size() ? end : (Activity) nodes.get(newIndex) );
70       
71       Transition leaving = predecessor.getDefaultLeavingTransition();
72       successor.removeArrivingTransition( leaving );
73       reorderedObject.addArrivingTransition( leaving );
74       reorderedObject.connect(successor);
75       
76       nodes.add(newIndex, reorderedObject);
77     } else {
78       throw new IndexOutOfBoundsException JavaDoc("no collection present");
79     }
80   }
81
82   /**{@inheritDoc}*/
83   public void accept(BpelVisitor visitor) {
84     visitor.visit(this);
85   }
86 }
Popular Tags