1 package org.jbpm.bpel.def; 2 3 import java.util.Collection ; 4 import java.util.Iterator ; 5 import java.util.Map ; 6 7 import org.jbpm.graph.exe.ExecutionContext; 8 import org.jbpm.graph.exe.Token; 9 10 import org.jbpm.bpel.service.def.Receiver; 11 12 16 class ProcessInstanceTrigger implements BpelVisitor { 17 18 private final ExecutionContext context; 19 private final Receiver trigger; 20 21 ProcessInstanceTrigger(ExecutionContext context, Receiver trigger) { 22 this.context = context; 23 this.trigger = trigger; 24 } 25 26 27 public void visit(BpelDefinition process) { 28 process.getRoot().accept(this); 29 } 30 31 32 public void visit(Empty empty) { 33 validateNonInitial(empty); 34 } 35 36 37 public void visit(Receive receive) { 38 if(!trigger.equals( receive.getReceiver() )) { 39 receive.enter(context); 40 } 41 else if( receive.isCreateInstance() ) { 42 receive.leave(context); 43 } 44 else { 45 throw new RuntimeException ( "receive " + receive.getFullyQualifiedName() + " can't create instances" ); 46 } 47 } 48 49 50 public void visit(Reply reply) { 51 validateNonInitial(reply); 52 } 53 54 55 public void visit(Invoke invoke) { 56 validateNonInitial(invoke); 57 } 58 59 60 public void visit(Assign assign) { 61 validateNonInitial(assign); 62 } 63 64 65 public void visit(Throw throwActivity) { 66 validateNonInitial(throwActivity); 67 } 68 69 70 public void visit(Exit exit) { 71 validateNonInitial(exit); 72 } 73 74 75 public void visit(Wait wait) { 76 validateNonInitial(wait); 77 } 78 79 80 public void visit(Sequence sequence) { 81 ((Activity)sequence.getNodes().get(0)).accept(this); 82 } 83 84 85 public void visit(Switch switchActivity) { 86 validateNonInitial(switchActivity); 87 } 88 89 90 public void visit(While whileActivity) { 91 validateNonInitial(whileActivity); 92 } 93 94 95 public void visit(Pick pick) { 96 Collection onMessages = pick.getOnMessages(); 97 98 if(!onMessages.contains(trigger)) { 99 pick.getStart().enter(context); 100 } 101 else if( pick.isCreateInstance() ){ 102 pick.pickPath(context, pick.getOnMessage(trigger)); 103 } 104 else { 105 throw new RuntimeException ("pick " + pick.getFullyQualifiedName() + " can't create instances"); 106 } 107 } 108 109 110 public void visit(Flow flow) { 111 Token token = context.getToken(); 112 if(flow.createVariableContext()) token = new Token(token, flow.getName()); 113 flow.initLinks(token); 114 Map flowTokens = flow.createFlowTokens(token); 116 Iterator iter = flowTokens.keySet().iterator(); 118 while( iter.hasNext() && !token.hasEnded()) { 120 Activity child = (Activity) iter.next(); 121 Token forkedToken = (Token) flowTokens.get(child); 122 ExecutionContext childExecutionContext = new ExecutionContext(forkedToken); 123 child.accept(new ProcessInstanceTrigger(childExecutionContext, trigger)); 124 } 125 } 126 127 public void visit(Scope scope) { 128 validateNonInitial(scope); 129 } 130 131 132 public void visit(Compensate compensate) { 133 throw new RuntimeException ("activity " + compensate.getFullyQualifiedName() + " can't be initial"); 134 } 135 136 137 public void visit(Rethrow rethrow) { 138 throw new RuntimeException ("activity " + rethrow.getFullyQualifiedName() + " can't be initial"); 139 } 140 141 142 public void visit(Validate validate) { 143 validateNonInitial(validate); 144 } 145 146 147 private static void validateNonInitial(Activity activity) { 148 if(activity.getTargets().size() == 0) { 149 throw new RuntimeException ("activity " + activity.getFullyQualifiedName() + " can't be initial"); 150 } 151 } 152 } | Popular Tags |