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

📄 node.java

📁 jboss jpdl-3.2.2 nolib
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*
 * JBoss, Home of Professional Open Source
 * Copyright 2005, JBoss Inc., and individual contributors as indicated
 * by the @authors tag. See the copyright.txt in the distribution for a
 * full listing of individual contributors.
 *
 * This is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this software; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 */
package org.jbpm.graph.def;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
import java.util.Map;
import java.util.Set;

import org.dom4j.Element;
import org.jbpm.JbpmException;
import org.jbpm.graph.action.ActionTypes;
import org.jbpm.graph.exe.ExecutionContext;
import org.jbpm.graph.exe.Token;
import org.jbpm.graph.log.NodeLog;
import org.jbpm.job.ExecuteNodeJob;
import org.jbpm.job.Job;
import org.jbpm.jpdl.xml.JpdlXmlReader;
import org.jbpm.jpdl.xml.Parsable;
import org.jbpm.msg.MessageService;
import org.jbpm.svc.Services;
import org.jbpm.util.Clock;

public class Node extends GraphElement implements Parsable {
  
  private static final long serialVersionUID = 1L;
  
  protected List leavingTransitions = null;
  transient Map leavingTransitionMap = null;
  protected Set arrivingTransitions = null;
  protected Action action = null;
  protected SuperState superState = null;
  protected boolean isAsync = false;
  protected boolean isAsyncExclusive = false;

  // event types //////////////////////////////////////////////////////////////

  public static final String[] supportedEventTypes = new String[]{Event.EVENTTYPE_NODE_ENTER,Event.EVENTTYPE_NODE_LEAVE,Event.EVENTTYPE_BEFORE_SIGNAL,Event.EVENTTYPE_AFTER_SIGNAL};
  public String[] getSupportedEventTypes() {
    return supportedEventTypes;
  }

  // constructors /////////////////////////////////////////////////////////////

  /**
   * creates an unnamed node.
   */
  public Node() {
  }

  /**
   * creates a node with the given name.
   */
  public Node(String name) {
    super(name);
  }

  public void read(Element nodeElement, JpdlXmlReader jpdlXmlReader) {
    action = jpdlXmlReader.readSingleAction(nodeElement);
  }
  
  public void write(Element nodeElement) {
    if (action!=null) {
      String actionName = ActionTypes.getActionName(action.getClass());
      Element actionElement = nodeElement.addElement(actionName);
      action.write(actionElement);
    }
  }

  // leaving transitions //////////////////////////////////////////////////////
  
  public List getLeavingTransitions() {
    return leavingTransitions;
  }

  /**
   * are the leaving {@link Transition}s, mapped by their name (java.lang.String).
   */
  public Map getLeavingTransitionsMap() {
    if ( (leavingTransitionMap==null)
         && (leavingTransitions!=null) ){
      // initialize the cached leaving transition map
      leavingTransitionMap = new HashMap();
      ListIterator iter = leavingTransitions.listIterator(leavingTransitions.size());
      while (iter.hasPrevious()) {
        Transition leavingTransition = (Transition) iter.previous();
        leavingTransitionMap.put(leavingTransition.getName(), leavingTransition);
      }
    }
    return leavingTransitionMap;
  }

  /**
   * creates a bidirection relation between this node and the given leaving transition.
   * @throws IllegalArgumentException if leavingTransition is null.
   */
  public Transition addLeavingTransition(Transition leavingTransition) {
    if (leavingTransition == null) throw new IllegalArgumentException("can't add a null leaving transition to an node");
    if (leavingTransitions == null) leavingTransitions = new ArrayList();
    leavingTransitions.add(leavingTransition);
    leavingTransition.from = this;
    leavingTransitionMap = null;
    return leavingTransition;
  }

  /**
   * removes the bidirection relation between this node and the given leaving transition.
   * @throws IllegalArgumentException if leavingTransition is null.
   */
  public void removeLeavingTransition(Transition leavingTransition) {
    if (leavingTransition == null) throw new IllegalArgumentException("can't remove a null leavingTransition from an node");
    if (leavingTransitions != null) {
      if (leavingTransitions.remove(leavingTransition)) {
        leavingTransition.from = null;
        leavingTransitionMap = null;
      }
    }
  }

  /**
   * checks for the presence of a leaving transition with the given name.
   * @return true if this node has a leaving transition with the given name,
   *         false otherwise.
   */
  public boolean hasLeavingTransition(String transitionName) {
    if (leavingTransitions==null) return false;
    return getLeavingTransitionsMap().containsKey(transitionName);
  }

  /**
   * retrieves a leaving transition by name. note that also the leaving
   * transitions of the supernode are taken into account.
   */
  public Transition getLeavingTransition(String transitionName) {
    Transition transition = null;
    if (leavingTransitions!=null) {
      transition = (Transition) getLeavingTransitionsMap().get(transitionName);
    }
    if ( (transition==null)
         && (superState!=null)
       ) {
      transition = superState.getLeavingTransition(transitionName); 
    }
    return transition;
  }

  /**
   * true if this transition has leaving transitions. 
   */
  public boolean hasNoLeavingTransitions() {
    return ( ( (leavingTransitions == null) 
               || (leavingTransitions.size() == 0) ) 
             && ( (superState==null) 
                  || (superState.hasNoLeavingTransitions() ) ) );
  }

  /**
   * generates a new name for a transition that will be added as a leaving transition. 
   */
  public String generateNextLeavingTransitionName() {
    String name = null;
    if (leavingTransitions!=null) {
      if (!containsName(leavingTransitions, null)) {
        name = null;
      } else {
        int n = 1;
        while (containsName(leavingTransitions, Integer.toString(n))) n++;
        name = Integer.toString(n);
      }
    }
    return name;
  }

  boolean containsName(List leavingTransitions, String name) {
    Iterator iter = leavingTransitions.iterator();
    while (iter.hasNext()) {
      Transition transition = (Transition) iter.next();
      if ( (name==null) && (transition.getName()==null) ) {
        return true;
      } else if ( (name!=null) && (name.equals(transition.getName())) ) {
        return true;
      }
    }
    return false;
  }

  // default leaving transition and leaving transition ordering ///////////////

  /**
   * is the default leaving transition.
   */
  public Transition getDefaultLeavingTransition() {
    Transition defaultTransition = null;
    if ( (leavingTransitions!=null)
         && (leavingTransitions.size()>0) ) {
      defaultTransition = (Transition) leavingTransitions.get(0);
    } else if ( superState!=null ){
      defaultTransition = superState.getDefaultLeavingTransition();
    }
    return defaultTransition;
  }

  /**
   * moves one leaving transition from the oldIndex and inserts it at the newIndex.
   */
  public void reorderLeavingTransition( int oldIndex, int newIndex ) {
    if ( (leavingTransitions!=null)
         && (Math.min(oldIndex, newIndex)>=0)
         && (Math.max(oldIndex, newIndex)<leavingTransitions.size()) ) {
      Object o = leavingTransitions.remove(oldIndex);
      leavingTransitions.add(newIndex, o);
    }
  }

  public List getLeavingTransitionsList() {
    return leavingTransitions;
  }

  // arriving transitions /////////////////////////////////////////////////////

  /**
   * are the arriving transitions.
   */

⌨️ 快捷键说明

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