001: /*
002: * Copyright 2002-2004 The Apache Software Foundation.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: /*
017: * $Id: XPathVisitor.java,v 1.4 2004/02/17 04:30:02 minchau Exp $
018: */
019: package org.apache.xpath;
020:
021: import org.apache.xpath.axes.LocPathIterator;
022: import org.apache.xpath.axes.UnionPathIterator;
023: import org.apache.xpath.functions.Function;
024: import org.apache.xpath.objects.XNumber;
025: import org.apache.xpath.objects.XString;
026: import org.apache.xpath.operations.Operation;
027: import org.apache.xpath.operations.UnaryOperation;
028: import org.apache.xpath.operations.Variable;
029: import org.apache.xpath.patterns.NodeTest;
030: import org.apache.xpath.patterns.StepPattern;
031: import org.apache.xpath.patterns.UnionPattern;
032:
033: /**
034: * A derivation from this class can be passed to a class that implements
035: * the XPathVisitable interface, to have the appropriate method called
036: * for each component of the XPath. Aside from possible other uses, the
037: * main intention is to provide a reasonable means to perform expression
038: * rewriting.
039: *
040: * <p>Each method has the form
041: * <code>boolean visitComponentType(ExpressionOwner owner, ComponentType compType)</code>.
042: * The ExpressionOwner argument is the owner of the component, and can
043: * be used to reset the expression for rewriting. If a method returns
044: * false, the sub hierarchy will not be traversed.</p>
045: *
046: * <p>This class is meant to be a base class that will be derived by concrete classes,
047: * and doesn't much except return true for each method.</p>
048: */
049: public class XPathVisitor {
050: /**
051: * Visit a LocationPath.
052: * @param owner The owner of the expression, to which the expression can
053: * be reset if rewriting takes place.
054: * @param path The LocationPath object.
055: * @return true if the sub expressions should be traversed.
056: */
057: public boolean visitLocationPath(ExpressionOwner owner,
058: LocPathIterator path) {
059: return true;
060: }
061:
062: /**
063: * Visit a UnionPath.
064: * @param owner The owner of the expression, to which the expression can
065: * be reset if rewriting takes place.
066: * @param path The UnionPath object.
067: * @return true if the sub expressions should be traversed.
068: */
069: public boolean visitUnionPath(ExpressionOwner owner,
070: UnionPathIterator path) {
071: return true;
072: }
073:
074: /**
075: * Visit a step within a location path.
076: * @param owner The owner of the expression, to which the expression can
077: * be reset if rewriting takes place.
078: * @param step The Step object.
079: * @return true if the sub expressions should be traversed.
080: */
081: public boolean visitStep(ExpressionOwner owner, NodeTest step) {
082: return true;
083: }
084:
085: /**
086: * Visit a predicate within a location path. Note that there isn't a
087: * proper unique component for predicates, and that the expression will
088: * be called also for whatever type Expression is.
089: *
090: * @param owner The owner of the expression, to which the expression can
091: * be reset if rewriting takes place.
092: * @param pred The predicate object.
093: * @return true if the sub expressions should be traversed.
094: */
095: public boolean visitPredicate(ExpressionOwner owner, Expression pred) {
096: return true;
097: }
098:
099: /**
100: * Visit a binary operation.
101: * @param owner The owner of the expression, to which the expression can
102: * be reset if rewriting takes place.
103: * @param op The operation object.
104: * @return true if the sub expressions should be traversed.
105: */
106: public boolean visitBinaryOperation(ExpressionOwner owner,
107: Operation op) {
108: return true;
109: }
110:
111: /**
112: * Visit a unary operation.
113: * @param owner The owner of the expression, to which the expression can
114: * be reset if rewriting takes place.
115: * @param op The operation object.
116: * @return true if the sub expressions should be traversed.
117: */
118: public boolean visitUnaryOperation(ExpressionOwner owner,
119: UnaryOperation op) {
120: return true;
121: }
122:
123: /**
124: * Visit a variable reference.
125: * @param owner The owner of the expression, to which the expression can
126: * be reset if rewriting takes place.
127: * @param var The variable reference object.
128: * @return true if the sub expressions should be traversed.
129: */
130: public boolean visitVariableRef(ExpressionOwner owner, Variable var) {
131: return true;
132: }
133:
134: /**
135: * Visit a function.
136: * @param owner The owner of the expression, to which the expression can
137: * be reset if rewriting takes place.
138: * @param func The function reference object.
139: * @return true if the sub expressions should be traversed.
140: */
141: public boolean visitFunction(ExpressionOwner owner, Function func) {
142: return true;
143: }
144:
145: /**
146: * Visit a match pattern.
147: * @param owner The owner of the expression, to which the expression can
148: * be reset if rewriting takes place.
149: * @param pattern The match pattern object.
150: * @return true if the sub expressions should be traversed.
151: */
152: public boolean visitMatchPattern(ExpressionOwner owner,
153: StepPattern pattern) {
154: return true;
155: }
156:
157: /**
158: * Visit a union pattern.
159: * @param owner The owner of the expression, to which the expression can
160: * be reset if rewriting takes place.
161: * @param pattern The union pattern object.
162: * @return true if the sub expressions should be traversed.
163: */
164: public boolean visitUnionPattern(ExpressionOwner owner,
165: UnionPattern pattern) {
166: return true;
167: }
168:
169: /**
170: * Visit a string literal.
171: * @param owner The owner of the expression, to which the expression can
172: * be reset if rewriting takes place.
173: * @param str The string literal object.
174: * @return true if the sub expressions should be traversed.
175: */
176: public boolean visitStringLiteral(ExpressionOwner owner, XString str) {
177: return true;
178: }
179:
180: /**
181: * Visit a number literal.
182: * @param owner The owner of the expression, to which the expression can
183: * be reset if rewriting takes place.
184: * @param num The number literal object.
185: * @return true if the sub expressions should be traversed.
186: */
187: public boolean visitNumberLiteral(ExpressionOwner owner, XNumber num) {
188: return true;
189: }
190:
191: }
|