1 package org.jbpm.bpel.xml; 2 3 import java.util.Collection ; 4 import java.util.Iterator ; 5 6 import org.w3c.dom.Element ; 7 8 import org.jbpm.bpel.data.def.Snippet; 9 import org.jbpm.bpel.def.Activity; 10 import org.jbpm.bpel.def.CompositeActivity; 11 import org.jbpm.bpel.def.Flow; 12 import org.jbpm.bpel.def.Link; 13 import org.jbpm.bpel.def.Pick; 14 import org.jbpm.bpel.def.Receive; 15 import org.jbpm.bpel.def.Sequence; 16 import org.jbpm.bpel.xml.util.NodeUtil; 17 import org.jbpm.jpdl.xml.Problem; 18 19 23 public abstract class ActivityReader { 24 25 protected BpelReader bpelReader; 26 27 30 public Activity read(Element element, CompositeActivity parent) { 31 Activity activity = createActivity(); 33 34 readStandardProperties(element, activity, parent); 36 37 try { 39 readActivity(activity, element); 40 } 41 catch(BpelException e) { 42 45 bpelReader.getProblemHandler().add( 46 new Problem( Problem.LEVEL_ERROR, "bpel activity is invalid.", e ) ); 47 } 48 49 return activity; 50 } 51 52 55 protected abstract Activity createActivity(); 56 57 61 protected void readActivity(Activity activity, Element element) { 62 } 64 65 protected void readStandardProperties(Element elem, Activity activity, CompositeActivity parent) { 66 activity.setName( NodeUtil.getAttribute(elem, BpelConstants.ATTR_NAME) ); 67 68 parent.addNode( activity ); 70 71 readSources(activity, elem); 73 readTargets(activity, elem); 74 75 if( activity.isInitial() ) { 78 Collection targets = activity.getTargets(); 79 if(!(activity instanceof Sequence || activity instanceof Flow || 80 activity instanceof Pick ||activity instanceof Receive) && 81 (targets == null || targets.size() == 0)) { 82 bpelReader.getProblemHandler().add( 83 new LocalizedProblem( Problem.LEVEL_ERROR, "activity can't be initial", elem ) ); 84 } 85 } 86 87 Boolean supJoin = bpelReader.readTBoolean( 89 elem.getAttributeNode(BpelConstants.ATTR_SUPPRESS_JOIN_FAILURE), null); 90 activity.setSuppressJoinFailure(supJoin); 91 } 92 93 private void readSources(Activity activity, Element element) { 94 Element sourcesElem = NodeUtil.getElement(element, BpelConstants.NS_BPWS, BpelConstants.ELEM_SOURCES); 95 96 if (sourcesElem != null) { 97 CompositeActivity parent = activity.getCompositeActivity(); 98 Iterator sourceElemIt = NodeUtil.getElements(sourcesElem, BpelConstants.NS_BPWS, BpelConstants.ELEM_SOURCE); 99 while (sourceElemIt.hasNext()) { 100 Element sourceElem = (Element ) sourceElemIt.next(); 101 String linkName = sourceElem.getAttribute(BpelConstants.ATTR_LINK_NAME); 102 Link link = parent.findLink(linkName); 103 Element transitionElem = NodeUtil.getElement(sourceElem, BpelConstants.NS_BPWS, BpelConstants.ELEM_TRANSITION_CONDITION); 104 if(transitionElem != null) { 105 link.setTransitionCondition(bpelReader.readExpression(transitionElem, parent)); 106 } 107 activity.addSource(link); 108 } 109 } 110 } 111 112 private void readTargets(Activity activity, Element activityElement) { 113 Element targetsElem = NodeUtil.getElement(activityElement, BpelConstants.NS_BPWS, BpelConstants.ELEM_TARGETS); 114 if (targetsElem != null) { 115 CompositeActivity parent = activity.getCompositeActivity(); 116 Iterator targetElemIt = NodeUtil.getElements(targetsElem, BpelConstants.NS_BPWS, BpelConstants.ELEM_TARGET); 118 while (targetElemIt.hasNext()) { 119 Element targetElem = (Element ) targetElemIt.next(); 120 String linkName = targetElem.getAttribute(BpelConstants.ATTR_LINK_NAME); 121 activity.addTarget(parent.findLink(linkName)); 122 } 123 Element conditionElem = NodeUtil.getElement(targetsElem, BpelConstants.NS_BPWS, BpelConstants.ELEM_JOIN_CONDITION); 125 if(conditionElem != null) { 126 activity.setJoinCondition(bpelReader.readExpression(conditionElem, parent, 127 Snippet.Use.JOIN_CONDITION)); 128 } 129 } 130 } 131 132 public BpelReader getBpelReader() { 133 return bpelReader; 134 } 135 136 public void setBpelReader(BpelReader bpelReader) { 137 this.bpelReader = bpelReader; 138 } 139 } | Popular Tags |