⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 taskmgmtinstance.java

📁 workflow first jbpm
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
      }
      pooledActors = (String[]) pooledActorList.toArray(new String[pooledActorList.size()]);
    } else {
      throw new JbpmException("pooled-actors expression '"+pooledActorsExpression+"' didn't resolve to a comma separated String, a Collection or a String[]: '"+result+"' ("+result.getClass().getName()+")");
    }

    assignable.setPooledActors(pooledActors);
  }

  /**
   * creates a task instance on the rootToken, and assigns it 
   * to the currently authenticated user.
   */
  public TaskInstance createStartTaskInstance() {
    TaskInstance taskInstance = null;
    Task startTask = taskMgmtDefinition.getStartTask();
    if (startTask!=null) {
      Token rootToken = processInstance.getRootToken();
      ExecutionContext executionContext = new ExecutionContext(rootToken);
      taskInstance = createTaskInstance(startTask, executionContext);
      taskInstance.setActorId(SecurityHelper.getAuthenticatedActorId());
    }
    return taskInstance;
  }

  TaskInstance instantiateNewTaskInstance(ExecutionContext executionContext) {
    TaskInstance newTaskInstance = null;
    TaskInstanceFactory taskInstanceFactory = (TaskInstanceFactory) JbpmConfiguration.Configs.getObject("jbpm.task.instance.factory"); 
    try {
      newTaskInstance = taskInstanceFactory.createTaskInstance(executionContext);
    } catch (NullPointerException e) {
      throw new JbpmException("jbpm.task.instance.factory was not configured in jbpm.cfg.xml", e);
    } catch (Exception e) {
      e.printStackTrace();
      throw new JbpmException("couldn't instantiate task instance with task instance factory '"+taskInstanceFactory+"'", e);
    }
    return newTaskInstance;
  }

  /**
   * is true if the given token has task instances that keep the 
   * token from leaving the current node.
   */
  public boolean hasBlockingTaskInstances(Token token) {
    boolean hasBlockingTasks = false;
    if (taskInstances!=null) {
      Iterator iter = taskInstances.iterator();
      while ( (iter.hasNext())
              && (! hasBlockingTasks)) {
        TaskInstance taskInstance = (TaskInstance) iter.next();
        if ( (! taskInstance.hasEnded())
             && (taskInstance.isBlocking())
             && (token!=null)
             && (token.equals(taskInstance.getToken())) ) {
          hasBlockingTasks = true;
        }
      }
    }
    return hasBlockingTasks;
  }

  /**
   * is true if the given token has task instances that are not yet ended.
   */
  public boolean hasUnfinishedTasks(Token token) {
    return (getUnfinishedTasks(token).size()>0);
  }

  /**
   * is the collection of {@link TaskInstance}s on the given token that are not ended.
   */
  public Collection getUnfinishedTasks(Token token) {
    Collection unfinishedTasks = new ArrayList();
    if ( taskInstances != null ) {
      Iterator iter = taskInstances.iterator();
      while (iter.hasNext()) {
        TaskInstance task = (TaskInstance) iter.next();
        if ( (!task.hasEnded())
             && (token!=null)
             && (token.equals(task.getToken())) 
           ) {
          unfinishedTasks.add( task );
        }
      }
    }
    return unfinishedTasks;
  }

  /**
   * is true if there are {@link TaskInstance}s on the given token that can trigger 
   * the token to continue.
   */
  public boolean hasSignallingTasks(ExecutionContext executionContext) {
    return (getSignallingTasks(executionContext).size()>0);
  }

  /**
   * is the collection of {@link TaskInstance}s for the given token that can trigger 
   * the token to continue.
   */
  public Collection getSignallingTasks(ExecutionContext executionContext) {
    Collection signallingTasks = new ArrayList();
    if ( taskInstances != null ) {
      Iterator iter = taskInstances.iterator();
      while (iter.hasNext()) {
        TaskInstance taskInstance = (TaskInstance) iter.next();
        if (taskInstance.isSignalling()
            &&(executionContext.getToken().equals(taskInstance.getToken()))) {
          signallingTasks.add(taskInstance);
        }
      }
    }
    return signallingTasks;
  }
  
  /**
   * returns all the taskInstances for the this process instance.  This 
   * includes task instances that have been completed previously.
   */
  public Collection getTaskInstances() {
    return taskInstances;
  }
  public void addTaskInstance(TaskInstance taskInstance) {
    if (taskInstances==null) taskInstances = new HashSet();
    taskInstances.add(taskInstance);
    taskInstance.setTaskMgmtInstance(this);
  }
  public void removeTaskInstance(TaskInstance taskInstance) {
    if (taskInstances!=null) {
      taskInstances.remove(taskInstance);
    }
  }

  // swimlane instances ///////////////////////////////////////////////////////

  public Map getSwimlaneInstances() {
    return swimlaneInstances;
  }
  public void addSwimlaneInstance( SwimlaneInstance swimlaneInstance ) {
    if (swimlaneInstances==null) swimlaneInstances = new HashMap();
    swimlaneInstances.put(swimlaneInstance.getName(), swimlaneInstance);
    swimlaneInstance.setTaskMgmtInstance(this);
  }
  public SwimlaneInstance getSwimlaneInstance(String swimlaneName) {
    return (SwimlaneInstance) (swimlaneInstances!=null ? swimlaneInstances.get(swimlaneName) : null );
  }

  public SwimlaneInstance createSwimlaneInstance(String swimlaneName) {
    Swimlane swimlane = (taskMgmtDefinition!=null ? taskMgmtDefinition.getSwimlane(swimlaneName) : null);
    if (swimlane!=null) {
      return createSwimlaneInstance(swimlane);
    }
    throw new JbpmException("couldn't create swimlane instance for non-existing swimlane "+swimlaneName);
  }

  public SwimlaneInstance createSwimlaneInstance(Swimlane swimlane) {
    if (swimlaneInstances==null) swimlaneInstances = new HashMap();
    SwimlaneInstance swimlaneInstance = new SwimlaneInstance(swimlane);
    try {
      swimlaneInstance.setTaskMgmtInstance(this);
      Class persistentMapClass = swimlaneInstances.getClass();
      Field mapField = persistentMapClass.getDeclaredField("map");
      mapField.setAccessible(true);
      // TODO remove the size when we switch to hibernate 3.2.1 (it's a workaround for a bug)
      swimlaneInstances.size();
      swimlaneInstances.put(swimlaneInstance.getName(), swimlaneInstance);
    } catch (Exception e) {
      e.printStackTrace();
    }
    return swimlaneInstance;
  }
  
  // getters and setters //////////////////////////////////////////////////////

  public TaskMgmtDefinition getTaskMgmtDefinition() {
    return taskMgmtDefinition;
  }

  /**
   * suspends all task instances for this process instance.
   */
  public void suspend(Token token) {
    if (token==null) {
      throw new JbpmException("can't suspend task instances for token null");
    }
    if (taskInstances!=null) {
      Iterator iter = taskInstances.iterator();
      while (iter.hasNext()) {
        TaskInstance taskInstance = (TaskInstance) iter.next();
        if ( (token.equals(taskInstance.getToken()))
             && (taskInstance.isOpen())
           ) {
          taskInstance.suspend();
        }
      }
    }
  }

  /**
   * resumes all task instances for this process instance.
   */
  public void resume(Token token) {
    if (token==null) {
      throw new JbpmException("can't suspend task instances for token null");
    }
    if (taskInstances!=null) {
      Iterator iter = taskInstances.iterator();
      while (iter.hasNext()) {
        TaskInstance taskInstance = (TaskInstance) iter.next();
        if ( (token.equals(taskInstance.getToken()))
            && (taskInstance.isOpen())
          ) {
          taskInstance.resume();
        }
      }
    }
  }
  
  void notifyVariableUpdate(TaskInstance taskInstance) {
    if (taskInstanceVariableUpdates==null) {
      taskInstanceVariableUpdates=new HashSet();
    }
    taskInstanceVariableUpdates.add(taskInstance);
  }
  /**
   * returns the collection of task instance with variable updates.
   */
  public Collection getTaskInstancesWithVariableUpdates() {
    return taskInstanceVariableUpdates;
  }

  /**
   * convenience method to end all tasks related to a given process instance.
   */
  public void endAll() {
    if (taskInstances!=null) {
      Iterator iter = taskInstances.iterator();
      while (iter.hasNext()) {
        TaskInstance taskInstance = (TaskInstance) iter.next();
        if (!taskInstance.hasEnded()) {
          taskInstance.end();
        }
      }
    }
  }

  /**
   * removes signalling capabilities from all task instances related to the given token.
   */
  public void removeSignalling(Token token) {
    if (taskInstances!=null) {
      Iterator iter = taskInstances.iterator();
      while (iter.hasNext()) {
        TaskInstance taskInstance = (TaskInstance) iter.next();
        if ( (token!=null)
             && (token.equals(taskInstance.getToken()))
           ) {
          taskInstance.setSignalling(false);
        }
      }
    }
  }
  private static final Log log = LogFactory.getLog(TaskMgmtInstance.class);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -