[jbpm-commits] JBoss JBPM SVN: r6129 - in jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/graph: node and 1 other directory.
do-not-reply at jboss.org
do-not-reply at jboss.org
Mon Jan 25 20:41:10 EST 2010
Author: alex.guizar at jboss.com
Date: 2010-01-25 20:41:10 -0500 (Mon, 25 Jan 2010)
New Revision: 6129
Modified:
jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/graph/def/GraphElement.java
jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/graph/def/Transition.java
jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/graph/node/EndState.java
Log:
improve hashCode/equals for GraphElement and Transition
simplify endCompleteProcess check in EndState
Modified: jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/graph/def/GraphElement.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/graph/def/GraphElement.java 2010-01-25 23:17:12 UTC (rev 6128)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/graph/def/GraphElement.java 2010-01-26 01:41:10 UTC (rev 6129)
@@ -210,7 +210,8 @@
}
// execute the runtime actions
- List runtimeActions = getRuntimeActionsForEvent(executionContext, eventType);
+ List runtimeActions =
+ getRuntimeActionsForEvent(executionContext, eventType);
executeActions(runtimeActions, executionContext, isPropagated);
// remove the event from the context
@@ -232,9 +233,10 @@
if (!action.acceptsPropagatedEvents() && isPropagated) continue;
if (action.isAsync()) {
- ExecuteActionJob job = createAsyncActionExecutionJob(
- executionContext.getToken(), action);
- MessageService messageService = (MessageService) Services.getCurrentService(Services.SERVICENAME_MESSAGE);
+ ExecuteActionJob job =
+ createAsyncActionExecutionJob(executionContext.getToken(), action);
+ MessageService messageService =
+ executionContext.getJbpmContext().getServices().getMessageService();
messageService.send(job);
}
else {
@@ -263,8 +265,8 @@
// the token needs to be locked. if this is an action
// being executed as the node behaviour or if the token
// is already locked, the token doesn't need to be locked.
- boolean actionMustBeLocked = executionContext.getEvent() != null
- && !token.isLocked();
+ boolean actionMustBeLocked =
+ executionContext.getEvent() != null && !token.isLocked();
try {
// update the execution context
@@ -278,7 +280,8 @@
token.lock(lockOwnerId);
}
- UserCodeInterceptor userCodeInterceptor = UserCodeInterceptorConfig.getUserCodeInterceptor();
+ UserCodeInterceptor userCodeInterceptor =
+ UserCodeInterceptorConfig.getUserCodeInterceptor();
if (userCodeInterceptor != null) {
userCodeInterceptor.executeAction(action, executionContext);
}
@@ -310,8 +313,8 @@
List getRuntimeActionsForEvent(ExecutionContext executionContext,
String eventType) {
List runtimeActionsForEvent = null;
- List runtimeActions = executionContext.getProcessInstance()
- .getRuntimeActions();
+ List runtimeActions =
+ executionContext.getProcessInstance().getRuntimeActions();
if (runtimeActions != null) {
for (Iterator iter = runtimeActions.iterator(); iter.hasNext();) {
RuntimeAction runtimeAction = (RuntimeAction) iter.next();
@@ -463,22 +466,50 @@
if (id != 0 && id == other.getId()) return true;
GraphElement parent = getParent();
- return (name != null ? name.equals(other.getName())
- : other.getName() == null)
- && (parent != null ? parent.equals(other.getParent())
- : other.getParent() == null);
+ GraphElement otherParent = other.getParent();
+
+ boolean result;
+ if (name != null && parent != null) {
+ result = name.equals(other.getName());
+ }
+ else if (parent instanceof NodeCollection
+ && otherParent instanceof NodeCollection) {
+ NodeCollection nodeCollection = (NodeCollection) parent;
+ int index = nodeCollection.getNodes().indexOf(this);
+ assert index != -1 : nodeCollection.getNodes();
+
+ NodeCollection otherNodeCollection = (NodeCollection) otherParent;
+ int otherIndex = otherNodeCollection.getNodes().indexOf(other);
+ result = index == otherIndex;
+ }
+ else {
+ return false;
+ }
+ return result && parent.equals(otherParent);
}
public int hashCode() {
- int result = 580399073 + (name != null ? name.hashCode() : 0);
GraphElement parent = getParent();
- result = 345105097 * result + (parent != null ? parent.hashCode() : 0);
- return result;
+
+ int result = 580399073;
+ if (name != null && parent != null) {
+ result += name.hashCode();
+ }
+ else if (parent instanceof NodeCollection) {
+ NodeCollection nodeCollection = (NodeCollection) parent;
+ int index = nodeCollection.getNodes().indexOf(this);
+ assert index != -1 : nodeCollection.getNodes();
+ result += index;
+ }
+ else {
+ return super.hashCode();
+ }
+ return 345105097 * result + parent.hashCode();
}
public String toString() {
return ClassUtil.getSimpleName(getClass())
- + (name != null ? '(' + name + ')'
+ + (name != null ? '(' + name + ')' : id != 0 ? "(" + id + ')'
: '@' + Integer.toHexString(hashCode()));
}
Modified: jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/graph/def/Transition.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/graph/def/Transition.java 2010-01-25 23:17:12 UTC (rev 6128)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/graph/def/Transition.java 2010-01-26 01:41:10 UTC (rev 6129)
@@ -173,7 +173,7 @@
+ " has no destination");
}
- // optimisation: check if there is a candidate superstate to be entered.
+ // optimisation: check if there is a candidate superstate to be entered
if (destination.getSuperState() != null) {
// collect all the superstates being left
List leavingSuperStates = collectAllSuperStates(destination, from);
@@ -189,7 +189,7 @@
}
void fireSuperStateLeaveEvents(ExecutionContext executionContext) {
- // optimisation: check if there is a candidate superstate to be left.
+ // optimisation: check if there is a candidate superstate to be left
if (executionContext.getTransitionSource().getSuperState() != null) {
// collect all the superstates being left
List leavingSuperStates =
@@ -224,8 +224,7 @@
*/
void fireSuperStateEvents(List superStates, String eventType,
ExecutionContext executionContext) {
- Iterator iter = superStates.iterator();
- while (iter.hasNext()) {
+ for (Iterator iter = superStates.iterator(); iter.hasNext();) {
SuperState leavingSuperState = (SuperState) iter.next();
leavingSuperState.fireEvent(eventType, executionContext);
}
@@ -242,14 +241,14 @@
return (name != null ? name.equals(other.getName())
: other.getName() == null)
- && (from != null ? from.equals(other.getFrom()) : other.getFrom() == null)
- && (to != null ? to.equals(other.getTo()) : other.getTo() == null);
+ && from != null && from.equals(other.getFrom());
}
public int hashCode() {
+ if (from == null) return System.identityHashCode(this);
+
int result = 580399073 + (name != null ? name.hashCode() : 0);
- result = 345105097 * result + (from != null ? from.hashCode() : 0);
- result = 345105097 * result + (to != null ? to.hashCode() : 0);
+ result = 345105097 * result + from.hashCode();
return result;
}
@@ -267,7 +266,6 @@
+ "'cause the from-node of this transition has already another leaving transition with the same name");
}
Map fromLeavingTransitions = from.getLeavingTransitionsMap();
- fromLeavingTransitions.remove(this.name);
fromLeavingTransitions.put(name, this);
}
this.name = name;
Modified: jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/graph/node/EndState.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/graph/node/EndState.java 2010-01-25 23:17:12 UTC (rev 6128)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/graph/node/EndState.java 2010-01-26 01:41:10 UTC (rev 6129)
@@ -33,7 +33,7 @@
private static final long serialVersionUID = 1L;
- String endCompleteProcess = null;
+ String endCompleteProcess;
public EndState() {
}
@@ -57,7 +57,7 @@
}
public void execute(ExecutionContext executionContext) {
- if ((endCompleteProcess != null) && (endCompleteProcess.equalsIgnoreCase("true"))) {
+ if ("true".equalsIgnoreCase(endCompleteProcess)) {
executionContext.getProcessInstance().end();
}
else {
More information about the jbpm-commits
mailing list