001 /* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the "License"); 007 * you may not use this file except in compliance with the License. 008 * You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018 /* 019 * $Id: XPathVisitor.java 468655 2006-10-28 07:12:06Z minchau $ 020 */ 021 package org.apache.xpath; 022 023 import org.apache.xpath.axes.LocPathIterator; 024 import org.apache.xpath.axes.UnionPathIterator; 025 import org.apache.xpath.functions.Function; 026 import org.apache.xpath.objects.XNumber; 027 import org.apache.xpath.objects.XString; 028 import org.apache.xpath.operations.Operation; 029 import org.apache.xpath.operations.UnaryOperation; 030 import org.apache.xpath.operations.Variable; 031 import org.apache.xpath.patterns.NodeTest; 032 import org.apache.xpath.patterns.StepPattern; 033 import org.apache.xpath.patterns.UnionPattern; 034 035 /** 036 * A derivation from this class can be passed to a class that implements 037 * the XPathVisitable interface, to have the appropriate method called 038 * for each component of the XPath. Aside from possible other uses, the 039 * main intention is to provide a reasonable means to perform expression 040 * rewriting. 041 * 042 * <p>Each method has the form 043 * <code>boolean visitComponentType(ExpressionOwner owner, ComponentType compType)</code>. 044 * The ExpressionOwner argument is the owner of the component, and can 045 * be used to reset the expression for rewriting. If a method returns 046 * false, the sub hierarchy will not be traversed.</p> 047 * 048 * <p>This class is meant to be a base class that will be derived by concrete classes, 049 * and doesn't much except return true for each method.</p> 050 */ 051 public class XPathVisitor 052 { 053 /** 054 * Visit a LocationPath. 055 * @param owner The owner of the expression, to which the expression can 056 * be reset if rewriting takes place. 057 * @param path The LocationPath object. 058 * @return true if the sub expressions should be traversed. 059 */ 060 public boolean visitLocationPath(ExpressionOwner owner, LocPathIterator path) 061 { 062 return true; 063 } 064 065 /** 066 * Visit a UnionPath. 067 * @param owner The owner of the expression, to which the expression can 068 * be reset if rewriting takes place. 069 * @param path The UnionPath object. 070 * @return true if the sub expressions should be traversed. 071 */ 072 public boolean visitUnionPath(ExpressionOwner owner, UnionPathIterator path) 073 { 074 return true; 075 } 076 077 /** 078 * Visit a step within a location path. 079 * @param owner The owner of the expression, to which the expression can 080 * be reset if rewriting takes place. 081 * @param step The Step object. 082 * @return true if the sub expressions should be traversed. 083 */ 084 public boolean visitStep(ExpressionOwner owner, NodeTest step) 085 { 086 return true; 087 } 088 089 /** 090 * Visit a predicate within a location path. Note that there isn't a 091 * proper unique component for predicates, and that the expression will 092 * be called also for whatever type Expression is. 093 * 094 * @param owner The owner of the expression, to which the expression can 095 * be reset if rewriting takes place. 096 * @param pred The predicate object. 097 * @return true if the sub expressions should be traversed. 098 */ 099 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 */ 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 */ 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 */ 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 */ 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 */ 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 */ 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 */ 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 */ 196 public boolean visitNumberLiteral(ExpressionOwner owner, XNumber num) 197 { 198 return true; 199 } 200 201 202 } 203