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

📄 processinstancestarter.java

📁 jbpm-bpel-1.1.Beta3 JBoss jBPM Starters Kit  是一个综合包
💻 JAVA
字号:
/*
 * JBoss, Home of Professional Open Source
 * Copyright 2005, JBoss Inc., and individual contributors as indicated
 * by the @authors tag.
 *
 * This is free software; you can redistribute it and/or modify it
 * under the terms of the JBPM BPEL PUBLIC LICENSE AGREEMENT as
 * published by JBoss Inc.; either version 1.0 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.
 */
package org.jbpm.bpel.graph.struct;

import java.util.Collection;
import java.util.List;

import org.jbpm.bpel.graph.basic.Assign;
import org.jbpm.bpel.graph.basic.Compensate;
import org.jbpm.bpel.graph.basic.Empty;
import org.jbpm.bpel.graph.basic.Exit;
import org.jbpm.bpel.graph.basic.Invoke;
import org.jbpm.bpel.graph.basic.Receive;
import org.jbpm.bpel.graph.basic.Reply;
import org.jbpm.bpel.graph.basic.Rethrow;
import org.jbpm.bpel.graph.basic.Throw;
import org.jbpm.bpel.graph.basic.Validate;
import org.jbpm.bpel.graph.basic.Wait;
import org.jbpm.bpel.graph.def.Activity;
import org.jbpm.bpel.graph.def.BpelDefinition;
import org.jbpm.bpel.graph.def.BpelVisitor;
import org.jbpm.bpel.graph.scope.Scope;
import org.jbpm.bpel.integration.def.Receiver;
import org.jbpm.graph.exe.ExecutionContext;
import org.jbpm.graph.exe.Token;

/**
 * @author Juan Cantu
 * @version $Revision: 1.3 $ $Date: 2006/12/29 21:38:25 $
 */
public class ProcessInstanceStarter implements BpelVisitor {

  private final ExecutionContext exeContext;
  private final Receiver trigger;

  public ProcessInstanceStarter(Token token, Receiver trigger) {
    this.exeContext = new ExecutionContext(token);
    this.trigger = trigger;
  }

  public void visit(BpelDefinition process) {
    process.getGlobalScope().getPrimaryActivity().accept(this);
  }

  public void visit(Empty empty) {
    validateNonInitial(empty);
  }

  public void visit(Receive receive) {
    if (!trigger.equals(receive.getReceiver())) {
      receive.enter(exeContext);
    }
    else if (receive.isCreateInstance()) {
      receive.leave(exeContext);
    }
    else {
      throw new RuntimeException("receive "
          + receive.getFullyQualifiedName()
          + " can't create instances");
    }
  }

  public void visit(Reply reply) {
    validateNonInitial(reply);
  }

  public void visit(Invoke invoke) {
    validateNonInitial(invoke);
  }

  public void visit(Assign assign) {
    validateNonInitial(assign);
  }

  public void visit(Throw throwActivity) {
    validateNonInitial(throwActivity);
  }

  public void visit(Exit exit) {
    validateNonInitial(exit);
  }

  public void visit(Wait wait) {
    validateNonInitial(wait);
  }

  public void visit(Sequence sequence) {
    ((Activity) sequence.getNodes().get(0)).accept(this);
  }

  public void visit(If ifActivity) {
    validateNonInitial(ifActivity);
  }

  public void visit(While whileActivity) {
    validateNonInitial(whileActivity);
  }

  public void visit(Pick pick) {
    Collection onMessages = pick.getOnMessages();

    if (!onMessages.contains(trigger)) {
      pick.getBegin().enter(exeContext);
    }
    else if (pick.isCreateInstance()) {
      pick.pickPath(exeContext, pick.getOnMessage(trigger));
    }
    else {
      throw new RuntimeException("pick "
          + pick.getFullyQualifiedName()
          + " can't create instances");
    }
  }

  public void visit(Flow flow) {
    Token token = flow.initializeLinks(exeContext.getToken());

    // phase one: spawn concurrent tokens
    List concurrentTokens = flow.createConcurrentTokens(token);

    // phase two: launch concurrent tokens over the arriving transitions of the
    // activities
    List activities = flow.getNodes();
    // stop launching concurrent tokens if the parent is prematurely ended
    for (int i = 0, n = concurrentTokens.size(); i < n && !token.hasEnded(); i++) {
      Activity activity = (Activity) activities.get(i);
      Token concurrentToken = (Token) concurrentTokens.get(i);

      ProcessInstanceStarter recursiveStarter = new ProcessInstanceStarter(
          concurrentToken, trigger);
      activity.accept(recursiveStarter);
    }
  }

  public void visit(Scope scope) {
    validateNonInitial(scope);
  }

  public void visit(Compensate compensate) {
    throw new RuntimeException("activity "
        + compensate.getFullyQualifiedName()
        + " can't be initial");
  }

  public void visit(Rethrow rethrow) {
    throw new RuntimeException("activity "
        + rethrow.getFullyQualifiedName()
        + " can't be initial");
  }

  public void visit(Validate validate) {
    validateNonInitial(validate);
  }

  private static void validateNonInitial(Activity activity) {
    if (activity.getTargets().isEmpty()) {
      throw new RuntimeException("activity "
          + activity.getFullyQualifiedName()
          + " can't be initial");
    }
  }
}

⌨️ 快捷键说明

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