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

📄 processdefinition.java

📁 jboss jpdl-3.2.2 nolib
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
  public Node addNode(Node node) {
    if (node == null) throw new IllegalArgumentException("can't add a null node to a processdefinition");
    if (nodes == null) nodes = new ArrayList();
    nodes.add(node);
    node.processDefinition = this;
    nodesMap = null;
    
    if( (node instanceof StartState)
        && (this.startState==null)
      ) {
      this.startState = node;
    }
    return node;
  }

  // javadoc description in NodeCollection
  public Node removeNode(Node node) {
    Node removedNode = null;
    if (node == null) throw new IllegalArgumentException("can't remove a null node from a process definition");
    if (nodes != null) {
      if (nodes.remove(node)) {
        removedNode = node;
        removedNode.processDefinition = null;
        nodesMap = null;
      }
    }
    
    if (startState==removedNode) {
      startState = null;
    }
    return removedNode;
  }

  // javadoc description in NodeCollection
  public void reorderNode(int oldIndex, int newIndex) {
    if ( (nodes!=null)
         && (Math.min(oldIndex, newIndex)>=0)
         && (Math.max(oldIndex, newIndex)<nodes.size()) ) {
      Object o = nodes.remove(oldIndex);
      nodes.add(newIndex, o);
    } else {
      throw new IndexOutOfBoundsException("couldn't reorder element from index '"+oldIndex+"' to index '"+newIndex+"' in nodeList '"+nodes+"'");
    }
  }

  // javadoc description in NodeCollection
  public String generateNodeName() {
    return generateNodeName(nodes);
  }

  // javadoc description in NodeCollection
  public Node findNode(String hierarchicalName) {
    return findNode(this, hierarchicalName);
  }

  public static String generateNodeName(List nodes) {
    String name = null;
    if (nodes==null) {
      name = "1";
    } else {
      int n = 1;
      while (containsName(nodes, Integer.toString(n))) n++;
      name = Integer.toString(n);
    }
    return name;
  }

  static boolean containsName(List nodes, String name) {
    Iterator iter = nodes.iterator();
    while (iter.hasNext()) {
      Node node = (Node) iter.next();
      if ( name.equals(node.getName()) ) {
        return true;
      }
    }
    return false;
  }

  public static Node findNode(NodeCollection nodeCollection, String hierarchicalName) {
    Node node = null;
    if ((hierarchicalName != null) && (!"".equals(hierarchicalName.trim())) ) {
      
      if ( (hierarchicalName.startsWith("/"))
            && (nodeCollection instanceof SuperState) ){
        nodeCollection = ((SuperState)nodeCollection).getProcessDefinition();
      }

      StringTokenizer tokenizer = new StringTokenizer(hierarchicalName, "/");
      while (tokenizer.hasMoreElements()) {
        String namePart = tokenizer.nextToken();
        if ("..".equals(namePart) ) {
          if (nodeCollection instanceof ProcessDefinition) {
            throw new JbpmException("couldn't find node '"+hierarchicalName+"' because of a '..' on the process definition.");
          }
          nodeCollection = (NodeCollection) ((GraphElement)nodeCollection).getParent();
        } else if ( tokenizer.hasMoreElements() ) {
          nodeCollection = (NodeCollection)nodeCollection.getNode(namePart);
        } else {
          node = nodeCollection.getNode(namePart);
        }
      }
    }
    return node;
  }
  
  public void setStartState(StartState startState) {
    if ( (this.startState!=startState)
         && (this.startState!=null) ){
      removeNode(this.startState);
    }
    this.startState = startState;
    if (startState!=null) {
      addNode(startState);
    }
  }

  public GraphElement getParent() {
    return null;
  }

  // actions //////////////////////////////////////////////////////////////////

  /**
   * creates a bidirectional relation between this process definition and the given action.
   * @throws IllegalArgumentException if action is null or if action.getName() is null.
   */
  public Action addAction(Action action) {
    if (action == null) throw new IllegalArgumentException("can't add a null action to an process definition");
    if (action.getName() == null) throw new IllegalArgumentException("can't add an unnamed action to an process definition");
    if (actions == null) actions = new HashMap();
    actions.put(action.getName(), action);
    action.processDefinition = this;
    return action;
  }

  /**
   * removes the bidirectional relation between this process definition and the given action.
   * @throws IllegalArgumentException if action is null or if the action was not present in the actions of this process definition.
   */
  public void removeAction(Action action) {
    if (action == null) throw new IllegalArgumentException("can't remove a null action from an process definition");
    if (actions != null) {
      if (! actions.containsValue(action)) {
        throw new IllegalArgumentException("can't remove an action that is not part of this process definition");
      }
      actions.remove(action.getName());
      action.processDefinition = null;
    }
  }

  public Action getAction(String name) {
    if (actions == null) return null;
    return (Action) actions.get(name);
  }
  
  public Map getActions() {
    return actions;
  }

  public boolean hasActions() {
    return ( (actions!=null)
             && (actions.size()>0) );
  }

  // module definitions ///////////////////////////////////////////////////////

  public Object createInstance() {
    return new ProcessInstance(this);
  }

  public ModuleDefinition addDefinition(ModuleDefinition moduleDefinition) {
    if (moduleDefinition == null) throw new IllegalArgumentException("can't add a null moduleDefinition to a process definition");
    if (definitions == null)
      definitions = new HashMap();
    definitions.put(moduleDefinition.getClass().getName(), moduleDefinition);
    moduleDefinition.setProcessDefinition(this);
    return moduleDefinition;
  }
  
  public ModuleDefinition removeDefinition(ModuleDefinition moduleDefinition) {
    ModuleDefinition removedDefinition = null;
    if (moduleDefinition == null) throw new IllegalArgumentException("can't remove a null moduleDefinition from a process definition");
    if (definitions != null) {
      removedDefinition = (ModuleDefinition) definitions.remove(moduleDefinition.getClass().getName());
      if (removedDefinition!=null) {
        moduleDefinition.setProcessDefinition(null);
      }
    }
    return removedDefinition;
  }

  public ModuleDefinition getDefinition(Class clazz) {
    ModuleDefinition moduleDefinition = null;
    if (definitions != null) {
      moduleDefinition = (ModuleDefinition) definitions.get(clazz.getName());
    }
    return moduleDefinition;
  }
  
  public ContextDefinition getContextDefinition() {
    return (ContextDefinition) getDefinition(ContextDefinition.class);
  }

  public FileDefinition getFileDefinition() {
    return (FileDefinition) getDefinition(FileDefinition.class);
  }
  public TaskMgmtDefinition getTaskMgmtDefinition() {
    return (TaskMgmtDefinition) getDefinition(TaskMgmtDefinition.class);
  }

  public Map getDefinitions() {
    return definitions;
  }

  public void setDefinitions(Map definitions) {
    this.definitions = definitions;
  }

  // getters and setters //////////////////////////////////////////////////////

  public int getVersion() {
    return version;
  }

  public void setVersion(int version) {
    this.version = version;
  }

  public Node getStartState() {
    return startState;
  }
  
  public void setStartState(Node startState) {
    this.startState = startState;
  }

  public boolean isTerminationImplicit() {
    return isTerminationImplicit;
  }

  public void setTerminationImplicit(boolean isTerminationImplicit) {
    this.isTerminationImplicit = isTerminationImplicit;
  }
}

⌨️ 快捷键说明

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