KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jbpm > bpel > xml > InvokeReader


1 package org.jbpm.bpel.xml;
2
3 import java.util.Iterator JavaDoc;
4
5 import javax.wsdl.Operation;
6 import javax.wsdl.OperationType;
7 import javax.wsdl.PortType;
8
9 import org.w3c.dom.Element JavaDoc;
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 /**
26  * @author Juan Cantú
27  * @version $Revision: 1.15 $ $Date: 2005/06/23 20:45:04 $
28  */

29 public class InvokeReader extends ActivityReader {
30
31   /**{@inheritDoc}*/
32   public Activity read(Element JavaDoc element, CompositeActivity parent) {
33     Element JavaDoc fHandlerElement = NodeUtil.getElement(element, BpelConstants.NS_BPWS, BpelConstants.ELEM_FAULT_HANDLERS );
34     Element JavaDoc 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     /*
39     WS-BPEL 11.3 Invoking Web Service Operations
40     Semantically, the specification of local fault and/or compensation handlers is equivalent target
41     the presence of an implicit scope immediately enclosing the activity and providing those
42     handlers. The name of such an implicit scope is always the same as the name of the activity
43     it encloses.
44     */

45     Scope scope = new Scope();
46     scope.setImplicit(true);
47     
48     //load standard properties
49
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 JavaDoc element) {
67     Invoke invoke = (Invoke) activity;
68     readInvoker(invoke.getInvoker(), invoke.getCompositeActivity(), element);
69   }
70   
71   public void readInvoker(Invoker invoker, CompositeActivity parent, Element JavaDoc invokeElem) {
72     // partner link
73
String JavaDoc 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     // port type
80
PortType portType = bpelReader.getPortType(invokeElem, partnerLink.getPartnerRole());
81     // operation
82
Operation operation = bpelReader.getOperation(invokeElem, portType);
83     invoker.setOperation( operation );
84     // input variable
85
VariableDefinition input = bpelReader.getVariable(invokeElem, BpelConstants.ATTR_INPUT_VARIABLE,
86         parent, operation.getInput().getMessage());
87     invoker.setInputVariable( input );
88     // output variable
89
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     // correlations
96
Element JavaDoc 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 JavaDoc correlationElemIt = NodeUtil.getElements(correlationsElem, BpelConstants.NS_BPWS, BpelConstants.ELEM_CORRELATION);
101       while (correlationElemIt.hasNext()) {
102         Element JavaDoc correlationElem = (Element JavaDoc) correlationElemIt.next();
103         Correlation correlation = bpelReader.readCorrelation(correlationElem, parent);
104         CorrelationSetDefinition set = correlation.getSet();
105         // applicability pattern
106
Pattern pattern = Pattern.valueOf(correlationElem.getAttribute(BpelConstants.ATTR_PATTERN));
107         // is pattern 'out' or 'out-in'?
108
if (pattern != Pattern.IN) {
109           bpelReader.checkVariableProperties(input, set);
110           outCorrelations.addCorrelation(correlation);
111         }
112         // is pattern 'in' or 'out-in'?
113
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