KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jbpm > bpel > xml > SwitchReader


1 package org.jbpm.bpel.xml;
2
3 import java.util.Iterator JavaDoc;
4
5 import org.w3c.dom.Element JavaDoc;
6
7 import org.jbpm.bpel.data.def.Snippet;
8 import org.jbpm.bpel.def.Activity;
9 import org.jbpm.bpel.def.CompositeActivity;
10 import org.jbpm.bpel.def.Switch;
11 import org.jbpm.bpel.xml.util.NodeUtil;
12
13 /**
14  * Encapsulates the logic to create and connect process elements that make up
15  * the <i>switch</i> structure.
16  * @author Juan Cantú
17  * @version $Revision: 1.5 $ $Date: 2005/06/23 02:22:46 $
18  */

19 public class SwitchReader extends ActivityReader {
20
21   protected Activity createActivity() {
22     return new Switch();
23   }
24   
25   protected void readActivity(Activity activity, Element JavaDoc switchElem) {
26     Switch switchBlock = (Switch)activity;
27     CompositeActivity parent = switchBlock.getCompositeActivity();
28     
29     Iterator JavaDoc caseElemIt = NodeUtil.getElements(switchElem, BpelConstants.NS_BPWS, BpelConstants.ELEM_CASE);
30     // Load case clauses
31
while (caseElemIt.hasNext()) {
32       Element JavaDoc caseElem = (Element JavaDoc) caseElemIt.next();
33       // activity
34
Element JavaDoc activityElement = bpelReader.getActivityElement(caseElem);
35       Activity child = bpelReader.readActivity(activityElement, switchBlock);
36       
37       // condition
38
Element JavaDoc conditionElement =
39         NodeUtil.getElement(caseElem, BpelConstants.NS_BPWS, BpelConstants.ELEM_CONDITION);
40       
41       Snippet condition = bpelReader.readExpression(conditionElement, parent);
42       switchBlock.setCondition(child, condition);
43     }
44
45     //Load the otherwise clause. If it doesn't exist create an empty activity.
46
Element JavaDoc otherwiseElem = NodeUtil.getElement(switchElem, BpelConstants.NS_BPWS, BpelConstants.ELEM_OTHERWISE);
47     
48     if (otherwiseElem != null) {
49       Element JavaDoc childElement = bpelReader.getActivityElement(otherwiseElem);
50       Activity otherwise = bpelReader.readActivity(childElement, switchBlock);
51       switchBlock.setOtherwise(otherwise);
52     }
53   }
54 }
55
Popular Tags