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.StringUtil;
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.AlarmEvent;
11 import org.smartcomps.twister.engine.priv.core.definition.CorrelationRef;
12 import org.smartcomps.twister.engine.priv.core.definition.Pick;
13
14 import java.util.HashSet;
15 import java.util.Iterator;
16 import java.util.Set;
17
18 /*
19 <pick createInstance="yes|no"? standard-attributes>
20 standard-elements
21 <onMessage partnerLink="ncname" portType="qname"
22 operation="ncname" variable="ncname"?>+
23 <correlations>?
24 <correlation set="ncname" initiate="yes|no"?>+
25 </correlations>
26 activity
27 </onMessage>
28 <onAlarm (for="duration-expr" | until="deadline-expr")>*
29 activity
30 </onAlarm>
31 </pick>
32 */
33
34 public class PickDeployer extends ActivityDeployer {
35
36 protected void processSpecificElements(final Element element, Activity activity) throws DeploymentException {
37 Pick pick = (Pick) activity;
38 for (Iterator i = element.elementIterator("onMessage"); i.hasNext();) {
39 Element onMessageElt = (Element) i.next();
40 String partnerLink = onMessageElt.valueOf("@partnerLink");
41 String portType = onMessageElt.valueOf("@portType");
42 String operation = onMessageElt.valueOf("@operation");
43 String variable = onMessageElt.valueOf("@variable");
44 Element correlationsElt = onMessageElt.element("correlations");
45 Set correlationList = getCorrelationRefList(correlationsElt);
46 Element activityElement = getActivityElement(onMessageElt);
47 ActivityDeployer ad = ActivityDeployerFactory.getActivityDeployer(activityElement.getName());
48 Activity act = ad.deploy(activityElement, pick);
49 try {
50 ActivityFactory.addMessageEvent(pick, act, partnerLink, portType, operation, variable, correlationList);
51 } catch (DBSessionException e) {
52 throw new DeploymentException(e);
53 }
54 }
55 for (Iterator i = element.elementIterator("onAlarm"); i.hasNext();) {
56 Element onAlarmElt = (Element) i.next();
57 String forDurationExpression = onAlarmElt.valueOf("@for");
58 String untilDeadlineExpression = onAlarmElt.valueOf("@until");
59 String timeExpression = null;
60 int expressionType = 0;
61 if (forDurationExpression != null) {
62 timeExpression = forDurationExpression;
63 expressionType = AlarmEvent.DURATION_EXPR;
64 } else if (untilDeadlineExpression != null) {
65 timeExpression = untilDeadlineExpression;
66 expressionType = AlarmEvent.DEADLINE_EXPR;
67 }
68 Element activityElement = getActivityElement(onAlarmElt);
69 ActivityDeployer ad = ActivityDeployerFactory.getActivityDeployer(activityElement.getName());
70 Activity act = ad.deploy(activityElement, pick);
71 try {
72 ActivityFactory.addAlarmEvent(pick, act, timeExpression, expressionType);
73 } catch (DBSessionException e) {
74 throw new DeploymentException(e);
75 }
76 }
77 processChildren = false;
78 }
79
80 private Set getCorrelationRefList(Element correlationsElt) throws DeploymentException {
81 Set correlationList = new HashSet();
82 if (correlationsElt != null) {
83 Iterator correlations = correlationsElt.elementIterator("correlation");
84 while (correlations.hasNext()) {
85 Element correlation = (Element) correlations.next();
86 Attribute setAtt = correlation.attribute("set");
87 Attribute initiateAtt = correlation.attribute("initiate");
88 String set = setAtt != null ? setAtt.getValue() : "";
89 boolean initiate = initiateAtt != null ? StringUtil.booleanValue(initiateAtt.getValue()) : false;
90 CorrelationRef correlationRef = null;
91 try {
92 correlationRef = ActivityFactory.createCorrelationRef(set, initiate, CorrelationRef.IN);
93 } catch (DBSessionException e) {
94 throw new DeploymentException(e);
95 }
96 correlationList.add(correlationRef);
97 }
98 }
99 return correlationList;
100 }
101
102 protected void processSpecificAttributes(Element element, Activity activity) throws DeploymentException {
103 Pick pick = (Pick) activity;
104 Attribute createInstance = element.attribute("createInstance");
105 if (createInstance != null) {
106 log.debug("createInstance=" + createInstance.getValue());
107 pick.setCreateInstance(StringUtil.booleanValue(createInstance.getValue()));
108 }
109 }
110
111 protected Class getActivityClass() {
112 return Pick.class;
113 }
114 }
This page was automatically generated by Maven