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

📄 elementimpl.java

📁 一个java工作流引擎
💻 JAVA
字号:
package org.jbpm.model.definition.impl;

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

public abstract class ElementImpl implements Element {

  protected Long id = null;
	protected String name = null;
	protected String description = null;
	protected List actions = null;
	protected DefinitionImpl definition = null;

	public ElementImpl() {}
  
  public ElementImpl(String name) {
		this.name = name;
  }

  public abstract EventType getDefaultEventType();
  
  public Long getId() { return this.id; }
  public void setId(Long id) { this.id = id; }

  public String getName() { return this.name; }
  public void setName(String name) { this.name = name; }
  public boolean hasName() { return (this.name != null ); }

  public String getDescription() { return description; }
  public void setDescription ( String description ) { this.description = description; }

  public Definition getDefinition() { return this.definition; }
  public void setDefinition(DefinitionImpl definition) { this.definition = definition; }

  public List getActions() { return this.actions; }
  public void setActions(List actions) { this.actions = actions; }
  public ActionImpl add(ActionImpl action) {
    if ( action != null ) {
      if ( actions == null ) actions = new ArrayList();
      if ( ! actions.contains( action ) ) {
        actions.add( action );
        action.setElement( this );
        for ( int i=0; i < actions.size(); i++ ) ((ActionImpl)actions.get(i)).setIndex(i);
      }
    }
    return action;
  }
  public void remove(ActionImpl action) {
    if ( ( action != null )
         && ( actions != null ) ) {
      if ( actions.contains( action ) ) {
        actions.remove( action );
        action.setElement( null );
        for ( int i=0; i < actions.size(); i++ ) ((ActionImpl)actions.get(i)).setIndex(i);
      }
    }
  }

  public void executeActions( EventType eventType, ExecutionContextImpl executionContext ) throws DelegationException {
    // TODO performance optimisation : replace the looping over all actions of an element with a database query.
    // Now, the query is not used to keep the model independant (even unaware!) of the persistence mechanism.
    // The way to solve this is to delegate the query to the persistence session which is inside the executionContext
    
    log.debug( "executing actions for element '" + name + "' " + eventType );
    
    TokenImpl token  = (TokenImpl) executionContext.getToken();
    
    Iterator iter = actions.iterator();
		while (iter.hasNext()) {
			ActionImpl action = (ActionImpl) iter.next();
      if ( eventType == action.getEventType() ) {
        // execute the action
        action.execute( executionContext );
      }
		}
  }
  
  public abstract String toString();
  
  protected void toXmlNameAndDescription(org.dom4j.Element element) {
    element.addAttribute( "name", name );
    if ( description != null ) element.addElement( "description" ).addText( description );
  }

  protected void toXmlActions(org.dom4j.Element element) {
    if ( actions != null ) {
      Iterator iter = actions.iterator();
      while (iter.hasNext()) {
        ActionImpl action = (ActionImpl) iter.next();
        action.toXml( element.addElement( "action" ) );
      }
    }
  }

  private static final Log log = LogFactory.getLog(ElementImpl.class);
}

⌨️ 快捷键说明

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