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