1 package org.jbpm.bpel.xml; 2 3 import java.util.ArrayList ; 4 import java.util.List ; 5 6 import org.w3c.dom.Attr ; 7 import org.w3c.dom.Element ; 8 import org.w3c.dom.NodeList ; 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 30 public class AssignReader extends ActivityReader { 31 32 public Activity createActivity() { 33 return new Assign(); 34 } 35 36 public void readActivity(Activity activity, Element element) { 37 Assign assign = (Assign) activity; 38 39 NodeList copyList = element.getElementsByTagNameNS(BpelConstants.NS_BPWS, BpelConstants.ELEM_COPY); 40 int copyCount = copyList.getLength(); 41 42 List copies = new ArrayList (copyCount); 43 44 for(int i = 0; i < copyCount; i++) { 45 Element copyElement = (Element ) copyList.item(i); 46 Assign.Copy copy = new Assign.Copy(); 47 48 Element fromElement = NodeUtil.getElement(copyElement, BpelConstants.NS_BPWS, BpelConstants.ELEM_FROM); 49 Element 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 toElement, CompositeActivity parent) { 61 62 String variableName = NodeUtil.getAttribute(toElement, BpelConstants.ATTR_VARIABLE); 63 if (variableName != null) { 64 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 String 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 partnerLink = NodeUtil.getAttribute(toElement, BpelConstants.ATTR_PARTNER_LINK); 85 if (partnerLink != null) { 86 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 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 fromElement, CompositeActivity parent) { 106 String variableName = NodeUtil.getAttribute(fromElement, BpelConstants.ATTR_VARIABLE); 107 if (variableName != null) { 108 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 String 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 partnerLink = NodeUtil.getAttribute(fromElement, BpelConstants.ATTR_PARTNER_LINK); 129 if (partnerLink != null) { 130 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 endpointReference = NodeUtil.getAttribute(fromElement, BpelConstants.ATTR_ENDPOINT_REFERENCE); 139 from.setEndpointReference(endpointReference); 140 copy.setFrom(from); 141 } 142 } 143 else { 144 Attr 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 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 |