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