• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements. See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership. The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the  "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *     http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18 /*
19  * $Id: XPathVisitor.java 468655 2006-10-28 07:12:06Z minchau $
20  */
21 package org.apache.xpath;
22 
23 import org.apache.xpath.axes.LocPathIterator;
24 import org.apache.xpath.axes.UnionPathIterator;
25 import org.apache.xpath.functions.Function;
26 import org.apache.xpath.objects.XNumber;
27 import org.apache.xpath.objects.XString;
28 import org.apache.xpath.operations.Operation;
29 import org.apache.xpath.operations.UnaryOperation;
30 import org.apache.xpath.operations.Variable;
31 import org.apache.xpath.patterns.NodeTest;
32 import org.apache.xpath.patterns.StepPattern;
33 import org.apache.xpath.patterns.UnionPattern;
34 
35 /**
36  * A derivation from this class can be passed to a class that implements
37  * the XPathVisitable interface, to have the appropriate method called
38  * for each component of the XPath.  Aside from possible other uses, the
39  * main intention is to provide a reasonable means to perform expression
40  * rewriting.
41  *
42  * <p>Each method has the form
43  * <code>boolean visitComponentType(ExpressionOwner owner, ComponentType compType)</code>.
44  * The ExpressionOwner argument is the owner of the component, and can
45  * be used to reset the expression for rewriting.  If a method returns
46  * false, the sub hierarchy will not be traversed.</p>
47  *
48  * <p>This class is meant to be a base class that will be derived by concrete classes,
49  * and doesn't much except return true for each method.</p>
50  */
51 public class XPathVisitor
52 {
53 	/**
54 	 * Visit a LocationPath.
55 	 * @param owner The owner of the expression, to which the expression can
56 	 *              be reset if rewriting takes place.
57 	 * @param path The LocationPath object.
58 	 * @return true if the sub expressions should be traversed.
59 	 */
visitLocationPath(ExpressionOwner owner, LocPathIterator path)60 	public boolean visitLocationPath(ExpressionOwner owner, LocPathIterator path)
61 	{
62 		return true;
63 	}
64 
65 	/**
66 	 * Visit a UnionPath.
67 	 * @param owner The owner of the expression, to which the expression can
68 	 *              be reset if rewriting takes place.
69 	 * @param path The UnionPath object.
70 	 * @return true if the sub expressions should be traversed.
71 	 */
visitUnionPath(ExpressionOwner owner, UnionPathIterator path)72 	public boolean visitUnionPath(ExpressionOwner owner, UnionPathIterator path)
73 	{
74 		return true;
75 	}
76 
77 	/**
78 	 * Visit a step within a location path.
79 	 * @param owner The owner of the expression, to which the expression can
80 	 *              be reset if rewriting takes place.
81 	 * @param step The Step object.
82 	 * @return true if the sub expressions should be traversed.
83 	 */
visitStep(ExpressionOwner owner, NodeTest step)84 	public boolean visitStep(ExpressionOwner owner, NodeTest step)
85 	{
86 		return true;
87 	}
88 
89 	/**
90 	 * Visit a predicate within a location path.  Note that there isn't a
91 	 * proper unique component for predicates, and that the expression will
92 	 * be called also for whatever type Expression is.
93 	 *
94 	 * @param owner The owner of the expression, to which the expression can
95 	 *              be reset if rewriting takes place.
96 	 * @param pred The predicate object.
97 	 * @return true if the sub expressions should be traversed.
98 	 */
visitPredicate(ExpressionOwner owner, Expression pred)99 	public boolean visitPredicate(ExpressionOwner owner, Expression pred)
100 	{
101 		return true;
102 	}
103 
104 	/**
105 	 * Visit a binary operation.
106 	 * @param owner The owner of the expression, to which the expression can
107 	 *              be reset if rewriting takes place.
108 	 * @param op The operation object.
109 	 * @return true if the sub expressions should be traversed.
110 	 */
visitBinaryOperation(ExpressionOwner owner, Operation op)111 	public boolean visitBinaryOperation(ExpressionOwner owner, Operation op)
112 	{
113 		return true;
114 	}
115 
116 	/**
117 	 * Visit a unary operation.
118 	 * @param owner The owner of the expression, to which the expression can
119 	 *              be reset if rewriting takes place.
120 	 * @param op The operation object.
121 	 * @return true if the sub expressions should be traversed.
122 	 */
visitUnaryOperation(ExpressionOwner owner, UnaryOperation op)123 	public boolean visitUnaryOperation(ExpressionOwner owner, UnaryOperation op)
124 	{
125 		return true;
126 	}
127 
128 	/**
129 	 * Visit a variable reference.
130 	 * @param owner The owner of the expression, to which the expression can
131 	 *              be reset if rewriting takes place.
132 	 * @param var The variable reference object.
133 	 * @return true if the sub expressions should be traversed.
134 	 */
visitVariableRef(ExpressionOwner owner, Variable var)135 	public boolean visitVariableRef(ExpressionOwner owner, Variable var)
136 	{
137 		return true;
138 	}
139 
140 	/**
141 	 * Visit a function.
142 	 * @param owner The owner of the expression, to which the expression can
143 	 *              be reset if rewriting takes place.
144 	 * @param func The function reference object.
145 	 * @return true if the sub expressions should be traversed.
146 	 */
visitFunction(ExpressionOwner owner, Function func)147 	public boolean visitFunction(ExpressionOwner owner, Function func)
148 	{
149 		return true;
150 	}
151 
152 	/**
153 	 * Visit a match pattern.
154 	 * @param owner The owner of the expression, to which the expression can
155 	 *              be reset if rewriting takes place.
156 	 * @param pattern The match pattern object.
157 	 * @return true if the sub expressions should be traversed.
158 	 */
visitMatchPattern(ExpressionOwner owner, StepPattern pattern)159 	public boolean visitMatchPattern(ExpressionOwner owner, StepPattern pattern)
160 	{
161 		return true;
162 	}
163 
164 	/**
165 	 * Visit a union pattern.
166 	 * @param owner The owner of the expression, to which the expression can
167 	 *              be reset if rewriting takes place.
168 	 * @param pattern The union pattern object.
169 	 * @return true if the sub expressions should be traversed.
170 	 */
visitUnionPattern(ExpressionOwner owner, UnionPattern pattern)171 	public boolean visitUnionPattern(ExpressionOwner owner, UnionPattern pattern)
172 	{
173 		return true;
174 	}
175 
176 	/**
177 	 * Visit a string literal.
178 	 * @param owner The owner of the expression, to which the expression can
179 	 *              be reset if rewriting takes place.
180 	 * @param str The string literal object.
181 	 * @return true if the sub expressions should be traversed.
182 	 */
visitStringLiteral(ExpressionOwner owner, XString str)183 	public boolean visitStringLiteral(ExpressionOwner owner, XString str)
184 	{
185 		return true;
186 	}
187 
188 
189 	/**
190 	 * Visit a number literal.
191 	 * @param owner The owner of the expression, to which the expression can
192 	 *              be reset if rewriting takes place.
193 	 * @param num The number literal object.
194 	 * @return true if the sub expressions should be traversed.
195 	 */
visitNumberLiteral(ExpressionOwner owner, XNumber num)196 	public boolean visitNumberLiteral(ExpressionOwner owner, XNumber num)
197 	{
198 		return true;
199 	}
200 
201 
202 }
203 
204