[jbpm-commits] JBoss JBPM SVN: r3828 - jbpm3/trunk/modules/core/src/main/java/org/jbpm/graph/node.
do-not-reply at jboss.org
do-not-reply at jboss.org
Wed Feb 11 04:15:02 EST 2009
Author: thomas.diesler at jboss.com
Date: 2009-02-11 04:15:01 -0500 (Wed, 11 Feb 2009)
New Revision: 3828
Modified:
jbpm3/trunk/modules/core/src/main/java/org/jbpm/graph/node/ProcessState.java
Log:
[JBPM-1899] Add setVariableAccess accessor to ProcessState
Modified: jbpm3/trunk/modules/core/src/main/java/org/jbpm/graph/node/ProcessState.java
===================================================================
--- jbpm3/trunk/modules/core/src/main/java/org/jbpm/graph/node/ProcessState.java 2009-02-11 08:27:12 UTC (rev 3827)
+++ jbpm3/trunk/modules/core/src/main/java/org/jbpm/graph/node/ProcessState.java 2009-02-11 09:15:01 UTC (rev 3828)
@@ -47,13 +47,14 @@
import org.jbpm.jpdl.xml.JpdlXmlReader;
import org.jbpm.util.Clock;
-public class ProcessState extends Node {
+public class ProcessState extends Node
+{
+ private static final long serialVersionUID = 1L;
- private static final long serialVersionUID = 1L;
-
static SubProcessResolver defaultSubProcessResolver = new DbSubProcessResolver();
- public static void setDefaultSubProcessResolver(SubProcessResolver subProcessResolver) {
+ public static void setDefaultSubProcessResolver(SubProcessResolver subProcessResolver)
+ {
defaultSubProcessResolver = subProcessResolver;
}
@@ -63,75 +64,105 @@
// event types //////////////////////////////////////////////////////////////
- public static final String[] supportedEventTypes = new String[] { Event.EVENTTYPE_SUBPROCESS_CREATED, Event.EVENTTYPE_SUBPROCESS_END,
- Event.EVENTTYPE_NODE_ENTER, Event.EVENTTYPE_NODE_LEAVE, Event.EVENTTYPE_BEFORE_SIGNAL, Event.EVENTTYPE_AFTER_SIGNAL };
+ public static final String[] supportedEventTypes = new String[] { Event.EVENTTYPE_SUBPROCESS_CREATED, Event.EVENTTYPE_SUBPROCESS_END, Event.EVENTTYPE_NODE_ENTER,
+ Event.EVENTTYPE_NODE_LEAVE, Event.EVENTTYPE_BEFORE_SIGNAL, Event.EVENTTYPE_AFTER_SIGNAL };
- public String[] getSupportedEventTypes() {
+ public String[] getSupportedEventTypes()
+ {
return supportedEventTypes;
}
+ // [JBPM-1899] Add setVariableAccess accessor to ProcessState
+ public Set<VariableAccess> getVariableAccesses()
+ {
+ return variableAccesses;
+ }
+
+ public void setVariableAccesses(Set<VariableAccess> variableAccesses)
+ {
+ this.variableAccesses = variableAccesses;
+ }
+
// xml //////////////////////////////////////////////////////////////////////
- public void read(Element processStateElement, JpdlXmlReader jpdlReader) {
+ public void read(Element processStateElement, JpdlXmlReader jpdlReader)
+ {
Element subProcessElement = processStateElement.element("sub-process");
-
- if (subProcessElement!=null) {
-
+
+ if (subProcessElement != null)
+ {
+
String binding = subProcessElement.attributeValue("binding");
- if ("late".equalsIgnoreCase(binding)) {
+ if ("late".equalsIgnoreCase(binding))
+ {
subProcessName = subProcessElement.attributeValue("name");
- } else {
-
+ }
+ else
+ {
+
SubProcessResolver subProcessResolver = getSubProcessResolver();
- try {
+ try
+ {
subProcessDefinition = subProcessResolver.findSubProcess(subProcessElement);
- } catch (JbpmException e) {
+ }
+ catch (JbpmException e)
+ {
jpdlReader.addWarning(e.getMessage());
}
// in case this is a self-recursive process invocation...
- if (subProcessDefinition==null) {
+ if (subProcessDefinition == null)
+ {
String subProcessName = subProcessElement.attributeValue("name");
- if (subProcessName.equals(processDefinition.getName())) {
+ if (subProcessName.equals(processDefinition.getName()))
+ {
subProcessDefinition = processDefinition;
}
}
}
}
-
- if (subProcessDefinition!=null) {
- log.debug("subprocess for process-state '"+name+"' bound to "+subProcessDefinition);
- } else if (subProcessName!=null ){
- log.debug("subprocess for process-state '"+name+"' will be late bound to "+subProcessName);
- } else {
- log.debug("subprocess for process-state '"+name+"' not yet bound");
+
+ if (subProcessDefinition != null)
+ {
+ log.debug("subprocess for process-state '" + name + "' bound to " + subProcessDefinition);
}
+ else if (subProcessName != null)
+ {
+ log.debug("subprocess for process-state '" + name + "' will be late bound to " + subProcessName);
+ }
+ else
+ {
+ log.debug("subprocess for process-state '" + name + "' not yet bound");
+ }
this.variableAccesses = new HashSet<VariableAccess>(jpdlReader.readVariableAccesses(processStateElement));
}
- private SubProcessResolver getSubProcessResolver() {
+ private SubProcessResolver getSubProcessResolver()
+ {
SubProcessResolver subProcessResolver = defaultSubProcessResolver;
- if (JbpmConfiguration.Configs.hasObject("jbpm.sub.process.resolver")) {
- subProcessResolver = (SubProcessResolver) JbpmConfiguration.Configs.getObject("jbpm.sub.process.resolver");
+ if (JbpmConfiguration.Configs.hasObject("jbpm.sub.process.resolver"))
+ {
+ subProcessResolver = (SubProcessResolver)JbpmConfiguration.Configs.getObject("jbpm.sub.process.resolver");
}
return subProcessResolver;
}
-
- public void execute(ExecutionContext executionContext) {
+
+ public void execute(ExecutionContext executionContext)
+ {
Token superProcessToken = executionContext.getToken();
-
+
ProcessDefinition usedSubProcessDefinition = subProcessDefinition;
// if this process has late binding
- if ( (subProcessDefinition==null)
- && (subProcessName!=null)
- ) {
+ if ((subProcessDefinition == null) && (subProcessName != null))
+ {
SubProcessResolver subProcessResolver = getSubProcessResolver();
List<FlyweightAttribute> attributes = new ArrayList<FlyweightAttribute>();
- String subProcessNameResolved = (String) JbpmExpressionEvaluator.evaluate(subProcessName, executionContext);
- if (log.isDebugEnabled()) {
- log.debug("SubProcessName after eval: " + subProcessNameResolved);
+ String subProcessNameResolved = (String)JbpmExpressionEvaluator.evaluate(subProcessName, executionContext);
+ if (log.isDebugEnabled())
+ {
+ log.debug("SubProcessName after eval: " + subProcessNameResolved);
}
attributes.add(new FlyweightAttribute("name", subProcessNameResolved));
Element subProcessElement = new DefaultElement("sub-process");
@@ -147,23 +178,27 @@
fireEvent(Event.EVENTTYPE_SUBPROCESS_CREATED, executionContext);
// feed the readable variableInstances
- if ((variableAccesses != null) && (!variableAccesses.isEmpty())) {
+ if ((variableAccesses != null) && (!variableAccesses.isEmpty()))
+ {
ContextInstance superContextInstance = executionContext.getContextInstance();
ContextInstance subContextInstance = subProcessInstance.getContextInstance();
subContextInstance.setTransientVariables(superContextInstance.getTransientVariables());
// loop over all the variable accesses
- for (VariableAccess variableAccess : variableAccesses) {
+ for (VariableAccess variableAccess : variableAccesses)
+ {
// if this variable access is readable
- if (variableAccess.isReadable()) {
+ if (variableAccess.isReadable())
+ {
// the variable is copied from the super process variable name
// to the sub process mapped name
String variableName = variableAccess.getVariableName();
Object value = superContextInstance.getVariable(variableName, superProcessToken);
String mappedName = variableAccess.getMappedName();
- log.debug("copying super process var '"+variableName+"' to sub process var '"+mappedName+"': "+value);
- if (value!=null) {
+ log.debug("copying super process var '" + variableName + "' to sub process var '" + mappedName + "': " + value);
+ if (value != null)
+ {
subContextInstance.setVariable(mappedName, value);
}
}
@@ -173,31 +208,34 @@
// send the signal to start the subprocess
subProcessInstance.signal();
}
-
-
- public void leave(ExecutionContext executionContext, Transition transition) {
+ public void leave(ExecutionContext executionContext, Transition transition)
+ {
ProcessInstance subProcessInstance = executionContext.getSubProcessInstance();
Token superProcessToken = subProcessInstance.getSuperProcessToken();
// feed the readable variableInstances
- if ((variableAccesses != null) && (!variableAccesses.isEmpty())) {
+ if ((variableAccesses != null) && (!variableAccesses.isEmpty()))
+ {
ContextInstance superContextInstance = executionContext.getContextInstance();
ContextInstance subContextInstance = subProcessInstance.getContextInstance();
// loop over all the variable accesses
- for (VariableAccess variableAccess : variableAccesses) {
+ for (VariableAccess variableAccess : variableAccesses)
+ {
// if this variable access is writable
- if (variableAccess.isWritable()) {
+ if (variableAccess.isWritable())
+ {
// the variable is copied from the sub process mapped name
// to the super process variable name
String mappedName = variableAccess.getMappedName();
Object value = subContextInstance.getVariable(mappedName);
String variableName = variableAccess.getVariableName();
- log.debug("copying sub process var '"+mappedName+"' to super process var '"+variableName+"': "+value);
- if (value!=null) {
+ log.debug("copying sub process var '" + mappedName + "' to super process var '" + variableName + "': " + value);
+ if (value != null)
+ {
superContextInstance.setVariable(variableName, value, superProcessToken);
}
}
@@ -209,26 +247,30 @@
// remove the subprocess reference
superProcessToken.setSubProcessInstance(null);
-
+
// We replaced the normal log generation of super.leave() by creating the log here
- // and overriding the addNodeLog method with an empty version
+ // and overriding the addNodeLog method with an empty version
superProcessToken.addLog(new ProcessStateLog(this, superProcessToken.getNodeEnter(), Clock.getCurrentTime(), subProcessInstance));
// call the subProcessEndAction
super.leave(executionContext, getDefaultLeavingTransition());
}
- // We replaced the normal log generation of super.leave() by creating the log above in the leave method
- // and overriding the addNodeLog method with an empty version
- protected void addNodeLog(Token token) {
+ // We replaced the normal log generation of super.leave() by creating the log above in the leave method
+ // and overriding the addNodeLog method with an empty version
+ protected void addNodeLog(Token token)
+ {
}
- public ProcessDefinition getSubProcessDefinition() {
+ public ProcessDefinition getSubProcessDefinition()
+ {
return subProcessDefinition;
}
- public void setSubProcessDefinition(ProcessDefinition subProcessDefinition) {
+
+ public void setSubProcessDefinition(ProcessDefinition subProcessDefinition)
+ {
this.subProcessDefinition = subProcessDefinition;
}
-
+
private static Log log = LogFactory.getLog(ProcessState.class);
}
More information about the jbpm-commits
mailing list