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

📄 scopematcher.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.app;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

import org.jbpm.bpel.graph.def.Activity;
import org.jbpm.bpel.graph.def.BpelDefinition;
import org.jbpm.bpel.graph.def.CompositeActivity;
import org.jbpm.bpel.graph.scope.Scope;
import org.jbpm.graph.def.NodeCollection;

/**
 * @author Juan Cantu
 * @version $Revision: 1.3 $ $Date: 2006/09/27 03:53:01 $
 */
public class ScopeMatcher implements AppDescriptorVisitor {

  private Map scopeConfigurations;
  private Scope parent;

  /**
   * Matches a bpel definition with the given configuration
   * @param definition the bpel definition
   * @param configuration the bpel configuration to use
   * @return the resulting match map of scope definitions with their
   *         corresponding configuration
   */
  public Map match(BpelDefinition definition, AppDescriptor configuration) {
    scopeConfigurations = new HashMap();
    this.parent = definition.getGlobalScope();
    visit(configuration);
    return scopeConfigurations;
  }

  public void visit(AppDescriptor appDescriptor) {
    scopeConfigurations.put(parent, appDescriptor);
    propagate(appDescriptor);
  }

  public void visit(AppScope appScope) {
    Scope scope = findScope(appScope.getName(), parent);
    // TODO if not found throw error?
    if (scope != null) {
      scopeConfigurations.put(scope, appScope);

      Scope previousParent = parent;
      parent = scope;
      propagate(appScope);
      parent = previousParent;
    }
  }

  public void visit(AppPartnerLink appPartnerLink) {
  }

  public void propagate(AppScope config) {
    Iterator configIt = config.getScopes().iterator();

    while (configIt.hasNext()) {
      AppScope scopeConfig = (AppScope) configIt.next();
      scopeConfig.accept(this);
    }
  }

  private Scope findScope(String configName, NodeCollection parent) {
    Iterator nodesIt = parent.getNodes().iterator();

    Scope matchingScope = null;

    while (nodesIt.hasNext()) {
      Activity activity = (Activity) nodesIt.next();

      if (!(activity instanceof CompositeActivity))
        continue;

      if (activity instanceof Scope
          && (configName == null && activity.getName() == null)
          || (configName != null && configName.equals(activity.getName()))) {
        if (matchingScope != null)
          throw new RuntimeException("conflicting name");
        matchingScope = (Scope) activity;
      }

      Scope scope = findScope(configName, ((NodeCollection) activity));
      if (scope != null) {
        if (matchingScope != null)
          throw new RuntimeException("conflicting name");
        matchingScope = scope;
      }
    }

    return matchingScope;
  }
}

⌨️ 快捷键说明

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