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

📄 scope.java

📁 ejb3 java session bean
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * 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.scope;import java.util.ArrayList;import java.util.Collection;import java.util.Collections;import java.util.HashMap;import java.util.Iterator;import java.util.List;import java.util.Map;import javax.xml.namespace.QName;import org.apache.commons.collections.Predicate;import org.apache.commons.collections.iterators.FilterIterator;import org.apache.commons.logging.Log;import org.apache.commons.logging.LogFactory;import org.hibernate.Session;import org.jbpm.JbpmContext;import org.jbpm.bpel.graph.def.Activity;import org.jbpm.bpel.graph.def.BpelProcessDefinition;import org.jbpm.bpel.graph.def.BpelVisitor;import org.jbpm.bpel.graph.def.CompositeActivity;import org.jbpm.bpel.graph.exe.BpelFaultException;import org.jbpm.bpel.graph.exe.ScopeInstance;import org.jbpm.bpel.integration.def.CorrelationSetDefinition;import org.jbpm.bpel.integration.def.PartnerLinkDefinition;import org.jbpm.bpel.persistence.db.BpelGraphSession;import org.jbpm.bpel.variable.def.MessageType;import org.jbpm.bpel.variable.def.VariableDefinition;import org.jbpm.bpel.variable.def.VariableType;import org.jbpm.bpel.wsdl.xml.WsdlUtil;import org.jbpm.graph.def.Action;import org.jbpm.graph.def.ExceptionHandler;import org.jbpm.graph.def.GraphElement;import org.jbpm.graph.def.Node;import org.jbpm.graph.def.ProcessDefinition;import org.jbpm.graph.exe.ExecutionContext;import org.jbpm.graph.exe.Token;import org.jbpm.instantiation.Delegation;/** * Provides a context which influences the execution behavior of enclosed activities. This * behavioral context includes {@linkplain VariableDefinition variables}, * {@linkplain PartnerLinkDefinition partner links}, message exchanges, * {@linkplain CorrelationSetDefinition correlation sets}, {@linkplain Handler event handlers}, * {@linkplain Catch fault handlers}, a {@linkplain Handler compensation handler} and a * {@linkplain Handler termination handler}. * @author Juan Cantu * @version $Revision: 1.23 $ $Date: 2008/02/04 14:35:49 $ */public class Scope extends CompositeActivity {  private Activity activity;  private Map variables = new HashMap();  private Map partnerLinks = new HashMap();  private Map correlationSets = new HashMap();  private Handler compensationHandler;  private Handler terminationHandler;  private Handler catchAll;  private List faultHandlers = new ArrayList();  private List onEvents = new ArrayList();  private List onAlarms = new ArrayList();  private boolean isolated;  private boolean implicit;  public static final String VARIABLE_NAME = "s:instance";  private static final Log log = LogFactory.getLog(Scope.class);  private static final boolean traceEnabled = log.isTraceEnabled();  private static final long serialVersionUID = 1L;  public Scope() {  }  public Scope(String name) {    super(name);  }  public void execute(ExecutionContext exeContext) {    // instantiate scope    Token scopeToken = new Token(exeContext.getToken(), name);    ScopeInstance scopeInstance = createInstance(scopeToken);    // initialize data and events    scopeInstance.initializeData();    scopeInstance.enableEvents();    // execute primary token on activity    Token primaryToken = scopeInstance.getPrimaryToken();    activity.enter(new ExecutionContext(primaryToken));  }  public void terminate(ExecutionContext context) {    Token scopeToken = context.getToken().getChild(name);    ScopeInstance scopeInstance = Scope.getInstance(scopeToken);    scopeInstance.terminate();  }  public void eliminatePath(Token token) {    activity.eliminatePath(token);    super.eliminatePath(token);  }  public void accept(BpelVisitor visitor) {    visitor.visit(this);  }  // scope properties  // //////////////////////////////////////////////////////////////////////////  public void installFaultExceptionHandler() {    ExceptionHandler exceptionHandler = new ExceptionHandler();    exceptionHandler.setExceptionClassName(BpelFaultException.class.getName());    exceptionHandler.addAction(new Action(new Delegation(FaultActionHandler.class.getName())));    addExceptionHandler(exceptionHandler);  }  public Activity getActivity() {    return activity;  }  public void setActivity(Activity activity) {    if (this.activity != null)      unsetActivity();    if (activity != null) {      activity.detachFromParent();      adoptActivity(activity);      this.activity = activity;    }  }  private void unsetActivity() {    disadoptActivity(activity);    activity = null;  }  /**   * Gets the variable with the given name. Only checks variables defined in this scope.   * @param variableName the variable name   * @return the variable with the given name, or <code>null</code> if no such variable exists   */  public VariableDefinition getVariable(String variableName) {    return (VariableDefinition) variables.get(variableName);  }  /**   * Gets the variables defined in scope.   * @return map&lt;name, variable&gt;   */  public Map getVariables() {    return variables;  }  public void addVariable(VariableDefinition variable) {    variables.put(variable.getName(), variable);  }  public void setVariables(Map variables) {    this.variables = variables;  }  /**   * Gets the correlation set with the given name. Only checks correlation sets defined in this   * scope.   * @param correlationSetName the correlation set name   * @return the correlation set with the given name, or <code>null</code> if no such correlation   * set exists   */  public CorrelationSetDefinition getCorrelationSet(String correlationSetName) {    return (CorrelationSetDefinition) correlationSets.get(correlationSetName);  }  public Map getCorrelationSets() {    return correlationSets;  }  public void addCorrelationSet(CorrelationSetDefinition correlation) {    correlationSets.put(correlation.getName(), correlation);  }  public void setCorrelationSets(Map correlationSets) {    this.correlationSets = correlationSets;  }  public PartnerLinkDefinition getPartnerLink(String plinkName) {    return (PartnerLinkDefinition) partnerLinks.get(plinkName);  }  public Map getPartnerLinks() {    return partnerLinks;  }  public void addPartnerLink(PartnerLinkDefinition partnerLink) {    partnerLinks.put(partnerLink.getName(), partnerLink);  }  public void setPartnerLinks(Map partnerLinks) {    this.partnerLinks = partnerLinks;  }  public Handler getCompensationHandler() {    return compensationHandler;  }  public void setCompensationHandler(Handler handler) {    if (compensationHandler != null)      disadoptActivity(compensationHandler);    adoptActivity(handler);    compensationHandler = handler;  }  public Handler getTerminationHandler() {    return terminationHandler;  }  public void setTerminationHandler(Handler handler) {    if (terminationHandler != null)      disadoptActivity(terminationHandler);    adoptActivity(handler);    terminationHandler = handler;  }  public Handler getCatchAll() {    return catchAll;  }  public void setCatchAll(Handler handler) {    if (catchAll != null)      disadoptActivity(catchAll);    adoptActivity(handler);    catchAll = handler;  }  public List getFaultHandlers() {    return faultHandlers;  }  public void addCatch(Catch catcher) {    adoptActivity(catcher);    faultHandlers.add(catcher);  }  public Handler selectFaultHandler(QName name, VariableType dataType) {    Catch selectedCatch;    // if the fault has no data,    if (dataType == null) {      // select a handler with a matching faultName and no faultVariable      selectedCatch = selectCatch(name);    }    // if the fault has data and name,    else if (name != null) {      // select a handler with a matching faultName and a matching faultVariable      selectedCatch = selectCatch(name, dataType);      // if there is no such handler,      if (selectedCatch == null) {        // select a handler with a matching faultVariable and no faultName        selectedCatch = selectCatch(dataType);      }    }    // if the fault has no name,    else {      // select a handler with a matching faultVariable and no faultName      selectedCatch = selectCatch(dataType);    }    // otherwise, select the catchAll handler if it exists    return selectedCatch != null ? selectedCatch : catchAll;  }  /**   * Finds a handler for a fault thrown without associated data among the handlers with the given   * name.   * @param name the fault name   * @return a fault handler with the given name and no variable; <code>null</code> if no such   * handler was found   */  public Catch selectCatch(QName name) {    if (traceEnabled)      log.trace("looking for fault handler with name '" + name + "' and no variable");    Iterator namedCatchIt = new FilterIterator(faultHandlers.iterator(), new NamedCatchPredicate(        name));    while (namedCatchIt.hasNext()) {      Catch namedCatch = (Catch) namedCatchIt.next();      if (namedCatch.getFaultVariable() == null) {        if (traceEnabled)          log.trace("selected catch with matching name: " + namedCatch);        return namedCatch;

⌨️ 快捷键说明

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