Exemplo n.º 1
0
  @Override
  public HibNodeToken newNodeToken(
      final GraphProcess process,
      final Node node,
      final ExecutionType executionType,
      final List<ArcToken> parents,
      final NodeToken envSource) {
    // Here we setup the token attributes for the new node
    // If the node has no predecessors, it will have no attributes
    // If it has only one processor (or only one processor with attributes)
    // it will inherit the attributes of that one node
    // Otherwise, the attributes of all predecessor nodes will get merged into
    // a single set.
    List<ArcToken> envParents = envSource == null ? parents : envSource.getParentTokens();

    HibNodeToken attrSetToken = null;
    Map<String, String> attrMap = new HashMap<String, String>();
    Map<String, Object> transientAttributes = new HashMap<String, Object>();
    boolean isMerge = false;

    for (ArcToken arcToken : envParents) {
      HibNodeToken parent = (HibNodeToken) arcToken.getParentToken();

      if (parent.getAttrSetToken() == null) {
        continue;
      }
      if (attrSetToken == null) {
        attrSetToken = parent.getAttrSetToken();
      } else if (!isMerge) {
        attrMap.putAll(attrSetToken.getAttrMap());
        isMerge = true;
      }

      if (isMerge) {
        attrMap.putAll(parent.getAttrSetToken().getAttrMap());
      }

      Env mergeEnv = parent.getEnv();
      for (String name : mergeEnv.getTransientAttributeNames()) {
        transientAttributes.put(name, mergeEnv.getTransientAttribute(name));
      }
    }

    HibNodeToken token =
        new HibNodeToken(
            (HibGraphProcess) process,
            (HibNodeRef) node,
            attrSetToken,
            executionType,
            attrMap,
            parents,
            transientAttributes);
    session.save(token);
    return token;
  }
 /**
  * @see
  *     com.googlecode.sarasvati.test.framework.TokenOnNodePredicate#matches(com.googlecode.sarasvati.NodeToken)
  */
 @Override
 public boolean matches(final NodeToken token) {
   if (super.matches(token)) {
     for (final ArcToken parent : token.getParentTokens()) {
       if (parent.getParentToken().getTokenSetMember(tokenSetName) != null) {
         return true;
       }
     }
   }
   return false;
 }
  public NodeToken backtrackDeadEnd(final NodeToken token) {
    token.markBacktracked();
    NodeTokenEvent.fireBacktrackedEvent(engine, token);

    List<ArcToken> parents = new ArrayList<ArcToken>(token.getParentTokens().size());
    for (ArcToken parent : token.getParentTokens()) {
      parent.markBacktracked();
      ArcTokenEvent.fireBacktrackedEvent(engine, parent);

      ArcToken backtrackArcToken =
          engine
              .getFactory()
              .newArcToken(token.getProcess(), parent.getArc(), ExecutionType.UTurn, token);
      ArcTokenEvent.fireCreatedEvent(engine, backtrackArcToken);
      token.getChildTokens().add(backtrackArcToken);
      parents.add(backtrackArcToken);
      shareTokenSets(backtrackArcToken, parent);
    }

    NodeToken backtrackToken =
        engine
            .getFactory()
            .newNodeToken(
                token.getProcess(), token.getNode(), ExecutionType.Forward, parents, token);
    NodeTokenEvent.fireCreatedEvent(engine, backtrackToken);
    token.getProcess().addNodeToken(backtrackToken);
    shareTokenSets(backtrackToken, token);

    for (ArcToken parent : parents) {
      parent.markProcessed();
      ArcTokenEvent.fireProcessedEvent(engine, parent);

      parent.markComplete(backtrackToken);
      ArcTokenEvent.fireCompletedEvent(engine, parent);
    }

    reactivateTokenSets();

    return backtrackToken;
  }
Exemplo n.º 4
0
 public boolean isStartTokenNode() {
   return token != null && token.getParentTokens().isEmpty() && token.getNode().isStart();
 }