KickJava   Java API By Example, From Geeks To Geeks.

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


1 package org.jbpm.bpel.xml;
2
3 import java.util.ArrayList JavaDoc;
4 import java.util.List JavaDoc;
5
6 import org.w3c.dom.Attr JavaDoc;
7 import org.w3c.dom.Element JavaDoc;
8 import org.w3c.dom.NodeList JavaDoc;
9
10 import org.jbpm.bpel.data.def.Snippet;
11 import org.jbpm.bpel.data.def.VariableDefinition;
12 import org.jbpm.bpel.def.Activity;
13 import org.jbpm.bpel.def.Assign;
14 import org.jbpm.bpel.def.CompositeActivity;
15 import org.jbpm.bpel.def.Assign.Copy;
16 import org.jbpm.bpel.def.assign.FromExpression;
17 import org.jbpm.bpel.def.assign.FromLiteral;
18 import org.jbpm.bpel.def.assign.FromPartnerLink;
19 import org.jbpm.bpel.def.assign.FromProperty;
20 import org.jbpm.bpel.def.assign.ToPartnerLink;
21 import org.jbpm.bpel.def.assign.ToProperty;
22 import org.jbpm.bpel.def.assign.ToQuery;
23 import org.jbpm.bpel.xml.util.NodeUtil;
24 import org.jbpm.jpdl.xml.Problem;
25
26 /**
27  * @author Juan Cantú
28  * @version $Revision: 1.6 $ $Date: 2005/06/23 20:45:04 $
29  */

30 public class AssignReader extends ActivityReader {
31
32   public Activity createActivity() {
33     return new Assign();
34   }
35   
36   public void readActivity(Activity activity, Element JavaDoc element) {
37     Assign assign = (Assign) activity;
38
39     NodeList JavaDoc copyList = element.getElementsByTagNameNS(BpelConstants.NS_BPWS, BpelConstants.ELEM_COPY);
40     int copyCount = copyList.getLength();
41     
42     List JavaDoc copies = new ArrayList JavaDoc(copyCount);
43     
44     for(int i = 0; i < copyCount; i++) {
45       Element JavaDoc copyElement = (Element JavaDoc) copyList.item(i);
46       Assign.Copy copy = new Assign.Copy();
47
48       Element JavaDoc fromElement = NodeUtil.getElement(copyElement, BpelConstants.NS_BPWS, BpelConstants.ELEM_FROM);
49       Element JavaDoc toElement = NodeUtil.getElement(copyElement, BpelConstants.NS_BPWS, BpelConstants.ELEM_TO);
50       
51       CompositeActivity parent = assign.getCompositeActivity();
52       readFrom(copy, fromElement, parent);
53       readTo(copy, toElement, parent);
54       copies.add(copy);
55     }
56     
57     assign.setCopies(copies);
58   }
59
60   private void readTo(Copy copy, Element JavaDoc toElement, CompositeActivity parent) {
61
62     String JavaDoc variableName = NodeUtil.getAttribute(toElement, BpelConstants.ATTR_VARIABLE);
63     if (variableName != null) {
64       // variable
65
VariableDefinition variable = parent.findVariable(variableName);
66       if (variable == null) {
67         bpelReader.getProblemHandler().add(
68             new LocalizedProblem( Problem.LEVEL_ERROR, "variable not found", toElement ) );
69         return;
70       }
71       // property
72
String JavaDoc property = NodeUtil.getAttribute(toElement, BpelConstants.ATTR_PROPERTY);
73       if (property == null) {
74         bpelReader.getProblemHandler().add(
75             new LocalizedProblem( Problem.LEVEL_ERROR, "missing property", toElement ) );
76         return;
77       }
78       ToProperty to = new ToProperty();
79       to.setVariable(variable);
80       to.setProperty(NodeUtil.getQName(property, toElement));
81       copy.setTo(to);
82     }
83     else {
84       String JavaDoc partnerLink = NodeUtil.getAttribute(toElement, BpelConstants.ATTR_PARTNER_LINK);
85       if (partnerLink != null) {
86         // partner link
87
if (parent.findPartnerLink(partnerLink) == null) {
88           bpelReader.getProblemHandler().add(
89               new LocalizedProblem( Problem.LEVEL_ERROR, "partner link not found", toElement ) );
90           return;
91         }
92         ToPartnerLink to = new ToPartnerLink();
93         to.setPartnerLink(partnerLink);
94         copy.setTo(to);
95       }
96       else {
97         // query
98
ToQuery to = new ToQuery();
99         to.setQuery(bpelReader.readExpression(toElement, parent, Snippet.Use.QUERY));
100         copy.setTo(to);
101       }
102     }
103   }
104
105   private void readFrom(Copy copy, Element JavaDoc fromElement, CompositeActivity parent) {
106     String JavaDoc variableName = NodeUtil.getAttribute(fromElement, BpelConstants.ATTR_VARIABLE);
107     if (variableName != null) {
108       // variable
109
VariableDefinition variable = parent.findVariable(variableName);
110       if (variable == null) {
111         bpelReader.getProblemHandler().add(
112             new LocalizedProblem( Problem.LEVEL_ERROR, "variable not found", fromElement ) );
113         return;
114       }
115       // property
116
String JavaDoc property = NodeUtil.getAttribute(fromElement, BpelConstants.ATTR_PROPERTY);
117       if (property == null) {
118         bpelReader.getProblemHandler().add(
119             new LocalizedProblem( Problem.LEVEL_ERROR, "missing property", fromElement ) );
120         return;
121       }
122       FromProperty from = new FromProperty();
123       from.setVariable(variable);
124       from.setProperty(NodeUtil.getQName(property, fromElement));
125       copy.setFrom(from);
126     }
127     else {
128       String JavaDoc partnerLink = NodeUtil.getAttribute(fromElement, BpelConstants.ATTR_PARTNER_LINK);
129       if (partnerLink != null) {
130         // partner link
131
if(parent.findPartnerLink(partnerLink) == null) {
132           bpelReader.getProblemHandler().add(
133               new LocalizedProblem( Problem.LEVEL_ERROR, "partner link not found", fromElement ) );
134         }
135         else {
136           FromPartnerLink from = new FromPartnerLink();
137           from.setPartnerLink(partnerLink);
138           String JavaDoc endpointReference = NodeUtil.getAttribute(fromElement, BpelConstants.ATTR_ENDPOINT_REFERENCE);
139           from.setEndpointReference(endpointReference);
140           copy.setFrom(from);
141         }
142       }
143       else {
144         // literal
145
Attr JavaDoc literal = fromElement.getAttributeNode(BpelConstants.ATTR_LITERAL);
146         if (bpelReader.readTBoolean(literal, Boolean.FALSE) == Boolean.TRUE) {
147           FromLiteral from = new FromLiteral();
148           from.setLiteral(NodeUtil.getValue(fromElement));
149           copy.setFrom(from);
150         }
151         else {
152           // expression
153
Snippet expression = bpelReader.readExpression(fromElement, parent);
154           FromExpression fromExp = new FromExpression();
155           fromExp.setExpression(expression);
156           copy.setFrom(fromExp);
157         }
158       }
159     }
160   }
161 }
162
Popular Tags