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

📄 scopeinstanceiterator.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.exe;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.NoSuchElementException;

import org.jbpm.bpel.graph.scope.Scope;
import org.jbpm.context.exe.ContextInstance;
import org.jbpm.graph.exe.Token;

/**
 * @author Juan Cantu
 * @version $Revision: 1.1 $ $Date: 2006/10/06 01:52:29 $
 */
public class ScopeInstanceIterator implements Iterator {

  private List tokensToTraverse = new ArrayList();
  private ScopeInstance currentScopeInstance;

  public ScopeInstanceIterator(Token parent) {
    Map children = parent.getChildren();
    if (children != null && !children.isEmpty()) {
      tokensToTraverse.addAll(children.values());
      currentScopeInstance = nextScopeInstance();
    }
  }

  public boolean hasNext() {
    return currentScopeInstance != null;
  }

  public Object next() {
    if (!hasNext())
      throw new NoSuchElementException();

    Object lastReturned = currentScopeInstance;
    currentScopeInstance = nextScopeInstance();
    return lastReturned;
  }

  public void remove() {
    throw new UnsupportedOperationException();
  }

  private ScopeInstance nextScopeInstance() {
    while (!tokensToTraverse.isEmpty()) {
      ScopeInstance scopeInstance = getScopeInstance(nextToken());
      if (scopeInstance != null)
        return scopeInstance;
    }
    return null;
  }

  private Token nextToken() {
    if (tokensToTraverse.isEmpty())
      throw new NoSuchElementException();

    Token nextToken = (Token) tokensToTraverse.remove(tokensToTraverse.size() - 1);
    // add children of the next token to the traverse collection
    Map children = nextToken.getChildren();
    // children are added if they don't have an instance themselves.
    // this causes the iterator to retrieve only instances of the immediate
    // nested level
    if (getScopeInstance(nextToken) == null && children != null)
      tokensToTraverse.addAll(children.values());

    return nextToken;
  }

  private static ScopeInstance getScopeInstance(Token token) {
    ContextInstance contextInstance = (ContextInstance) token.getProcessInstance()
        .getInstance(ContextInstance.class);
    return (ScopeInstance) contextInstance.getLocalVariable(
        Scope.VARIABLE_NAME, token);
  }
}

⌨️ 快捷键说明

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