public Object invoke(MethodInvocation methodInvocation) throws Throwable { String methodName = methodInvocation.getMethod().getName() ; logger.info("method invocation for " + methodName+ "."); if(methodName.equals("toString")) return "SharedProcessInstance"; ProcessInstance processInstance = Context.getExecutionContext().getProcessInstance(); Method method = methodInvocation.getMethod(); Object[] args = methodInvocation.getArguments(); Object result = method.invoke(processInstance, args); return result; } });
private void persistVariable(String variableName, Object scopedObject) { ProcessInstance processInstance = Context.getExecutionContext().getProcessInstance(); ExecutionEntity executionEntity = (ExecutionEntity) processInstance; Assert.isTrue(scopedObject instanceof Serializable, "the scopedObject is not " + Serializable.class.getName() + "!"); executionEntity.setVariable(variableName, scopedObject); } }
@Override public java.lang.Object get(java.lang.Object o) { Assert.isInstanceOf(String.class, o, "the 'key' must be a String"); String varName = (String) o; ProcessInstance processInstance = Context.getExecutionContext().getProcessInstance(); ExecutionEntity executionEntity = (ExecutionEntity) processInstance; if (executionEntity.getVariableNames().contains(varName)) { return executionEntity.getVariable(varName); } throw new RuntimeException("no processVariable by the name of '" + varName + "' is available!"); } };
public Object resolveContextualObject(String key) { if ("executionId".equalsIgnoreCase(key)) return Context.getExecutionContext().getExecution().getId(); if ("processInstance".equalsIgnoreCase(key)) return Context.getExecutionContext().getProcessInstance(); if ("processInstanceId".equalsIgnoreCase(key)) return Context.getExecutionContext().getProcessInstance().getId(); return null; }
protected ClassLoader resolveProcessArchiveClassLoader() { final DeploymentCache deploymentCache = Context.getProcessEngineConfiguration().getDeploymentCache(); final ExecutionContext executionContext = getExecutionContext(); if (executionContext != null) { String processDefinitionId = executionContext.getProcessInstance().getProcessDefinitionId(); // check whether the process definition is deployed to the cache. // if the process definition is not deployed to the cache, we do not attempt // to resolve the deploymentClassloader since the process archive is undeployed. if (deploymentCache.getProcessDefinitionCache().containsKey(processDefinitionId)) { String processDefinitionKey = executionContext.getProcessDefinition().getKey(); // look up the classloader for that processDefinition: return deploymentClassloaderMap.get(processDefinitionKey); } } return null; }
public Object get(String name, ObjectFactory<?> objectFactory) { ExecutionEntity executionEntity = null; try { logger.fine("returning scoped object having beanName '" + name + "' for conversation ID '" + this.getConversationId() + "'. "); ProcessInstance processInstance = Context.getExecutionContext().getProcessInstance(); executionEntity = (ExecutionEntity) processInstance; Object scopedObject = executionEntity.getVariable(name); if (scopedObject == null) { scopedObject = objectFactory.getObject(); if (scopedObject instanceof ScopedObject) { ScopedObject sc = (ScopedObject) scopedObject; scopedObject = sc.getTargetObject(); logger.fine("de-referencing " + ScopedObject.class.getName() + "#targetObject before persisting variable"); } persistVariable(name, scopedObject); } return createDirtyCheckingProxy(name, scopedObject); } catch (Throwable th) { logger.warning("couldn't return value from process scope! " + ExceptionUtils.getFullStackTrace(th)); } finally { if (executionEntity != null) { logger.fine("set variable '" + name + "' on executionEntity# " + executionEntity.getId()); } } return null; }