Exemple #1
0
 public Vector<Node> getTopologicalorder() {
   Vector<Node> topOrder = new Vector<Node>();
   HashSet<Node> nodesLeft = new HashSet<Node>();
   nodesLeft.addAll(nodes);
   for (Node n : nodes) {
     if (n.parents.isEmpty()) {
       topOrder.add(n);
       nodesLeft.remove(n);
     }
   }
   // out.println("Start topological order with "
   // +StringTool.join(", ", topOrder));
   int i = 0;
   while (!nodesLeft.isEmpty() && i < 10) {
     HashSet<Node> removeNodes = new HashSet<Node>();
     // out.println(" Current order: " +StringTool.join(", ",
     // topOrder));
     for (Node n : nodesLeft) {
       // out.println("   - Check for " + n.getShortName() +
       // " with parents " + StringTool.join(", ", n.mb.parents));
       if (topOrder.containsAll(n.parents)) {
         // out.println("    -- Can be inserted!");
         topOrder.add(n);
         removeNodes.add(n);
       }
     }
     nodesLeft.removeAll(removeNodes);
     // i++;
   }
   return topOrder;
 }
  private void init() {
    actionsVector = actionsVector(actions);

    if (actions.equals("*"))
      actionsVector = actionsVector(LIFECYCLE_ACTION + "," + SCHEDULE_ACTION + "," + LOCK_ACTION);
    else if (!ACTIONS.containsAll(actionsVector))
      throw new IllegalArgumentException("Illegal action!");

    applicationID = null;
  }
  /**
   * This method returns a vector with variables/params and keys in the order in which they are to
   * be compiled for initialization. The order is determined by analyzing the dependencies between
   * them. The XSLT 1.0 spec does not allow a key to depend on a variable. However, for
   * compatibility with Xalan interpretive, that type of dependency is allowed and, therefore,
   * consider to determine the partial order.
   */
  private Vector resolveDependencies(Vector input) {
    /* DEBUG CODE - INGORE
    for (int i = 0; i < input.size(); i++) {
        final TopLevelElement e = (TopLevelElement) input.elementAt(i);
        System.out.println("e = " + e + " depends on:");
        Vector dep = e.getDependencies();
        for (int j = 0; j < (dep != null ? dep.size() : 0); j++) {
            System.out.println("\t" + dep.elementAt(j));
        }
    }
    System.out.println("=================================");
    */

    Vector result = new Vector();
    while (input.size() > 0) {
      boolean changed = false;
      for (int i = 0; i < input.size(); ) {
        final TopLevelElement vde = (TopLevelElement) input.elementAt(i);
        final Vector dep = vde.getDependencies();
        if (dep == null || result.containsAll(dep)) {
          result.addElement(vde);
          input.remove(i);
          changed = true;
        } else {
          i++;
        }
      }

      // If nothing was changed in this pass then we have a circular ref
      if (!changed) {
        ErrorMsg err = new ErrorMsg(ErrorMsg.CIRCULAR_VARIABLE_ERR, input.toString(), this);
        getParser().reportError(Constants.ERROR, err);
        return (result);
      }
    }

    /* DEBUG CODE - INGORE
    System.out.println("=================================");
    for (int i = 0; i < result.size(); i++) {
        final TopLevelElement e = (TopLevelElement) result.elementAt(i);
        System.out.println("e = " + e);
    }
    */

    return result;
  }