1 package org.jbpm.bpel.xml; 2 3 import java.util.Iterator ; 4 5 import javax.wsdl.Operation; 6 import javax.wsdl.OperationType; 7 import javax.wsdl.PortType; 8 9 import org.w3c.dom.Element ; 10 11 import org.jbpm.bpel.data.def.VariableDefinition; 12 import org.jbpm.bpel.def.Activity; 13 import org.jbpm.bpel.def.CompositeActivity; 14 import org.jbpm.bpel.def.Invoke; 15 import org.jbpm.bpel.def.Scope; 16 import org.jbpm.bpel.service.def.Correlation; 17 import org.jbpm.bpel.service.def.CorrelationSetDefinition; 18 import org.jbpm.bpel.service.def.Correlations; 19 import org.jbpm.bpel.service.def.Invoker; 20 import org.jbpm.bpel.service.def.PartnerLinkDefinition; 21 import org.jbpm.bpel.service.def.Correlation.Pattern; 22 import org.jbpm.bpel.xml.util.NodeUtil; 23 import org.jbpm.jpdl.xml.Problem; 24 25 29 public class InvokeReader extends ActivityReader { 30 31 32 public Activity read(Element element, CompositeActivity parent) { 33 Element fHandlerElement = NodeUtil.getElement(element, BpelConstants.NS_BPWS, BpelConstants.ELEM_FAULT_HANDLERS ); 34 Element cHandlerElement = NodeUtil.getElement(element, BpelConstants.NS_BPWS, BpelConstants.ELEM_COMPENSATION_HANDLER ); 35 36 if( cHandlerElement == null && fHandlerElement == null ) return super.read(element, parent); 37 38 45 Scope scope = new Scope(); 46 scope.setImplicit(true); 47 48 readStandardProperties(element, scope, parent); 50 51 Invoke invoke = new Invoke(); 52 invoke.setName(scope.getName()); 53 scope.setRoot(invoke); 54 readInvoker(invoke.getInvoker(), scope, element); 55 56 if( cHandlerElement != null ) bpelReader.readHandler(cHandlerElement, scope, Scope.COMPENSATION); 57 if( fHandlerElement != null ) bpelReader.readFaultHandlers(fHandlerElement, scope); 58 59 return scope; 60 } 61 62 protected Activity createActivity() { 63 return new Invoke(); 64 } 65 66 public void readActivity(Activity activity, Element element) { 67 Invoke invoke = (Invoke) activity; 68 readInvoker(invoke.getInvoker(), invoke.getCompositeActivity(), element); 69 } 70 71 public void readInvoker(Invoker invoker, CompositeActivity parent, Element invokeElem) { 72 String pLinkName = invokeElem.getAttribute( BpelConstants.ATTR_PARTNER_LINK ); 74 PartnerLinkDefinition partnerLink = parent.findPartnerLink(pLinkName); 75 if(partnerLink == null) { 76 throw new BpelException("partner link not found", invokeElem); 77 } 78 invoker.setPartnerLink( partnerLink ); 79 PortType portType = bpelReader.getPortType(invokeElem, partnerLink.getPartnerRole()); 81 Operation operation = bpelReader.getOperation(invokeElem, portType); 83 invoker.setOperation( operation ); 84 VariableDefinition input = bpelReader.getVariable(invokeElem, BpelConstants.ATTR_INPUT_VARIABLE, 86 parent, operation.getInput().getMessage()); 87 invoker.setInputVariable( input ); 88 VariableDefinition output = null; 90 if (operation.getStyle().equals(OperationType.REQUEST_RESPONSE)) { 91 output = bpelReader.getVariable(invokeElem, BpelConstants.ATTR_OUTPUT_VARIABLE, 92 parent, operation.getOutput().getMessage()); 93 invoker.setOutputVariable( output ); 94 } 95 Element correlationsElem = NodeUtil.getElement(invokeElem, BpelConstants.NS_BPWS, BpelConstants.ELEM_CORRELATIONS ); 97 if (correlationsElem != null) { 98 Correlations inCorrelations = new Correlations(); 99 Correlations outCorrelations = new Correlations(); 100 Iterator correlationElemIt = NodeUtil.getElements(correlationsElem, BpelConstants.NS_BPWS, BpelConstants.ELEM_CORRELATION); 101 while (correlationElemIt.hasNext()) { 102 Element correlationElem = (Element ) correlationElemIt.next(); 103 Correlation correlation = bpelReader.readCorrelation(correlationElem, parent); 104 CorrelationSetDefinition set = correlation.getSet(); 105 Pattern pattern = Pattern.valueOf(correlationElem.getAttribute(BpelConstants.ATTR_PATTERN)); 107 if (pattern != Pattern.IN) { 109 bpelReader.checkVariableProperties(input, set); 110 outCorrelations.addCorrelation(correlation); 111 } 112 if (pattern != Pattern.OUT) { 114 if (output == null) { 115 bpelReader.getProblemHandler().add( 116 new LocalizedProblem( Problem.LEVEL_ERROR, 117 "correlation cannot apply to inbound message for one-way operation", correlationElem) ); 118 } 119 bpelReader.checkVariableProperties(output, set); 120 inCorrelations.addCorrelation(correlation); 121 } 122 } 123 invoker.setInCorrelations(inCorrelations); 124 invoker.setOutCorrelations(outCorrelations); 125 } 126 } 127 } 128 | Popular Tags |