KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jbpm > graph > def > Action


1 package org.jbpm.graph.def;
2
3 import java.io.*;
4 import java.util.*;
5
6 import org.dom4j.*;
7 import org.jbpm.graph.exe.*;
8 import org.jbpm.instantiation.*;
9 import org.jbpm.jpdl.xml.*;
10
11 public class Action implements Parsable, Serializable {
12
13   private static final long serialVersionUID = 1L;
14   
15   long id = 0;
16   protected String JavaDoc name = null;
17   protected boolean isPropagationAllowed = true;
18   protected Action referencedAction = null;
19   protected Delegation actionDelegation = null;
20   protected Event event = null;
21   protected ProcessDefinition processDefinition = null;
22
23   public Action() {
24   }
25
26   public Action(Delegation actionDelegate) {
27     this.actionDelegation = actionDelegate;
28   }
29   
30   public String JavaDoc toString() {
31     String JavaDoc toString = null;
32     if (name!=null) {
33       toString = "action["+name+"]";
34     } else if ( (actionDelegation!=null)
35                 && (actionDelegation.getClassName()!=null)
36               ) {
37       String JavaDoc className = actionDelegation.getClassName();
38       toString = className.substring(className.lastIndexOf('.')+1);
39     } else {
40       String JavaDoc className = getClass().getName();
41       className = className.substring(className.lastIndexOf('.')+1);
42       if (name!=null) {
43         toString = className+"("+name+")";
44       } else {
45         toString = className+"("+Integer.toHexString(System.identityHashCode(this))+")";
46       }
47     }
48     return toString;
49   }
50
51   public void read(Element actionElement, JpdlXmlReader jpdlReader) {
52     if (actionElement.attribute("ref-name")!=null) {
53       jpdlReader.addUnresolvedActionReference(actionElement, this);
54     } else if (actionElement.attribute("class")!=null) {
55       actionDelegation = new Delegation();
56       actionDelegation.read(actionElement, jpdlReader);
57       
58       String JavaDoc acceptPropagatedEvents = actionElement.attributeValue("accept-propagated-events");
59       if ("false".equalsIgnoreCase(acceptPropagatedEvents)
60           || "no".equalsIgnoreCase(acceptPropagatedEvents)) {
61         isPropagationAllowed = false;
62       }
63     } else {
64       jpdlReader.addWarning("action does not have class nor ref-name attribute "+actionElement.asXML());
65     }
66   }
67
68   public void write(Element actionElement) {
69     if (actionDelegation!=null) {
70       actionDelegation.write(actionElement);
71     }
72   }
73
74   public void execute(ExecutionContext executionContext) throws Exception JavaDoc {
75     if (referencedAction!=null) {
76       referencedAction.execute(executionContext);
77     } else {
78       ActionHandler actionHandler = (ActionHandler)actionDelegation.getInstance();
79       actionHandler.execute(executionContext);
80     }
81   }
82
83   public void setName(String JavaDoc name) {
84     // if the process definition is already set
85
if (processDefinition!=null) {
86       // update the process definition action map
87
Map actionMap = processDefinition.getActions();
88       // the != string comparison is to avoid null pointer checks. it is no problem if the body is executed a few times too much :-)
89
if ( (this.name != name)
90            && (actionMap!=null) ) {
91         actionMap.remove(this.name);
92         actionMap.put(name, this);
93       }
94     }
95
96     // then update the name
97
this.name = name;
98   }
99   
100   // getters and setters //////////////////////////////////////////////////////
101

102   public boolean acceptsPropagatedEvents() {
103     return isPropagationAllowed;
104   }
105
106   public boolean isPropagationAllowed() {
107     return isPropagationAllowed;
108   }
109   public void setPropagationAllowed(boolean isPropagationAllowed) {
110     this.isPropagationAllowed = isPropagationAllowed;
111   }
112
113   public long getId() {
114     return id;
115   }
116   public String JavaDoc getName() {
117     return name;
118   }
119   public Event getEvent() {
120     return event;
121   }
122   public ProcessDefinition getProcessDefinition() {
123     return processDefinition;
124   }
125   public void setProcessDefinition(ProcessDefinition processDefinition) {
126     this.processDefinition = processDefinition;
127   }
128   public Delegation getActionDelegation() {
129     return actionDelegation;
130   }
131   public void setActionDelegation(Delegation instantiatableDelegate) {
132     this.actionDelegation = instantiatableDelegate;
133   }
134   public Action getReferencedAction() {
135     return referencedAction;
136   }
137   public void setReferencedAction(Action referencedAction) {
138     this.referencedAction = referencedAction;
139   }
140 }
141
Popular Tags