001: /*
002: * Copyright (c) 1998-2008 Caucho Technology -- all rights reserved
003: *
004: * This file is part of Resin(R) Open Source
005: *
006: * Each copy or derived work must preserve the copyright notice and this
007: * notice unmodified.
008: *
009: * Resin Open Source is free software; you can redistribute it and/or modify
010: * it under the terms of the GNU General Public License as published by
011: * the Free Software Foundation; either version 2 of the License, or
012: * (at your option) any later version.
013: *
014: * Resin Open Source is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
017: * of NON-INFRINGEMENT. See the GNU General Public License for more
018: * details.
019: *
020: * You should have received a copy of the GNU General Public License
021: * along with Resin Open Source; if not, write to the
022: * Free SoftwareFoundation, Inc.
023: * 59 Temple Place, Suite 330
024: * Boston, MA 02111-1307 USA
025: *
026: * @author Scott Ferguson
027: */
028:
029: package com.caucho.xpath.pattern;
030:
031: import com.caucho.xml.XmlUtil;
032: import com.caucho.xpath.ExprEnvironment;
033:
034: import org.w3c.dom.Node;
035:
036: /**
037: * matches any node. The 'any' axis is the root of a match pattern.
038: */
039: public class FromAny extends Axis {
040: public FromAny() {
041: super (null);
042: }
043:
044: /**
045: * All nodes match
046: *
047: * @param node the current node
048: * @param env the variable environment
049: *
050: * @return true
051: */
052: public boolean match(Node node, ExprEnvironment env) {
053: return true;
054: }
055:
056: /**
057: * Returns the first node in the selection order.
058: *
059: * @param node the current node
060: *
061: * @return the first node
062: */
063: public Node firstNode(Node node, ExprEnvironment env) {
064: Node owner = node.getOwnerDocument();
065: if (owner == null)
066: return node;
067: else
068: return owner;
069: }
070:
071: /**
072: * Returns the next node in the selection order.
073: *
074: * @param node the current node
075: * @param lastNode the last node
076: *
077: * @return the next node
078: */
079: public Node nextNode(Node node, Node lastNode) {
080: return XmlUtil.getNext(node);
081: }
082:
083: /**
084: * The root is strictly ascending.
085: */
086: public boolean isStrictlyAscending() {
087: return false;
088: }
089:
090: /*
091: * Should be impossible to call position() with the any pattern.
092: *
093: * @param node the current node
094: * @param env the variable environment
095: * @param pattern the position pattern
096: */
097: public int position(Node node, ExprEnvironment env,
098: AbstractPattern pattern) {
099: throw new RuntimeException();
100: }
101:
102: /*
103: * Should be impossible to call last() with the any pattern.
104: *
105: * @param node the current node
106: * @param env the variable environment
107: * @param pattern the position pattern
108: */
109: public int count(Node node, ExprEnvironment env,
110: AbstractPattern pattern) {
111: throw new RuntimeException();
112: }
113:
114: /**
115: * Returns true if the two patterns are equal.
116: */
117: public boolean equals(Object b) {
118: return b instanceof FromAny;
119: }
120:
121: public String toString() {
122: return "node()";
123: }
124: }
|