[jboss-user] [jBPM] - Re: Access variables bound to process instance during its lifecyle
Shobhit Tyagi
do-not-reply at jboss.com
Thu May 23 15:11:20 EDT 2013
Shobhit Tyagi [https://community.jboss.org/people/roxy1987] created the discussion
"Re: Access variables bound to process instance during its lifecyle"
To view the discussion, visit: https://community.jboss.org/message/819172#819172
--------------------------------------------------------------
To read a process variable you could use the following code :
public Map<String, Object> getProcessVariables(final long intProcessInstId
) {
StatefulKnowledgeSession objKSession = getSession(); //Get the session
Map<String, Object> hshVariables = null;
try {
hshVariables = objKSession.execute(new GenericCommand<Map<String, Object>>() {
private static final long serialVersionUID = 1L;
public Map<String, Object> execute(Context objContext) {
StatefulKnowledgeSession objKSession = ((KnowledgeCommandContext) objContext)
.getStatefulKnowledgesession();
org.jbpm.process.instance.ProcessInstance objProcessInstance = (org.jbpm.process.instance.
ProcessInstance) objKSession.
getProcessInstance(intProcessInstId);
VariableScopeInstance objVariableScope = (VariableScopeInstance) objProcessInstance.
getContextInstance(VariableScope.VARIABLE_SCOPE);
/*Obtiene las variables del Proceso*/
Map<String, Object> hshVariables = objVariableScope.getVariables();
return hshVariables;
}
});
} catch(Exception objException) {
objLogger.loggerError(objException);
}
return hshVariables;
}
And to put a variable in the process
public void setProcessVariables(final long intProcessInstId, final Map<String, Object> hshVariableMap)
{
StatefulKnowledgeSession objKSession = getSession(); //Get the session
try {
objKSession.execute(new GenericCommand<Map<String, Object>>() {
private static final long serialVersionUID = 1L;
public Map<String, Object> execute(Context objContext) {
StatefulKnowledgeSession objKSession = ((KnowledgeCommandContext) objContext).
getStatefulKnowledgesession();
org.jbpm.process.instance.ProcessInstance objProcessInstance = (org.jbpm.process.instance.
ProcessInstance) objKSession.
getProcessInstance(intProcessInstId);
VariableScopeInstance objVariableScope = (VariableScopeInstance) objProcessInstance.
getContextInstance(VariableScope.VARIABLE_SCOPE);
Iterator<Map.Entry<String, Object>> objIterator = hshVariableMap.entrySet().iterator();
Map.Entry<String, Object> objPairs;
while(objIterator.hasNext()) {
objPairs = (Map.Entry<String, Object>)objIterator.next();
objVariableScope.setVariable(objPairs.getKey(), objPairs.getValue());
}
return null;
}
});
} catch(Exception objException) {
objLogger.loggerError(objException);
}
}
--------------------------------------------------------------
Reply to this message by going to Community
[https://community.jboss.org/message/819172#819172]
Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/jboss-user/attachments/20130523/9a8c9589/attachment-0001.html
More information about the jboss-user
mailing list