nodeimpl.java

来自「一个java工作流引擎」· Java 代码 · 共 87 行

JAVA
87
字号
package org.jbpm.model.definition.impl;

import java.util.*;
import org.jbpm.*;
import org.jbpm.model.definition.*;
import org.jbpm.model.execution.impl.*;

public abstract class NodeImpl extends ElementImpl implements Node {

  private Collection leavingTransitions = null;

	public NodeImpl() {}

  public NodeImpl(String name) {
    super( name );
  }

  public Collection getLeavingTransitions() { return this.leavingTransitions; }
  public void setLeavingTransitions(Collection leavingTransitions) { this.leavingTransitions = leavingTransitions; }
  public TransitionImpl addLeavingTransition(TransitionImpl transition) {
    if ( transition != null ) {
      if ( leavingTransitions == null ) leavingTransitions = new HashSet();
      
      String transitionName = transition.getName();
      if ( transitionName != null ) {
        Iterator iter = leavingTransitions.iterator();
				while (iter.hasNext()) {
					TransitionImpl other = (TransitionImpl) iter.next();
					if ( transitionName.equals( other.getName() ) ) {
            throw new IllegalStateException( "duplicate transition name '" + transitionName +"' in node '" + name + "'"); 
          }
				}
      }
      
      leavingTransitions.add( transition );
    }
    return transition;
  }
  public void removeLeavingTransition(TransitionImpl transition) {
    if ( ( transition != null ) 
         && ( leavingTransitions != null ) ) {
      leavingTransitions.remove( transition );
      transition.setFrom( null );
    }
  }

  public TransitionImpl getLeavingTransition( String transitionName ) throws IllegalTransitionException {
    TransitionImpl transition = null;
    if ( transitionName != null ) {
      Iterator iter = leavingTransitions.iterator();
			while ( (iter.hasNext() )
              && ( transition==null ) ) {
				TransitionImpl candidate = (TransitionImpl) iter.next();
				if ( transitionName.equals( candidate.getName() ) ) {
          transition = candidate;
        }
			}
      if ( transition == null ) {
        throw new IllegalTransitionException( "transition '" + transitionName + "' is not a leaving transition of state " + name );
      }
    } else {
      if ( leavingTransitions.size() != 1 ) {
        throw new IllegalTransitionException( "no transitionName is specified while state '" + name + "' has " + leavingTransitions.size() + " leaving transitions : " + leavingTransitions );
      }
      transition = (TransitionImpl) leavingTransitions.iterator().next();
    }

    return transition;
  }
  
  public abstract void acceptToken( ExecutionContextImpl executionContext ) throws ExecutionException;
	public abstract EventType getDefaultEventType();
  
  public abstract void toXml(org.dom4j.Element element);
	public abstract String getTagName();
  
  public void toXmlTransitions(org.dom4j.Element element) {
    if ( leavingTransitions != null ) {
      Iterator iter = leavingTransitions.iterator();
			while (iter.hasNext()) {
				TransitionImpl transition = (TransitionImpl) iter.next();
        transition.toXml( element.addElement( "transition" ) );
			}
    }
  }
}

⌨️ 快捷键说明

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