Author: alex.guizar(a)jboss.com
Date: 2009-07-05 10:27:27 -0400 (Sun, 05 Jul 2009)
New Revision: 5233
Modified:
jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/graph/def/Node.java
Log:
make NodeType serializable
Modified:
jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/graph/def/Node.java
===================================================================
---
jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/graph/def/Node.java 2009-07-05
13:42:53 UTC (rev 5232)
+++
jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/graph/def/Node.java 2009-07-05
14:27:27 UTC (rev 5233)
@@ -55,6 +55,7 @@
public static class NodeType implements Serializable {
private final String name;
+ private static final Map values = new HashMap();
private static final long serialVersionUID = 1L;
@@ -69,6 +70,7 @@
protected NodeType(String name) {
this.name = name;
+ values.put(name, this);
}
public String toString() {
@@ -76,10 +78,7 @@
}
public static NodeType valueOf(String name) {
- return Node.name.equals(name) ? Node : StartState.name.equals(name) ? StartState
- : EndState.name.equals(name) ? EndState : State.name.equals(name) ? State
- : Task.name.equals(name) ? Task : Fork.name.equals(name) ? Fork
- : Join.name.equals(name) ? Join : Decision.name.equals(name) ? Decision
: null;
+ return (NodeType) values.get(name);
}
private Object readResolve() throws ObjectStreamException {
@@ -87,7 +86,6 @@
if (nodeType == null) throw new InvalidObjectException("invalid node type:
" + name);
return nodeType;
}
-
};
protected List leavingTransitions = null;
@@ -159,7 +157,7 @@
* are the leaving {@link Transition}s, mapped by their name (java.lang.String).
*/
public Map getLeavingTransitionsMap() {
- if ((leavingTransitionMap == null) && (leavingTransitions != null)) {
+ if (leavingTransitionMap == null && leavingTransitions != null) {
// initialize the cached leaving transition map
leavingTransitionMap = new HashMap();
ListIterator iter = leavingTransitions.listIterator(leavingTransitions.size());
@@ -179,6 +177,7 @@
public Transition addLeavingTransition(Transition leavingTransition) {
if (leavingTransition == null)
throw new IllegalArgumentException("can't add a null leaving transition to
an node");
+
if (leavingTransitions == null) leavingTransitions = new ArrayList();
leavingTransitions.add(leavingTransition);
leavingTransition.from = this;
@@ -194,11 +193,10 @@
public void removeLeavingTransition(Transition leavingTransition) {
if (leavingTransition == null)
throw new IllegalArgumentException("can't remove a null leavingTransition
from an node");
- if (leavingTransitions != null) {
- if (leavingTransitions.remove(leavingTransition)) {
- leavingTransition.from = null;
- leavingTransitionMap = null;
- }
+
+ if (leavingTransitions != null &&
leavingTransitions.remove(leavingTransition)) {
+ leavingTransition.from = null;
+ leavingTransitionMap = null;
}
}
@@ -221,7 +219,7 @@
if (leavingTransitions != null) {
transition = (Transition) getLeavingTransitionsMap().get(transitionName);
}
- if ((transition == null) && (superState != null)) {
+ if (transition == null && superState != null) {
transition = superState.getLeavingTransition(transitionName);
}
return transition;
@@ -231,7 +229,8 @@
* true if this transition has leaving transitions.
*/
public boolean hasNoLeavingTransitions() {
- return (((leavingTransitions == null) || (leavingTransitions.size() == 0)) &&
((superState == null) || (superState.hasNoLeavingTransitions())));
+ return (leavingTransitions == null || leavingTransitions.size() == 0) &&
+ (superState == null || superState.hasNoLeavingTransitions());
}
/**
@@ -249,15 +248,10 @@
}
boolean containsName(List leavingTransitions, String name) {
- Iterator iter = leavingTransitions.iterator();
- while (iter.hasNext()) {
+ for (Iterator iter = leavingTransitions.iterator(); iter.hasNext();) {
Transition transition = (Transition) iter.next();
- if ((name == null) && (transition.getName() == null)) {
+ if (name != null ? name.equals(transition.getName()) : transition.getName() ==
null)
return true;
- }
- else if ((name != null) && (name.equals(transition.getName()))) {
- return true;
- }
}
return false;
}
@@ -314,6 +308,7 @@
public Transition addArrivingTransition(Transition arrivingTransition) {
if (arrivingTransition == null)
throw new IllegalArgumentException("can't add a null arrivingTransition to
a node");
+
if (arrivingTransitions == null) arrivingTransitions = new HashSet();
arrivingTransitions.add(arrivingTransition);
arrivingTransition.to = this;
@@ -328,10 +323,9 @@
public void removeArrivingTransition(Transition arrivingTransition) {
if (arrivingTransition == null)
throw new IllegalArgumentException("can't remove a null arrivingTransition
from a node");
- if (arrivingTransitions != null) {
- if (arrivingTransitions.remove(arrivingTransition)) {
- arrivingTransition.to = null;
- }
+
+ if (arrivingTransitions != null &&
arrivingTransitions.remove(arrivingTransition)) {
+ arrivingTransition.to = null;
}
}
@@ -341,8 +335,11 @@
* is the {@link SuperState} or the {@link ProcessDefinition} in which this node is
contained.
*/
public GraphElement getParent() {
- GraphElement parent = processDefinition;
- if (superState != null) parent = superState;
+ GraphElement parent;
+ if (superState != null)
+ parent = superState;
+ else
+ parent = processDefinition;
return parent;
}
@@ -360,8 +357,7 @@
// fire the leave-node event for this node
fireEvent(Event.EVENTTYPE_NODE_ENTER, executionContext);
- // keep track of node entrance in the token, so that a node-log can be generated at
node leave
- // time.
+ // register entrance time so that a node-log can be generated upon leaving
token.setNodeEnter(Clock.getCurrentTime());
// remove the transition references from the runtime context
@@ -397,15 +393,13 @@
try {
// execute the action
executeAction(action, executionContext);
-
}
catch (Exception exception) {
- // NOTE that Error's are not caught because that might halt the JVM and mask
the original
- // Error.
+ // NOTE that Errors are not caught because that might halt the JVM
+ // and mask the original Error.
// search for an exception handler or throw to the client
raiseException(exception, executionContext);
}
-
}
else {
// let this node handle the token
@@ -426,13 +420,9 @@
*/
public void leave(ExecutionContext executionContext, String transitionName) {
Transition transition = getLeavingTransition(transitionName);
- if (transition == null) {
- throw new JbpmException("transition '" +
- transitionName +
- "' is not a leaving transition of node '" +
- this +
- "'");
- }
+ if (transition == null)
+ throw new JbpmException("'" + transitionName + "' is not a
leaving transition of " + this);
+
leave(executionContext, transition);
}
@@ -441,7 +431,8 @@
*/
public void leave(ExecutionContext executionContext, Transition transition) {
if (transition == null)
- throw new JbpmException("can't leave node '" + this + "'
without leaving transition");
+ throw new JbpmException("cannot leave " + this + " without leaving
transition");
+
Token token = executionContext.getToken();
token.setNode(this);
executionContext.setTransition(transition);
@@ -469,11 +460,7 @@
// ///////////////////////////////////////////////////////////////////////////
public ProcessDefinition getProcessDefinition() {
- ProcessDefinition pd = this.processDefinition;
- if (superState != null) {
- pd = superState.getProcessDefinition();
- }
- return pd;
+ return superState != null ? superState.getProcessDefinition() : processDefinition;
}
// change the name of a node ////////////////////////////////////////////////
@@ -485,11 +472,11 @@
String oldName = this.name;
if (superState != null) {
if (superState.hasNode(name)) {
- throw new IllegalArgumentException("couldn't set name '" +
- name +
- "' on node '" +
+ throw new IllegalArgumentException("cannot rename " +
this +
- "'cause the superState of this node has already another child node
with the same name");
+ " to '" +
+ name +
+ "' - parent superstate has another child node with the same
name");
}
Map nodes = superState.getNodesMap();
nodes.remove(oldName);
@@ -497,11 +484,11 @@
}
else if (processDefinition != null) {
if (processDefinition.hasNode(name)) {
- throw new IllegalArgumentException("couldn't set name '" +
- name +
- "' on node '" +
+ throw new IllegalArgumentException("cannot rename " +
this +
- "'cause the process definition of this node has already another
node with the same name");
+ " to '" +
+ name +
+ "' - process definition has another child node with the same
name");
}
Map nodeMap = processDefinition.getNodesMap();
nodeMap.remove(oldName);
@@ -511,25 +498,15 @@
}
}
- boolean isDifferent(String name1, String name2) {
- if ((name1 != null) && (name1.equals(name2))) {
- return false;
- }
- else if ((name1 == null) && (name2 == null)) {
- return false;
- }
- return true;
+ private static boolean isDifferent(String name1, String name2) {
+ return !(name1 != null ? name1.equals(name2) : name2 == null);
}
/**
* the slash separated name that includes all the superstate names.
*/
public String getFullyQualifiedName() {
- String fullyQualifiedName = name;
- if (superState != null) {
- fullyQualifiedName = superState.getFullyQualifiedName() + "/" + name;
- }
- return fullyQualifiedName;
+ return superState != null ? superState.getFullyQualifiedName() + '/' + name :
name;
}
/** indicates wether this node is a superstate. */