KickJava   Java API By Example, From Geeks To Geeks.

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


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.def.Activity;
8 import org.jbpm.bpel.def.Pick;
9 import org.jbpm.bpel.service.def.Receiver;
10 import org.jbpm.bpel.timer.def.Alarm;
11 import org.jbpm.bpel.xml.util.NodeUtil;
12 import org.jbpm.jpdl.xml.Problem;
13
14 /**
15  * @author Juan Cantú
16  * @version $Revision: 1.8 $ $Date: 2005/06/23 20:45:04 $
17  */

18 public class PickReader extends ActivityReader {
19
20   public Activity createActivity() {
21     return new Pick();
22   }
23   
24   public void readActivity(Activity activity, Element JavaDoc pickElem) {
25     Pick pick = (Pick) activity;
26     boolean initial = pick.isInitial();
27
28     boolean createInstance = bpelReader.readTBoolean(
29         pickElem.getAttributeNode(BpelConstants.ATTR_CREATE_INSTANCE), Boolean.FALSE).booleanValue();
30     
31     if( !initial && createInstance ) {
32       bpelReader.getProblemHandler().add(
33           new LocalizedProblem( Problem.LEVEL_ERROR,
34               "createInstance='yes' but the pick activity is not initial", pickElem) );
35     }
36       
37     pick.setCreateInstance(createInstance);
38     
39     Iterator JavaDoc messageElemIt = NodeUtil.getElements(pickElem, BpelConstants.NS_BPWS, BpelConstants.ELEM_ON_MESSAGE);
40     while (messageElemIt.hasNext()) {
41       Element JavaDoc eventElement = (Element JavaDoc) messageElemIt.next();
42       Element JavaDoc activityElement = bpelReader.getActivityElement(eventElement);
43       Activity child = bpelReader.readActivity(activityElement, pick);
44       Receiver receiver = bpelReader.readReceiver(eventElement, pick);
45       receiver.setInboundMessageActivity( pick );
46       pick.setOnMessage(child, receiver);
47     }
48     
49     Iterator JavaDoc alarmElemIt = NodeUtil.getElements(pickElem, BpelConstants.NS_BPWS, BpelConstants.ELEM_ON_ALARM);
50     if( !initial ) {
51       while (alarmElemIt.hasNext()) {
52         Element JavaDoc eventElement = (Element JavaDoc) alarmElemIt.next();
53         Element JavaDoc activityElement = bpelReader.getActivityElement(eventElement);
54         Activity child = bpelReader.readActivity(activityElement, pick);
55         Alarm alarm = bpelReader.readAlarm(eventElement, pick);
56         alarm.setAlarmActivity(pick);
57         pick.setOnAlarm(child, alarm);
58       }
59     }
60     else if ( alarmElemIt.hasNext() ) {
61       bpelReader.getProblemHandler().add(
62           new LocalizedProblem( Problem.LEVEL_ERROR,
63               "pick activity can't have alarm events since it is initial", pickElem) );
64     }
65   }
66 }
67
Popular Tags