2 Replies Latest reply on Jul 16, 2007 12:58 PM by Randy Gullett

    ProcessState 'leave' method

    Randy Gullett Newbie

      The leave method for ProcessStates currently automatically takes the default transition despite taking a transition as a parameter. Can it be modified so that it leaves by the transition passed in (if it isn't null) like you'd expect it to? I want to be able to short-circuit my subprocesses in certain scenarios. See the method as it's currently coded below.

      public void leave(ExecutionContext executionContext, Transition transition) {
      ProcessInstance subProcessInstance = executionContext.getSubProcessInstance();

      Token superProcessToken = subProcessInstance.getSuperProcessToken();

      // feed the readable variableInstances
      if ((variableAccesses != null) && (!variableAccesses.isEmpty())) {

      ContextInstance superContextInstance = executionContext.getContextInstance();
      ContextInstance subContextInstance = subProcessInstance.getContextInstance();

      // loop over all the variable accesses
      Iterator iter = variableAccesses.iterator();
      while (iter.hasNext()) {
      VariableAccess variableAccess = (VariableAccess) iter.next();
      // if this variable access is writable
      if (variableAccess.isWritable()) {
      // the variable is copied from the sub process mapped name
      // to the super process variable name
      String mappedName = variableAccess.getMappedName();
      Object value = subContextInstance.getVariable(mappedName);
      String variableName = variableAccess.getVariableName();
      log.debug("copying sub process var '"+mappedName+"' to super process var '"+variableName+"': "+value);
      if (value!=null) {
      superContextInstance.setVariable(variableName, value, superProcessToken);

      // fire the subprocess ended event
      fireEvent(Event.EVENTTYPE_SUBPROCESS_END, executionContext);

      // remove the subprocess reference

      // We replaced the normal log generation of super.leave() by creating the log here
      // and overriding the addNodeLog method with an empty version
      superProcessToken.addLog(new ProcessStateLog(this, superProcessToken.getNodeEnter(), new Date(), subProcessInstance));

      // call the subProcessEndAction
      super.leave(executionContext, getDefaultLeavingTransition()); }

      The bold line could be replaced by something like:

      if(transition != null) {
      super.leave(executionContext, transition);
      } else {
      super.leave(executionContext, getDefaultLeavingTransition());