View Javadoc
1 package org.smartcomps.twister.deployer.priv; 2 3 import org.dom4j.Attribute; 4 import org.dom4j.Element; 5 import org.smartcomps.twister.common.persistence.DBSessionException; 6 import org.smartcomps.twister.deployer.exception.DeploymentException; 7 import org.smartcomps.twister.engine.priv.core.definition.*; 8 9 import java.util.Iterator; 10 11 /* 12 <assign standard-attributes> 13 standard-elements 14 <copy>+ 15 from-spec 16 to-spec 17 </copy> 18 </assign> 19 20 where from-spec : 21 <from variable="ncname" part="ncname"? query="queryString"?/> 22 <from partnerLink="ncname" endpointReference="myRole|partnerRole"/> 23 <from variable="ncname" property="qname"/> 24 <from expression="general-expr"/> 25 <from> ... literal value ... </from> 26 27 and to-spec : 28 <to variable="ncname" part="ncname"? query="queryString"?/> 29 <to partnerLink="ncname"/> 30 <to variable="ncname" property="qname"/> 31 */ 32 public class AssignDeployer extends ActivityDeployer { 33 34 protected Class getActivityClass() { 35 return Assign.class; 36 } 37 38 39 protected void processSpecificAttributes(Element element, Activity activity) throws DeploymentException { 40 // No Specific Attributes 41 } 42 43 protected void processSpecificElements(Element element, Activity activity) throws DeploymentException { 44 for (Iterator copy = element.elementIterator(); copy.hasNext();) { 45 Element copyElement = (Element) copy.next(); 46 // log.debug("processing the copyElement : " + copyElement); 47 48 Element fromElement = copyElement.element("from"); 49 Element toElement = copyElement.element("to"); 50 51 if (fromElement == null || toElement == null) { 52 throw new DeploymentException("The copy tag in an assigment MUST contains BOTH the FROM and the TO attributes !"); 53 } 54 55 // processing the FROM type 56 Attribute fromFirstAtt = null; 57 Attribute fromSecondAtt = null; 58 Attribute fromThirdAtt = null; 59 60 int fromType = 0; 61 String fromFirstValue = ""; 62 String fromSecondValue = ""; 63 String fromThirdValue = ""; 64 /* 65 <from variable="ncname" part="ncname"? query="queryString"?/> 66 */ 67 log.debug("<copy>"); 68 fromFirstAtt = fromElement.attribute("variable"); 69 fromSecondAtt = fromElement.attribute("part"); 70 fromThirdAtt = fromElement.attribute("query"); 71 if ((fromFirstAtt != null && fromElement.attributeCount() == 1) 72 || (fromSecondAtt != null || fromThirdAtt != null)) { 73 fromType = Assignment.VARIABLE_PART; 74 fromFirstValue = fromFirstAtt != null ? fromFirstAtt.getValue() : ""; 75 fromSecondValue = fromSecondAtt != null ? fromSecondAtt.getValue() : ""; 76 fromThirdValue = fromThirdAtt != null ? fromThirdAtt.getValue() : ""; 77 log.debug(" <from" + 78 (fromFirstAtt != null ? " variable=" + fromFirstValue : "") + 79 (fromSecondAtt != null ? " part=" + fromSecondValue : "") + 80 (fromThirdAtt != null ? " query=" + fromThirdValue : "") + 81 "/>"); 82 } else 83 /* 84 <from expression="general-expr"/> 85 */ if ((fromFirstAtt = fromElement.attribute("expression")) != null) { 86 fromType = Assignment.EXPRESSION; 87 fromFirstValue = fromFirstAtt.getValue(); 88 log.debug(" <from" + 89 (fromFirstAtt != null ? " expression=" + fromFirstValue : "") + 90 "/>"); 91 } else 92 /* 93 <from partnerLink="ncname" endpointReference="myRole|partnerRole"/> 94 */ if ((fromFirstAtt = fromElement.attribute("partnerLink")) != null && 95 (fromSecondAtt = fromElement.attribute("endpointReference")) != null) { 96 fromType = Assignment.PARTNER_REFERENCE; 97 fromFirstValue = fromFirstAtt.getValue(); 98 fromSecondValue = fromSecondAtt.getValue(); 99 log.debug(" <from" + 100 (fromFirstAtt != null ? " partnerLink=" + fromFirstValue : "") + 101 (fromSecondAtt != null ? " endpointReference=" + fromSecondValue : "") + 102 "/>"); 103 } else 104 /* 105 <from variable="ncname" property="qname"/> 106 */ if ((fromFirstAtt = fromElement.attribute("variable")) != null && 107 (fromSecondAtt = fromElement.attribute("property")) != null) { 108 fromType = Assignment.VARIABLE_PROPERTY; 109 fromFirstValue = fromFirstAtt != null ? fromFirstAtt.getValue() : ""; 110 fromSecondValue = fromSecondAtt != null ? truncNamespace(fromSecondAtt.getValue()) : ""; 111 log.debug(" <from" + 112 (fromFirstAtt != null ? " variable=" + fromFirstValue : "") + 113 (fromSecondAtt != null ? " property=" + fromSecondValue : "") + 114 "/>"); 115 } else 116 /* 117 <from> ... literal value ... </from> 118 */ if (fromElement.attributeCount() == 0) { 119 fromType = Assignment.LITERAL; 120 fromFirstValue = fromElement.getText(); 121 log.debug(" <from>" + fromFirstValue + "</from>"); 122 } else { 123 throw new DeploymentException("The FROM attribute is invalid !"); 124 } 125 126 // processing the TO type 127 int toType = 0; 128 String toFirstValue = ""; 129 String toSecondValue = ""; 130 String toThirdValue = ""; 131 132 Attribute toFirstAtt = null; 133 Attribute toSecondAtt = null; 134 Attribute toThirdAtt = null; 135 136 /* 137 <to variable="ncname" part="ncname"? query="queryString"?/> 138 */ 139 toFirstAtt = toElement.attribute("variable"); 140 toSecondAtt = toElement.attribute("part"); 141 toThirdAtt = toElement.attribute("query"); 142 if ((toFirstAtt != null && toElement.attributeCount() == 1) 143 || (toSecondAtt != null || toThirdAtt != null)) { 144 toType = Assignment.VARIABLE_PART; 145 toFirstValue = toFirstAtt != null ? toFirstAtt.getValue() : ""; 146 toSecondValue = toSecondAtt != null ? toSecondAtt.getValue() : ""; 147 toThirdValue = toThirdAtt != null ? toThirdAtt.getValue() : ""; 148 log.debug(" <to" + 149 (toFirstAtt != null ? " variable=" + toFirstValue : "") + 150 (toSecondAtt != null ? " part=" + toSecondValue : "") + 151 (toThirdAtt != null ? " query=" + toThirdValue : "") + 152 "/>"); 153 } else 154 /* 155 <to partnerLink="ncname" endpointReference="myRole|partnerRole"/> 156 */ if ((toFirstAtt = toElement.attribute("partnerLink")) != null && 157 (toSecondAtt = toElement.attribute("endpointReference")) != null) { 158 toType = Assignment.PARTNER_REFERENCE; 159 toFirstValue = toFirstAtt.getValue(); 160 toSecondValue = toSecondAtt.getValue(); 161 log.debug(" <to" + 162 (toFirstAtt != null ? " partnerLink=" + toFirstValue : "") + 163 (toSecondAtt != null ? " endpointReference=" + toSecondValue : "") + 164 "/>"); 165 } else 166 /* 167 <to variable="ncname" property="qname"/> 168 */ if ((toFirstAtt = toElement.attribute("variable")) != null && 169 (toSecondAtt = toElement.attribute("property")) != null) { 170 toType = Assignment.VARIABLE_PROPERTY; 171 toFirstValue = toFirstAtt != null ? toFirstAtt.getValue() : ""; 172 toSecondValue = toSecondAtt != null ? truncNamespace(toSecondAtt.getValue()): ""; 173 log.debug(" <to" + 174 (toFirstAtt != null ? " variable=" + toFirstValue : "") + 175 (toSecondAtt != null ? " property=" + toSecondValue : "") + 176 "/>"); 177 } else { 178 throw new DeploymentException("The TO attribute is invalid !"); 179 } 180 181 Assignment assignment = null; 182 try { 183 assignment = ActivityFactory.addAssignment((Assign) activity, fromType, toType); 184 } catch (DBSessionException e) { 185 throw new DeploymentException(e); 186 } 187 188 assignment.setFromFirstValue(fromFirstValue); 189 assignment.setFromSecondValue(fromSecondValue); 190 assignment.setFromQuery(fromThirdValue); 191 assignment.setToFirstValue(toFirstValue); 192 assignment.setToSecondValue(toSecondValue); 193 assignment.setToQuery(toThirdValue); 194 log.debug("</copy>"); 195 } 196 } 197 198 } 199

This page was automatically generated by Maven