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.common.util.logger.Logger; 7 import org.smartcomps.twister.deployer.exception.DeploymentException; 8 import org.smartcomps.twister.engine.priv.core.definition.Activity; 9 import org.smartcomps.twister.engine.priv.core.definition.ActivityFactory; 10 import org.smartcomps.twister.engine.priv.core.definition.CorrelationRef; 11 import org.smartcomps.twister.engine.priv.core.definition.StructuredActivity; 12 import org.smartcomps.twister.engine.priv.core.definition.TwisterProcess; 13 14 import java.util.Iterator; 15 16 /*** 17 * parent class of specific activity deployer 18 */ 19 public abstract class ActivityDeployer { 20 21 protected Logger log = Logger.getLogger(getClass()); 22 23 // this flag indicates if the deploy loop should deploy the 24 // children elements or not 25 protected boolean processChildren = true; 26 27 protected ActivityDeployer() { 28 } 29 30 /*** 31 * The token "activity" can be any of the following: 32 * • <receive> 33 * • <reply> 34 * • <invoke> 35 * • <assign> 36 * • <throw> 37 * • <terminate> 38 * • <wait> 39 * • <empty> 40 * • <sequence> 41 * • <switch> 42 * • <while> 43 * • <pick> 44 * • <flow> 45 * • <scope> 46 * • <compensate> 47 * 48 * @param pe 49 * @return 50 */ 51 public static Element getActivityElement(final Element pe) { 52 Element res = null; 53 Element tmp = null; 54 res = ((res != null) || (tmp = pe.element("assign")) == null) ? res : tmp; 55 res = ((res != null) || (tmp = pe.element("compensate")) == null) ? res : tmp; 56 res = ((res != null) || (tmp = pe.element("empty")) == null) ? res : tmp; 57 res = ((res != null) || (tmp = pe.element("flow")) == null) ? res : tmp; 58 res = ((res != null) || (tmp = pe.element("invoke")) == null) ? res : tmp; 59 res = ((res != null) || (tmp = pe.element("pick")) == null) ? res : tmp; 60 res = ((res != null) || (tmp = pe.element("receive")) == null) ? res : tmp; 61 res = ((res != null) || (tmp = pe.element("reply")) == null) ? res : tmp; 62 res = ((res != null) || (tmp = pe.element("sequence")) == null) ? res : tmp; 63 res = ((res != null) || (tmp = pe.element("scope")) == null) ? res : tmp; 64 res = ((res != null) || (tmp = pe.element("switch")) == null) ? res : tmp; 65 res = ((res != null) || (tmp = pe.element("terminate")) == null) ? res : tmp; 66 res = ((res != null) || (tmp = pe.element("throw")) == null) ? res : tmp; 67 res = ((res != null) || (tmp = pe.element("wait")) == null) ? res : tmp; 68 res = ((res != null) || (tmp = pe.element("while")) == null) ? res : tmp; 69 return res; 70 } 71 72 73 /*** 74 * @param element 75 * @param twisterProcess 76 * @return 77 * @throws DeploymentException 78 */ 79 final public Activity deploy(Element element, TwisterProcess twisterProcess) throws DeploymentException { 80 Activity activity = createActivity(element, twisterProcess); 81 if ((activity instanceof StructuredActivity) && (processChildren == true)) { 82 for (Iterator i = element.elementIterator(); i.hasNext();) { 83 Element e = (Element) i.next(); 84 log.info("<" + e.getName() + ">"); 85 ActivityDeployer ad = null; 86 try { 87 ad = ActivityDeployerFactory.getActivityDeployer(e.getName()); 88 } catch (DeploymentException ex) { 89 throw new DeploymentException(ex); 90 } 91 ad.deploy(e, (StructuredActivity) activity); 92 93 log.info("</" + e.getName() + ">"); 94 } 95 } 96 return activity; 97 } 98 99 /*** 100 * @param element 101 * @param parentActivity 102 * @return 103 * @throws DeploymentException 104 */ 105 final public Activity deploy(Element element, StructuredActivity parentActivity) throws DeploymentException { 106 Activity activity = createActivity(element, parentActivity); 107 if ((activity instanceof StructuredActivity) && (processChildren == true)) { 108 for (Iterator i = element.elementIterator(); i.hasNext();) { 109 Element e = (Element) i.next(); 110 log.debug("<" + e.getName() + ">"); 111 ActivityDeployer ad = null; 112 try { 113 ad = ActivityDeployerFactory.getActivityDeployer(e.getName()); 114 } catch (DeploymentException ex) { 115 log.debug("unable to find '" + element.getName() + "' deployer due to " + ex.getMessage()); 116 } 117 ad.deploy(e, (StructuredActivity) activity); 118 log.debug("</" + e.getName() + ">"); 119 } 120 } 121 return activity; 122 } 123 124 /*** 125 * Standard Attributes for Each Activity 126 * <p/> 127 * name="ncname"? 128 * joinCondition="bool-expr"? 129 * suppressJoinFailure="yes|no"?> 130 * 131 * @param element 132 * @param activity 133 */ 134 final protected void processStandardAttributes(Element element, Activity activity) { 135 Attribute name = element.attribute("name"); 136 if (name != null) { 137 log.debug("name=" + name); 138 activity.setName(name.getValue()); 139 } 140 141 Attribute joinCondition = element.attribute("joinCondition"); 142 if (joinCondition != null) { 143 log.debug("joinCondition=" + joinCondition); 144 activity.setJoinCondition(joinCondition.getValue()); 145 } 146 147 /* TODO manage the suppressJoinFailure when avaliable in the implementation 148 Attribute suppressJoinFailure = element.attribute("suppressJoinFailure"); 149 if (suppressJoinFailure != null) { 150 log.debug("suppressJoinFailure=" + suppressJoinFailure); 151 activity.setPartner(partnerLink.getValue()); 152 } 153 */ 154 } 155 156 /*** 157 * Standard Elements for Each Activity 158 * <p/> 159 * <source linkName="ncname" transitionCondition="bool-expr"?/>* 160 * <target linkName="ncname"/>* 161 * 162 * @param element 163 * @param activity 164 */ 165 final protected void processStandardElements(Element element, Activity activity) { 166 Iterator sourceElements = element.elementIterator("source"); 167 processSource(sourceElements, activity); 168 169 Iterator targetElements = element.elementIterator("target"); 170 processTarget(targetElements, activity); 171 } 172 173 174 private void processSource(Iterator sourceElements, Activity activity) { 175 while (sourceElements.hasNext()) { 176 Element element = (Element) sourceElements.next(); 177 log.info("not yet managed element : " + element); 178 } 179 } 180 181 private void processTarget(Iterator targetElements, Activity activity) { 182 while (targetElements.hasNext()) { 183 Element element = (Element) targetElements.next(); 184 log.info("not yet managed element : " + element); 185 } 186 } 187 188 protected int getCorrelationPattern(String patternAsString) { 189 int res = CorrelationRef.NONE; 190 if ("in".equalsIgnoreCase(patternAsString)) { 191 res = CorrelationRef.IN; 192 } else if ("out".equalsIgnoreCase(patternAsString)) { 193 res = CorrelationRef.OUT; 194 } else if ("out-in".equalsIgnoreCase(patternAsString)) { 195 res = CorrelationRef.OUT_IN; 196 } 197 return res; 198 } 199 200 /*** 201 * @param element 202 * @param twisterProcess 203 * @return 204 * @throws DeploymentException 205 */ 206 final protected Activity createActivity(Element element, TwisterProcess twisterProcess) throws DeploymentException { 207 Activity activity = null; 208 // log.debug("Creating " + StringUtil.getClassName(getActivityClass().getName()) + " ..."); 209 try { 210 activity = ActivityFactory.createActivity(getActivityClass(), twisterProcess); 211 } catch (DBSessionException e) { 212 throw new DeploymentException(e); 213 } 214 processElements(element, activity); 215 return activity; 216 } 217 218 /*** 219 * @param element 220 * @param parentActivity 221 * @return 222 * @throws DeploymentException 223 */ 224 final protected Activity createActivity(Element element, StructuredActivity parentActivity) throws DeploymentException { 225 Activity activity = null; 226 // log.debug("Creating " + StringUtil.getClassName(getActivityClass().getName()) + " ..."); 227 try { 228 activity = ActivityFactory.createActivity(getActivityClass(), parentActivity); 229 } catch (DBSessionException e) { 230 throw new DeploymentException(e); 231 } 232 233 processElements(element, activity); 234 235 return activity; 236 } 237 238 private void processElements(Element element, Activity activity) throws DeploymentException { 239 processStandardAttributes(element, activity); 240 processSpecificAttributes(element, activity); 241 processStandardElements(element, activity); 242 processSpecificElements(element, activity); 243 } 244 245 protected abstract void processSpecificElements(Element element, Activity activity) throws DeploymentException; 246 247 protected abstract void processSpecificAttributes(Element element, Activity activity) throws DeploymentException; 248 249 protected abstract Class getActivityClass(); 250 251 protected String truncNamespace(String string) { 252 int index = string.lastIndexOf(":"); 253 return string.substring(index + 1); 254 } 255 256 }

This page was automatically generated by Maven