[jboss-user] [JBoss jBPM] - Re: Confused about variable and token association

mteira do-not-reply at jboss.com
Tue Sep 5 07:38:45 EDT 2006


Hello again.
I think that I've found the problem. It's how the variable is initialized in the ActioHandler:

if (!ci.hasVariable(varName, executionContext.getToken())) {
  |   ci.setVariable(varName, new Integer(0), executionContext.getToken());
  | }
 
ContextInstance.setVariable(String name, Object value, Token token) resolves the TokenVariableMap using getOrCreateTokenVariableMap, that delegates on the parent Token when the var doesn't exist on the current token:

   // if the given token has a variable map
  |     TokenVariableMap tokenVariableMap = null;
  |     if ( (tokenVariableMaps!=null)
  |          && (tokenVariableMaps.containsKey(token))
  |        ) {
  |       tokenVariableMap = (TokenVariableMap) tokenVariableMaps.get(token);
  | 
  |     } else if (!token.isRoot()) {
  |       tokenVariableMap = getOrCreateTokenVariableMap(token.getParent());
  |       
  |     } else {
  |       tokenVariableMap = createTokenVariableMap(token);
  |     }
  | 

So, the only way to force a variable to be created in the current Token is to use the function:
public void createVariable(String name, Object value, Token token)
that uses createTokenVariableMap(Token token) to do the work.

So, using ContextInstance.setVariable(String name, Object value, Token token) is always delegating into the parent context when the variable name doesn't exist in the current Token tokenVariableMap.

I find this a little confusing. Is it the expected behaviour?

Regards.


View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3969439#3969439

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3969439



More information about the jboss-user mailing list