1 package org.jbpm.bpel.def; 2 3 import org.jbpm.graph.def.Transition; 4 5 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 name) { 21 super(name); 22 } 23 24 public boolean isChildInitial(Activity activity) { 25 return activity.equals(getNodes().get(0)); 26 } 27 28 30 protected void addImplicitTransitions(Activity activity) { 31 if(nodes == null || nodes.size() == 0) { 32 start.connect(activity); 34 } 35 else { 36 Activity last = (Activity) nodes.get(nodes.size() - 1); 38 Transition leavingTransition = last.getDefaultLeavingTransition(); 39 end.removeArrivingTransition( leavingTransition ); 40 activity.addArrivingTransition( leavingTransition ); 41 } 42 43 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 public void reorderNode(int oldIndex, int newIndex) { 62 if (nodes!=null) { 63 Activity reorderedObject = (Activity) nodes.remove(oldIndex); 65 removeImplicitTransitions(reorderedObject); 66 67 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 ("no collection present"); 79 } 80 } 81 82 83 public void accept(BpelVisitor visitor) { 84 visitor.visit(this); 85 } 86 } | Popular Tags |