예제 #1
0
  /**
   * Returns the path nodes that are the result of this step.
   *
   * @param nodes initial path nodes
   * @param data data reference
   * @return resulting path nodes, or {@code null} if nodes cannot be evaluated
   */
  final ObjList<PathNode> nodes(final ObjList<PathNode> nodes, final Data data) {

    // skip steps with predicates or different namespaces
    if (preds.length != 0 || data.nspaces.globalNS() == null) return null;

    // check restrictions on node type
    int kind = -1, name = 0;
    if (test.type != null) {
      kind = ANode.kind(test.type);
      if (kind == Data.PI) return null;

      if (test.test == Name.NAME) {
        // element/attribute test (*:ln)
        final Names names = kind == Data.ATTR ? data.atnindex : data.tagindex;
        name = names.id(((NameTest) test).ln);
      } else if (test.test != null && test.test != Name.ALL) {
        // skip namespace and standard tests
        return null;
      }
    }

    // skip axes other than descendant, child, and attribute
    if (axis != Axis.ATTR
        && axis != Axis.CHILD
        && axis != Axis.DESC
        && axis != Axis.DESCORSELF
        && axis != Axis.SELF) return null;

    final ObjList<PathNode> tmp = new ObjList<PathNode>();
    for (final PathNode n : nodes) {
      if (axis == Axis.SELF || axis == Axis.DESCORSELF) {
        if (kind == -1 || kind == n.kind && (name == 0 || name == n.name)) {
          if (!tmp.contains(n)) tmp.add(n);
        }
      }
      if (axis != Axis.SELF) add(n, tmp, name, kind);
    }
    return tmp;
  }