[jbpm-commits] JBoss JBPM SVN: r3487 - in jbpm3/trunk/modules: core/src/main/java/org/jbpm/graph/node and 1 other directories.
do-not-reply at jboss.org
do-not-reply at jboss.org
Sat Dec 20 10:47:24 EST 2008
Author: thomas.diesler at jboss.com
Date: 2008-12-20 10:47:24 -0500 (Sat, 20 Dec 2008)
New Revision: 3487
Modified:
jbpm3/trunk/modules/core/src/main/java/org/jbpm/graph/def/Node.java
jbpm3/trunk/modules/core/src/main/java/org/jbpm/graph/node/Decision.java
jbpm3/trunk/modules/integration/src/main/java/org/jbpm/integration/spec/runtime/TokenAttachmentDelegate.java
Log:
Choke if there is no default transition
Modified: jbpm3/trunk/modules/core/src/main/java/org/jbpm/graph/def/Node.java
===================================================================
--- jbpm3/trunk/modules/core/src/main/java/org/jbpm/graph/def/Node.java 2008-12-20 15:46:33 UTC (rev 3486)
+++ jbpm3/trunk/modules/core/src/main/java/org/jbpm/graph/def/Node.java 2008-12-20 15:47:24 UTC (rev 3487)
@@ -267,9 +267,17 @@
public Transition getDefaultLeavingTransition()
{
Transition defaultTransition = null;
- if ((leavingTransitions != null) && (leavingTransitions.size() > 0))
+ if (leavingTransitions != null)
{
- defaultTransition = (Transition)leavingTransitions.get(0);
+ // Select the first unconditional transition
+ for (Transition auxTransition : leavingTransitions)
+ {
+ if (auxTransition.getCondition() == null)
+ {
+ defaultTransition = auxTransition;
+ break;
+ }
+ }
}
else if (superState != null)
{
Modified: jbpm3/trunk/modules/core/src/main/java/org/jbpm/graph/node/Decision.java
===================================================================
--- jbpm3/trunk/modules/core/src/main/java/org/jbpm/graph/node/Decision.java 2008-12-20 15:46:33 UTC (rev 3486)
+++ jbpm3/trunk/modules/core/src/main/java/org/jbpm/graph/node/Decision.java 2008-12-20 15:47:24 UTC (rev 3487)
@@ -41,8 +41,8 @@
/**
* decision node.
*/
-public class Decision extends Node implements Parsable {
-
+public class Decision extends Node implements Parsable
+{
static final String NEWLINE = System.getProperty("line.separator");
static final String DECISION_CONDITION_RESULT = "decision_condition_result";
static final long serialVersionUID = 1L;
@@ -51,10 +51,12 @@
Delegation decisionDelegation = null;
String decisionExpression = null;
- public Decision() {
+ public Decision()
+ {
}
- public Decision(String name) {
+ public Decision(String name)
+ {
super(name);
}
@@ -64,86 +66,110 @@
return NodeType.Decision;
}
- public void read(Element decisionElement, JpdlXmlReader jpdlReader) {
+ public void read(Element decisionElement, JpdlXmlReader jpdlReader)
+ {
String expression = decisionElement.attributeValue("expression");
Element decisionHandlerElement = decisionElement.element("handler");
- if (expression!=null) {
+ if (expression != null)
+ {
decisionExpression = expression;
- } else if (decisionHandlerElement!=null) {
+ }
+ else if (decisionHandlerElement != null)
+ {
decisionDelegation = new Delegation();
decisionDelegation.read(decisionHandlerElement, jpdlReader);
}
}
- public void execute(ExecutionContext executionContext) {
+ public void execute(ExecutionContext executionContext)
+ {
Transition transition = null;
ClassLoader surroundingClassLoader = Thread.currentThread().getContextClassLoader();
- try {
- // set context class loader correctly for delegation class (https://jira.jboss.org/jira/browse/JBPM-1448)
+ try
+ {
+ // set context class loader correctly for delegation class (https://jira.jboss.org/jira/browse/JBPM-1448)
Thread.currentThread().setContextClassLoader(JbpmConfiguration.getProcessClassLoader(executionContext.getProcessDefinition()));
- try {
- if (decisionDelegation != null) {
+ try
+ {
+ if (decisionDelegation != null)
+ {
DecisionHandler decisionHandler = (DecisionHandler)decisionDelegation.getInstance();
if (decisionHandler == null)
- decisionHandler = (DecisionHandler) decisionDelegation.instantiate();
-
+ decisionHandler = (DecisionHandler)decisionDelegation.instantiate();
+
String transitionName = decisionHandler.decide(executionContext);
transition = getLeavingTransition(transitionName);
- if (transition == null) {
+ if (transition == null)
+ {
throw new JbpmException("decision '" + name + "' selected non existing transition '" + transitionName + "'");
}
- } else if (decisionExpression != null) {
+ }
+ else if (decisionExpression != null)
+ {
Object result = JbpmExpressionEvaluator.evaluate(decisionExpression, executionContext);
- if (result == null) {
+ if (result == null)
+ {
throw new JbpmException("decision expression '" + decisionExpression + "' returned null");
}
String transitionName = result.toString();
transition = getLeavingTransition(transitionName);
- if (transition == null) {
+ if (transition == null)
+ {
throw new JbpmException("decision '" + name + "' selected non existing transition '" + transitionName + "'");
}
- } else if (decisionConditions != null && !decisionConditions.isEmpty()) {
+ }
+ else if (decisionConditions != null && !decisionConditions.isEmpty())
+ {
// backwards compatible mode based on separate DecisionCondition's
Iterator iter = decisionConditions.iterator();
- while (iter.hasNext() && (transition == null)) {
- DecisionCondition decisionCondition = (DecisionCondition) iter.next();
+ while (iter.hasNext() && (transition == null))
+ {
+ DecisionCondition decisionCondition = (DecisionCondition)iter.next();
Object result = JbpmExpressionEvaluator.evaluate(decisionCondition.getExpression(), executionContext);
- if (Boolean.TRUE.equals(result)) {
+ if (Boolean.TRUE.equals(result))
+ {
String transitionName = decisionCondition.getTransitionName();
transition = getLeavingTransition(transitionName);
- if (transition != null) {
+ if (transition != null)
+ {
transition.removeConditionEnforcement();
}
}
}
-
- } else {
+ }
+ else
+ {
// new mode based on conditions in the transition itself
Iterator iter = leavingTransitions.iterator();
- while (iter.hasNext() && (transition == null)) {
- Transition candidate = (Transition) iter.next();
+ while (iter.hasNext() && (transition == null))
+ {
+ Transition candidate = (Transition)iter.next();
String conditionExpression = candidate.getCondition();
- if (conditionExpression != null) {
+ if (conditionExpression != null)
+ {
Object result = JbpmExpressionEvaluator.evaluate(conditionExpression, executionContext);
- if (Boolean.TRUE.equals(result)) {
+ if (Boolean.TRUE.equals(result))
+ {
transition = candidate;
}
}
}
-
}
- if (transition == null) {
+ if (transition == null)
transition = getDefaultLeavingTransition();
- log.debug("decision didn't select transition, taking default " + transition);
- }
+
+ if (transition == null)
+ throw new IllegalStateException("decision cannot select transition: " + this);
+
+ log.debug("decision didn't select transition, taking default " + transition);
// since the decision node evaluates condition expressions, the
// condition of the
@@ -153,25 +179,30 @@
// node.
transition.removeConditionEnforcement();
- } catch (Exception exception) {
+ }
+ catch (Exception exception)
+ {
raiseException(exception, executionContext);
}
}
- finally {
+ finally
+ {
Thread.currentThread().setContextClassLoader(surroundingClassLoader);
- }
- log.debug("decision "+name+" is taking '"+transition+"'");
+ }
+ log.debug("decision " + name + " is taking '" + transition + "'");
executionContext.leaveNode(transition);
}
- public List getDecisionConditions() {
+ public List getDecisionConditions()
+ {
return decisionConditions;
}
-
- public void setDecisionDelegation(Delegation decisionDelegation) {
+
+ public void setDecisionDelegation(Delegation decisionDelegation)
+ {
this.decisionDelegation = decisionDelegation;
}
-
+
private static Log log = LogFactory.getLog(Decision.class);
}
Modified: jbpm3/trunk/modules/integration/src/main/java/org/jbpm/integration/spec/runtime/TokenAttachmentDelegate.java
===================================================================
--- jbpm3/trunk/modules/integration/src/main/java/org/jbpm/integration/spec/runtime/TokenAttachmentDelegate.java 2008-12-20 15:46:33 UTC (rev 3486)
+++ jbpm3/trunk/modules/integration/src/main/java/org/jbpm/integration/spec/runtime/TokenAttachmentDelegate.java 2008-12-20 15:47:24 UTC (rev 3487)
@@ -27,6 +27,7 @@
import java.util.HashSet;
import java.util.Set;
+import org.jboss.bpm.api.NotImplementedException;
import org.jboss.bpm.api.runtime.Attachments;
import org.jbpm.context.exe.ContextInstance;
@@ -60,8 +61,8 @@
@SuppressWarnings("unchecked")
public <T> T addAttachment(Class<T> clazz, String name, Object value)
{
- Key key = new Key(clazz, name);
- context.createVariable(key.toString(), value, token.getDelegate());
+ validateAttachmentKey(clazz, name);
+ context.createVariable(name, value, token.getDelegate());
return (T)value;
}
@@ -78,8 +79,8 @@
@SuppressWarnings("unchecked")
public <T> T getAttachment(Class<T> clazz, String name)
{
- Key key = new Key(clazz, name);
- return (T)context.getVariable(key.toString(), token.getDelegate());
+ validateAttachmentKey(clazz, name);
+ return (T)context.getVariable(name, token.getDelegate());
}
@SuppressWarnings("unchecked")
@@ -89,18 +90,16 @@
Set<String> strKeys = context.getVariables(token.getDelegate()).keySet();
for (String strKey : strKeys)
{
- Key key = Key.valueOf(strKey);
- if (key != null)
- keys.add(key);
+ Key key = new Key(null, strKey);
+ keys.add(key);
}
return keys;
}
public <T> T removeAttachment(Class<T> clazz, String name)
{
- Key key = new Key(clazz, name);
T value = getAttachment(clazz, name);
- context.deleteVariable(key.toString(), token.getDelegate());
+ context.deleteVariable(name, token.getDelegate());
return value;
}
@@ -113,4 +112,13 @@
{
return removeAttachment(null, name);
}
+
+ private <T> void validateAttachmentKey(Class<T> clazz, String name)
+ {
+ if (clazz != null)
+ throw new NotImplementedException("Attachments keyed by Class not supported");
+
+ if (name == null)
+ throw new NotImplementedException("Attachments with null name not supported");
+ }
}
\ No newline at end of file
More information about the jbpm-commits
mailing list