1 package org.jbpm.bpel.def; 2 3 import java.util.HashMap ; 4 import java.util.Map ; 5 6 import org.apache.commons.logging.Log; 7 import org.apache.commons.logging.LogFactory; 8 import org.w3c.dom.Element ; 9 10 import org.jbpm.graph.exe.ExecutionContext; 11 import org.jbpm.graph.exe.Token; 12 13 import org.jbpm.bpel.data.def.VariableDefinition; 14 import org.jbpm.bpel.exe.EventInstance; 15 import org.jbpm.bpel.exe.ScopeInstance; 16 import org.jbpm.bpel.exe.state.ActiveState; 17 import org.jbpm.bpel.service.def.CorrelationSetDefinition; 18 import org.jbpm.bpel.service.def.InboundMessageActivity; 19 import org.jbpm.bpel.service.def.Receiver; 20 21 25 public class MessageHandler extends ScopeHandler implements InboundMessageActivity { 26 27 public MessageHandler() { 28 super(); 29 } 30 31 private static final Log log = LogFactory.getLog(MessageHandler.class); 32 private static final long serialVersionUID = 1L; 33 34 private Receiver receiver; 35 private VariableDefinition variable; 36 private Map correlationSets = new HashMap (); 37 38 public void messageReceived(Receiver receiver, Element element, Token token) { 39 ScopeInstance scopeInstance = ScopeInstance.get(token); 40 if (!scopeInstance.getState().equals(ActiveState.NORMAL_PROCESSING)) { 41 log.error("Incoming events are only accepted when a scope instance is normally processing"); 42 return; 43 } 44 45 Token child = new Token(token, Scope.EVENT_TOKEN + token.getChildren().size()); 46 receiver.getVariable().createInstance(child); 48 EventInstance.create(child); 50 receiver.readMessage(element, child); 52 53 execute(new ExecutionContext(child)); 54 } 55 56 58 59 public VariableDefinition findVariable(String varName) { 60 return variable != null && 61 variable.getName().equals(varName) ? variable 62 : super.findVariable(varName); 63 } 64 65 66 public CorrelationSetDefinition findCorrelationSet(String csName) { 67 CorrelationSetDefinition cs = getCorrelationSet(csName); 68 return cs != null ? cs : super.findCorrelationSet(csName); 69 } 70 71 73 public void addCorrelationSet(CorrelationSetDefinition correlation) { 74 correlationSets.put(correlation.getName(), correlation); 75 } 76 77 82 public CorrelationSetDefinition getCorrelationSet(String correlationSetName) { 83 return (CorrelationSetDefinition) correlationSets.get(correlationSetName); 84 } 85 86 public void setCorrelationSets(Map correlationSets) { 87 this.correlationSets = correlationSets; 88 } 89 90 public Receiver getReceiver() { 91 return receiver; 92 } 93 94 public void setReceiver(Receiver receiver) { 95 this.receiver = receiver; 96 } 97 98 public VariableDefinition getVariableDefinition() { 99 return variable; 100 } 101 102 public void setVariableDefinition(VariableDefinition variable) { 103 this.variable = variable; 104 } 105 } 106 | Popular Tags |