osworkflow,transientVars的传递

 

以前一直对于为什么 osworkflow在pre-function, beanshell,post-function等里面可以随便调用context,store,等信息

表示不解。

我们do一个action的步骤是先 new BasicWorkflow(username), username会被 用来constructer 一个BasicWorkflowContext, 目前为止BasicWorkflowContext类中只有一个caller属性。BasicWorkflow extends AbstractWorkflow, 在AbstractWorkflow中有 protected Configuration configuration; protected ThreadLocal stateCache = new ThreadLocal(); protected WorkflowContext context; private TypeResolver typeResolver; 这些属性。因此BasicWorkflowContext会被 赋值给context。我们注意到第一个attribute is Configuration ,因此我们可以通过Configuration 得到 workflowStor等信息。

因此也就可以在doAction(long id, int actionId, Map inputs)中有下列代码,

。。。。。。。

transientVars.put("context", context); transientVars.put("entry", entry); transientVars.put("store", getPersistence()); transientVars.put("configuration", getConfiguration()); transientVars.put("descriptor", getConfiguration().getWorkflow(entry.getWorkflowName()));

。。。。。。

到时我们就可以在pre-function,post-function等功能 中取出 它们。 之所以可以取出它们 是在处理<action>中的每个功能时,都会把transientVars做为参数传过去。

经验分享 程序员 微信小程序 职场和发展