[jbpm-commits] JBoss JBPM SVN: r3367 - in jbpm3/trunk/modules/core/src: main/java/org/jbpm/graph/exe and 2 other directories.
do-not-reply at jboss.org
do-not-reply at jboss.org
Fri Dec 12 09:00:33 EST 2008
Author: thomas.diesler at jboss.com
Date: 2008-12-12 09:00:33 -0500 (Fri, 12 Dec 2008)
New Revision: 3367
Added:
jbpm3/trunk/modules/core/src/test/java/org/jbpm/jbpm1778/
jbpm3/trunk/modules/core/src/test/java/org/jbpm/jbpm1778/JBPM1778Test.java
Modified:
jbpm3/trunk/modules/core/src/main/java/org/jbpm/context/exe/ContextInstance.java
jbpm3/trunk/modules/core/src/main/java/org/jbpm/graph/exe/ProcessInstance.java
Log:
[JBPM-1778] Empty map variables on process creation is set as null
Modified: jbpm3/trunk/modules/core/src/main/java/org/jbpm/context/exe/ContextInstance.java
===================================================================
--- jbpm3/trunk/modules/core/src/main/java/org/jbpm/context/exe/ContextInstance.java 2008-12-12 13:05:58 UTC (rev 3366)
+++ jbpm3/trunk/modules/core/src/main/java/org/jbpm/context/exe/ContextInstance.java 2008-12-12 14:00:33 UTC (rev 3367)
@@ -40,7 +40,8 @@
* More information on context and process variableInstances can be found in
* <a href="../../../../../userguide/en/html/reference.html#context">the userguide, section context</a>
*/
-public class ContextInstance extends ModuleInstance {
+public class ContextInstance extends ModuleInstance
+{
private static final long serialVersionUID = 1L;
@@ -49,336 +50,372 @@
// maps variablenames (String) to values (Object)
protected transient Map transientVariables = null;
protected transient List updatedVariableContainers = null;
-
- public ContextInstance() {
+
+ public ContextInstance()
+ {
}
// normal variableInstances (persistent) ////////////////////////////////////
- /**
- * creates a variable on the root-token (= process-instance scope) and
- * calculates the actual VariableInstance-type from the value.
+ /*
+ * creates a variable on the root-token (= process-instance scope) and calculates the actual VariableInstance-type from the value.
*/
- public void createVariable(String name, Object value) {
+ public void createVariable(String name, Object value)
+ {
setVariableLocally(name, value, getRootToken());
}
- /**
- * sets the variable on the root token, creates the variable if necessary and
- * calculates the actual VariableInstance-type from the value.
+ /*
+ * sets the variable on the root token, creates the variable if necessary and calculates the actual VariableInstance-type from the value.
*/
- public void setVariableLocally(String name, Object value) {
+ public void setVariableLocally(String name, Object value)
+ {
setVariableLocally(name, value, getRootToken());
}
- /**
- * creates a variable in the scope of the given token and calculates the
- * actual VariableInstance-type from the value.
+ /*
+ * creates a variable in the scope of the given token and calculates the actual VariableInstance-type from the value.
*/
- public void createVariable(String name, Object value, Token token) {
+ public void createVariable(String name, Object value, Token token)
+ {
setVariableLocally(name, value, token);
}
- /**
- * creates a variable in the scope of the given token and calculates the
- * actual VariableInstance-type from the value.
+ /*
+ * creates a variable in the scope of the given token and calculates the actual VariableInstance-type from the value.
*/
- public void setVariableLocally(String name, Object value, Token token) {
+ public void setVariableLocally(String name, Object value, Token token)
+ {
TokenVariableMap tokenVariableMap = createTokenVariableMap(token);
tokenVariableMap.setVariableLocally(name, value);
}
- /**
+ /*
* gets all the variableInstances on the root-token (= process-instance scope).
*/
- public Map getVariables() {
+ public Map getVariables()
+ {
return getVariables(getRootToken());
}
- /**
+ /*
* retrieves all the variableInstances in scope of the given token.
*/
- public Map getVariables(Token token) {
+ public Map getVariables(Token token)
+ {
Map variables = null;
TokenVariableMap tokenVariableMap = getTokenVariableMap(token);
- if (tokenVariableMap != null) {
+ if (tokenVariableMap != null)
+ {
variables = tokenVariableMap.getVariables();
}
return variables;
}
- /**
+ /*
* adds all the variableInstances on the root-token (= process-instance scope).
*/
- public void addVariables(Map variables) {
+ public void addVariables(Map variables)
+ {
setVariables(variables, getRootToken());
}
- /**
- * The method setVariables is the same as the {@link #addVariables(Map, Token)},
- * but it was added for more consistency.
+ /*
+ * The method setVariables is the same as the {@link #addVariables(Map, Token)}, but it was added for more consistency.
*/
- public void setVariables(Map variables) {
+ public void setVariables(Map variables)
+ {
setVariables(variables, getRootToken());
}
- /**
- * adds all the variableInstances to the scope of the given token.
- * This method delegates to {@link #setVariables(Map, Token)}.
- * The method setVariables was added for more consistency.
+ /*
+ * adds all the variableInstances to the scope of the given token. This method delegates to {@link #setVariables(Map, Token)}. The method setVariables was added for
+ * more consistency.
*/
- public void addVariables(Map variables, Token token) {
+ public void addVariables(Map variables, Token token)
+ {
setVariables(variables, token);
}
- /**
- * adds all the variableInstances to the scope of the given token.
- * The method setVariables is the same as the {@link #addVariables(Map, Token)},
- * but it was added for more consistency.
+ /*
+ * adds all the variableInstances to the scope of the given token. The method setVariables is the same as the {@link #addVariables(Map, Token)}, but it was added for
+ * more consistency.
*/
- public void setVariables(Map variables, Token token) {
+ public void setVariables(Map variables, Token token)
+ {
+ // [JBPM-1778] Empty map variables on process creation is set as null
+ TokenVariableMap tokenVariableMap = getOrCreateTokenVariableMap(token);
Iterator iter = variables.entrySet().iterator();
- while (iter.hasNext()) {
- Map.Entry entry = (Map.Entry) iter.next();
- String name = (String) entry.getKey();
+ while (iter.hasNext())
+ {
+ Map.Entry entry = (Map.Entry)iter.next();
+ String name = (String)entry.getKey();
Object value = entry.getValue();
- setVariable(name, value, token);
+ tokenVariableMap.setVariable(name, value);
}
}
- /**
- * gets the variable with the given name on the root-token (= process-instance
- * scope).
+ /*
+ * gets the variable with the given name on the root-token (= process-instance scope).
*/
- public Object getVariable(String name) {
+ public Object getVariable(String name)
+ {
return getVariable(name, getRootToken());
}
- /**
- * retrieves a variable in the scope of the token. If the given token does not
- * have a variable for the given name, the variable is searched for up the
- * token hierarchy.
+ /*
+ * retrieves a variable in the scope of the token. If the given token does not have a variable for the given name, the variable is searched for up the token
+ * hierarchy.
*/
- public Object getVariable(String name, Token token) {
+ public Object getVariable(String name, Token token)
+ {
Object variable = null;
TokenVariableMap tokenVariableMap = getTokenVariableMap(token);
- if (tokenVariableMap != null) {
+ if (tokenVariableMap != null)
+ {
variable = tokenVariableMap.getVariable(name);
}
return variable;
}
- /**
- * retrieves a variable which is local to the token.
- * Method {@link #getVariableLocally(String, Token)} is the same
- * as this method and it was added for naming consistency.
+ /*
+ * retrieves a variable which is local to the token. Method {@link #getVariableLocally(String, Token)} is the same as this method and it was added for naming
+ * consistency.
*/
- public Object getLocalVariable(String name, Token token) {
+ public Object getLocalVariable(String name, Token token)
+ {
return getVariableLocally(name, token);
}
- /**
- * retrieves a variable which is local to the token.
- * this method was added for naming consistency. it is the same
- * as {@link #getLocalVariable(String, Token)}.
+ /*
+ * retrieves a variable which is local to the token. this method was added for naming consistency. it is the same as {@link #getLocalVariable(String, Token)}.
*/
- public Object getVariableLocally(String name, Token token) {
+ public Object getVariableLocally(String name, Token token)
+ {
Object variable = null;
- if (tokenVariableMaps!=null && tokenVariableMaps.containsKey(token)) {
- TokenVariableMap tokenVariableMap = (TokenVariableMap) tokenVariableMaps.get(token);
- if (tokenVariableMap != null) {
+ if (tokenVariableMaps != null && tokenVariableMaps.containsKey(token))
+ {
+ TokenVariableMap tokenVariableMap = (TokenVariableMap)tokenVariableMaps.get(token);
+ if (tokenVariableMap != null)
+ {
variable = tokenVariableMap.getVariableLocally(name);
}
}
return variable;
}
- /**
+ /*
* sets a variable on the process instance scope.
*/
- public void setVariable(String name, Object value) {
+ public void setVariable(String name, Object value)
+ {
setVariable(name, value, getRootToken());
}
- /**
- * sets a variable. If a variable exists in the scope given by the token, that
- * variable is updated. Otherwise, the variable is created on the root token
- * (=process instance scope).
+ /*
+ * sets a variable. If a variable exists in the scope given by the token, that variable is updated. Otherwise, the variable is created on the root token (=process
+ * instance scope).
*/
- public void setVariable(String name, Object value, Token token) {
+ public void setVariable(String name, Object value, Token token)
+ {
TokenVariableMap tokenVariableMap = getOrCreateTokenVariableMap(token);
tokenVariableMap.setVariable(name, value);
}
- /**
- * checks if a variable is present with the given name on the root-token (=
- * process-instance scope).
+ /*
+ * checks if a variable is present with the given name on the root-token (= process-instance scope).
*/
- public boolean hasVariable(String name) {
+ public boolean hasVariable(String name)
+ {
return hasVariable(name, getRootToken());
}
- /**
- * checks if a variable is present with the given name in the scope of the
- * token.
+ /*
+ * checks if a variable is present with the given name in the scope of the token.
*/
- public boolean hasVariable(String name, Token token) {
+ public boolean hasVariable(String name, Token token)
+ {
boolean hasVariable = false;
TokenVariableMap tokenVariableMap = getTokenVariableMap(token);
- if (tokenVariableMap != null) {
+ if (tokenVariableMap != null)
+ {
hasVariable = tokenVariableMap.hasVariable(name);
}
return hasVariable;
}
- /**
+ /*
* deletes the given variable on the root-token (=process-instance scope).
*/
- public void deleteVariable(String name) {
+ public void deleteVariable(String name)
+ {
deleteVariable(name, getRootToken());
}
- /**
- * deletes a variable from the given token. For safety reasons, this method does
- * not propagate the deletion to parent tokens in case the given token does not contain
- * the variable.
+ /*
+ * deletes a variable from the given token. For safety reasons, this method does not propagate the deletion to parent tokens in case the given token does not contain
+ * the variable.
*/
- public void deleteVariable(String name, Token token) {
+ public void deleteVariable(String name, Token token)
+ {
TokenVariableMap tokenVariableMap = getTokenVariableMap(token);
- if (tokenVariableMap != null) {
+ if (tokenVariableMap != null)
+ {
tokenVariableMap.deleteVariable(name);
}
}
// transient variableInstances //////////////////////////////////////////////
- /**
+ /*
* retrieves the transient variable for the given name.
*/
- public Object getTransientVariable(String name) {
+ public Object getTransientVariable(String name)
+ {
Object transientVariable = null;
- if (transientVariables!= null) {
+ if (transientVariables != null)
+ {
transientVariable = transientVariables.get(name);
}
return transientVariable;
}
- /**
+ /*
* sets the transient variable for the given name to the given value.
*/
- public void setTransientVariable(String name, Object value) {
- if (transientVariables == null) {
+ public void setTransientVariable(String name, Object value)
+ {
+ if (transientVariables == null)
+ {
transientVariables = new HashMap();
}
transientVariables.put(name, value);
}
- /**
+ /*
* tells if a transient variable with the given name is present.
*/
- public boolean hasTransientVariable(String name) {
- if (transientVariables == null) {
+ public boolean hasTransientVariable(String name)
+ {
+ if (transientVariables == null)
+ {
return false;
}
return transientVariables.containsKey(name);
}
- /**
- * retrieves all the transient variableInstances map. note that no deep copy is
- * performed, changing the map leads to changes in the transient variableInstances of
+ /*
+ * retrieves all the transient variableInstances map. note that no deep copy is performed, changing the map leads to changes in the transient variableInstances of
* this context instance.
*/
- public Map getTransientVariables() {
+ public Map getTransientVariables()
+ {
return transientVariables;
}
- /**
+ /*
* replaces the transient variableInstances with the given map.
*/
- public void setTransientVariables(Map transientVariables) {
+ public void setTransientVariables(Map transientVariables)
+ {
this.transientVariables = transientVariables;
}
- /**
+ /*
* removes the transient variable.
*/
- public void deleteTransientVariable(String name) {
+ public void deleteTransientVariable(String name)
+ {
if (transientVariables == null)
return;
transientVariables.remove(name);
}
-
- Token getRootToken() {
+ Token getRootToken()
+ {
return processInstance.getRootToken();
}
- /**
- * searches for the first token-variable-map for the given token
- * and creates it on the root token if it doesn't exist.
+ /*
+ * searches for the first token-variable-map for the given token and creates it on the root token if it doesn't exist.
*/
- public TokenVariableMap getOrCreateTokenVariableMap(Token token) {
- if (token==null) {
+ public TokenVariableMap getOrCreateTokenVariableMap(Token token)
+ {
+ if (token == null)
+ {
throw new JbpmException("can't get variables for token 'null'");
}
// if the given token has a variable map
TokenVariableMap tokenVariableMap = null;
- if ( (tokenVariableMaps!=null)
- && (tokenVariableMaps.containsKey(token))
- ) {
- tokenVariableMap = (TokenVariableMap) tokenVariableMaps.get(token);
+ if ((tokenVariableMaps != null) && (tokenVariableMaps.containsKey(token)))
+ {
+ tokenVariableMap = (TokenVariableMap)tokenVariableMaps.get(token);
- } else if (!token.isRoot()) {
+ }
+ else if (!token.isRoot())
+ {
tokenVariableMap = getOrCreateTokenVariableMap(token.getParent());
-
- } else {
+
+ }
+ else
+ {
tokenVariableMap = createTokenVariableMap(token);
}
-
+
return tokenVariableMap;
}
- TokenVariableMap createTokenVariableMap(Token token) {
- if (tokenVariableMaps==null) {
+ TokenVariableMap createTokenVariableMap(Token token)
+ {
+ if (tokenVariableMaps == null)
+ {
tokenVariableMaps = new HashMap();
}
- TokenVariableMap tokenVariableMap = (TokenVariableMap) tokenVariableMaps.get(token);
- if (tokenVariableMap==null) {
+ TokenVariableMap tokenVariableMap = (TokenVariableMap)tokenVariableMaps.get(token);
+ if (tokenVariableMap == null)
+ {
tokenVariableMap = new TokenVariableMap(token, this);
tokenVariableMaps.put(token, tokenVariableMap);
}
return tokenVariableMap;
}
- /**
- * looks for the first token-variable-map that is found
- * up the token-parent hirarchy.
+ /*
+ * looks for the first token-variable-map that is found up the token-parent hirarchy.
*/
- public TokenVariableMap getTokenVariableMap(Token token) {
+ public TokenVariableMap getTokenVariableMap(Token token)
+ {
TokenVariableMap tokenVariableMap = null;
- if (tokenVariableMaps!=null) {
- if (tokenVariableMaps.containsKey(token)) {
- tokenVariableMap = (TokenVariableMap) tokenVariableMaps.get(token);
- } else if (! token.isRoot()) {
+ if (tokenVariableMaps != null)
+ {
+ if (tokenVariableMaps.containsKey(token))
+ {
+ tokenVariableMap = (TokenVariableMap)tokenVariableMaps.get(token);
+ }
+ else if (!token.isRoot())
+ {
tokenVariableMap = getTokenVariableMap(token.getParent());
}
}
return tokenVariableMap;
}
- public VariableInstance getVariableInstance(String name, Token token) {
+ public VariableInstance getVariableInstance(String name, Token token)
+ {
VariableInstance variableInstance = null;
TokenVariableMap tokenVariableMap = getTokenVariableMap(token);
- if (tokenVariableMap!=null) {
+ if (tokenVariableMap != null)
+ {
tokenVariableMap.getVariableInstances();
}
return variableInstance;
}
- public Map getTokenVariableMaps() {
+ public Map getTokenVariableMaps()
+ {
return tokenVariableMaps;
}
}
Modified: jbpm3/trunk/modules/core/src/main/java/org/jbpm/graph/exe/ProcessInstance.java
===================================================================
--- jbpm3/trunk/modules/core/src/main/java/org/jbpm/graph/exe/ProcessInstance.java 2008-12-12 13:05:58 UTC (rev 3366)
+++ jbpm3/trunk/modules/core/src/main/java/org/jbpm/graph/exe/ProcessInstance.java 2008-12-12 14:00:33 UTC (rev 3367)
@@ -60,20 +60,20 @@
private static final long serialVersionUID = 1L;
- long id = 0;
- int version = 0;
- protected String key = null;
- protected Date start = null;
- protected Date end = null;
- protected ProcessDefinition processDefinition = null;
- protected Token rootToken = null;
- protected Token superProcessToken = null;
- protected boolean isSuspended = false;
- protected Map instances = null;
- protected Map transientInstances = null;
- protected List runtimeActions = null;
+ long id;
+ int version;
+ protected String key;
+ protected Date start;
+ protected Date end;
+ protected ProcessDefinition processDefinition;
+ protected Token rootToken;
+ protected Token superProcessToken;
+ protected boolean isSuspended;
+ protected Map instances;
+ protected Map transientInstances;
+ protected List runtimeActions;
/** not persisted */
- protected List cascadeProcessInstances = null;
+ protected List cascadeProcessInstances;
// constructors /////////////////////////////////////////////////////////////
Added: jbpm3/trunk/modules/core/src/test/java/org/jbpm/jbpm1778/JBPM1778Test.java
===================================================================
--- jbpm3/trunk/modules/core/src/test/java/org/jbpm/jbpm1778/JBPM1778Test.java (rev 0)
+++ jbpm3/trunk/modules/core/src/test/java/org/jbpm/jbpm1778/JBPM1778Test.java 2008-12-12 14:00:33 UTC (rev 3367)
@@ -0,0 +1,55 @@
+package org.jbpm.jbpm1778;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.jbpm.AbstractJbpmTestCase;
+import org.jbpm.JbpmConfiguration;
+import org.jbpm.JbpmContext;
+import org.jbpm.graph.def.ProcessDefinition;
+import org.jbpm.graph.exe.ProcessInstance;
+import org.jbpm.taskmgmt.exe.TaskMgmtInstance;
+
+/**
+ * Empty map variables on process creation is set as null
+ *
+ * https://jira.jboss.org/jira/browse/JBPM-1778
+ *
+ * @author Thomas.Diesler at jboss.com
+ */
+public class JBPM1778Test extends AbstractJbpmTestCase
+{
+
+ public void testEmptyMapVariables()
+ {
+ JbpmContext jbpmContext = JbpmConfiguration.getInstance().createJbpmContext();
+ try
+ {
+ HashMap<String, String> vars = new HashMap<String, String>();
+ // vars.put("uno", "dos");
+
+ ProcessDefinition pd = ProcessDefinition.parseXmlString(
+ "<process-definition>" +
+ " <start-state>" +
+ " <transition to='s' />" +
+ " </start-state>" +
+ " <state name='s'>" +
+ " <transition to='end' />" +
+ " </state>" +
+ " <end-state name='end' />" +
+ "</process-definition>");
+
+ ProcessInstance pi = pd.createProcessInstance(vars);
+ TaskMgmtInstance tmi = pi.getTaskMgmtInstance();
+ tmi.createStartTaskInstance();
+
+ Map piVars = pi.getContextInstance().getVariables();
+ assertNotNull("ProcessInstance vars not null", piVars);
+ assertEquals("ProcessInstance vars empty", 0, piVars.size());
+ }
+ finally
+ {
+ jbpmContext.close();
+ }
+ }
+}
Property changes on: jbpm3/trunk/modules/core/src/test/java/org/jbpm/jbpm1778/JBPM1778Test.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
More information about the jbpm-commits
mailing list