1. /*
  2. * The Apache Software License, Version 1.1
  3. *
  4. *
  5. * Copyright (c) 2002 The Apache Software Foundation. All rights
  6. * reserved.
  7. *
  8. * Redistribution and use in source and binary forms, with or without
  9. * modification, are permitted provided that the following conditions
  10. * are met:
  11. *
  12. * 1. Redistributions of source code must retain the above copyright
  13. * notice, this list of conditions and the following disclaimer.
  14. *
  15. * 2. Redistributions in binary form must reproduce the above copyright
  16. * notice, this list of conditions and the following disclaimer in
  17. * the documentation and/or other materials provided with the
  18. * distribution.
  19. *
  20. * 3. The end-user documentation included with the redistribution,
  21. * if any, must include the following acknowledgment:
  22. * "This product includes software developed by the
  23. * Apache Software Foundation (http://www.apache.org/)."
  24. * Alternately, this acknowledgment may appear in the software itself,
  25. * if and wherever such third-party acknowledgments normally appear.
  26. *
  27. * 4. The names "Xalan" and "Apache Software Foundation" must
  28. * not be used to endorse or promote products derived from this
  29. * software without prior written permission. For written
  30. * permission, please contact apache@apache.org.
  31. *
  32. * 5. Products derived from this software may not be called "Apache",
  33. * nor may "Apache" appear in their name, without prior written
  34. * permission of the Apache Software Foundation.
  35. *
  36. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  37. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  38. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  39. * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  40. * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  41. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  42. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  43. * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  44. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  45. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  46. * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  47. * SUCH DAMAGE.
  48. * ====================================================================
  49. *
  50. * This software consists of voluntary contributions made by many
  51. * individuals on behalf of the Apache Software Foundation and was
  52. * originally based on software copyright (c) 1999, Lotus
  53. * Development Corporation., http://www.lotus.com. For more
  54. * information on the Apache Software Foundation, please see
  55. * <http://www.apache.org/>.
  56. */
  57. package org.apache.xpath;
  58. import org.apache.xpath.patterns.NodeTest;
  59. import org.apache.xpath.axes.LocPathIterator;
  60. import org.apache.xpath.axes.UnionPathIterator;
  61. import org.apache.xpath.functions.Function;
  62. import org.apache.xpath.objects.XNumber;
  63. import org.apache.xpath.objects.XString;
  64. import org.apache.xpath.operations.Operation;
  65. import org.apache.xpath.operations.UnaryOperation;
  66. import org.apache.xpath.operations.Variable;
  67. import org.apache.xpath.patterns.StepPattern;
  68. import org.apache.xpath.patterns.UnionPattern;
  69. /**
  70. * A derivation from this class can be passed to a class that implements
  71. * the XPathVisitable interface, to have the appropriate method called
  72. * for each component of the XPath. Aside from possible other uses, the
  73. * main intention is to provide a reasonable means to perform expression
  74. * rewriting.
  75. *
  76. * <p>Each method has the form
  77. * <code>boolean visitComponentType(ExpressionOwner owner, ComponentType compType)</code>.
  78. * The ExpressionOwner argument is the owner of the component, and can
  79. * be used to reset the expression for rewriting. If a method returns
  80. * false, the sub hierarchy will not be traversed.</p>
  81. *
  82. * <p>This class is meant to be a base class that will be derived by concrete classes,
  83. * and doesn't much except return true for each method.</p>
  84. */
  85. public class XPathVisitor
  86. {
  87. /**
  88. * Visit a LocationPath.
  89. * @param owner The owner of the expression, to which the expression can
  90. * be reset if rewriting takes place.
  91. * @param path The LocationPath object.
  92. * @return true if the sub expressions should be traversed.
  93. */
  94. public boolean visitLocationPath(ExpressionOwner owner, LocPathIterator path)
  95. {
  96. return true;
  97. }
  98. /**
  99. * Visit a UnionPath.
  100. * @param owner The owner of the expression, to which the expression can
  101. * be reset if rewriting takes place.
  102. * @param path The UnionPath object.
  103. * @return true if the sub expressions should be traversed.
  104. */
  105. public boolean visitUnionPath(ExpressionOwner owner, UnionPathIterator path)
  106. {
  107. return true;
  108. }
  109. /**
  110. * Visit a step within a location path.
  111. * @param owner The owner of the expression, to which the expression can
  112. * be reset if rewriting takes place.
  113. * @param step The Step object.
  114. * @return true if the sub expressions should be traversed.
  115. */
  116. public boolean visitStep(ExpressionOwner owner, NodeTest step)
  117. {
  118. return true;
  119. }
  120. /**
  121. * Visit a predicate within a location path. Note that there isn't a
  122. * proper unique component for predicates, and that the expression will
  123. * be called also for whatever type Expression is.
  124. *
  125. * @param owner The owner of the expression, to which the expression can
  126. * be reset if rewriting takes place.
  127. * @param pred The predicate object.
  128. * @return true if the sub expressions should be traversed.
  129. */
  130. public boolean visitPredicate(ExpressionOwner owner, Expression pred)
  131. {
  132. return true;
  133. }
  134. /**
  135. * Visit a binary operation.
  136. * @param owner The owner of the expression, to which the expression can
  137. * be reset if rewriting takes place.
  138. * @param op The operation object.
  139. * @return true if the sub expressions should be traversed.
  140. */
  141. public boolean visitBinaryOperation(ExpressionOwner owner, Operation op)
  142. {
  143. return true;
  144. }
  145. /**
  146. * Visit a unary operation.
  147. * @param owner The owner of the expression, to which the expression can
  148. * be reset if rewriting takes place.
  149. * @param op The operation object.
  150. * @return true if the sub expressions should be traversed.
  151. */
  152. public boolean visitUnaryOperation(ExpressionOwner owner, UnaryOperation op)
  153. {
  154. return true;
  155. }
  156. /**
  157. * Visit a variable reference.
  158. * @param owner The owner of the expression, to which the expression can
  159. * be reset if rewriting takes place.
  160. * @param var The variable reference object.
  161. * @return true if the sub expressions should be traversed.
  162. */
  163. public boolean visitVariableRef(ExpressionOwner owner, Variable var)
  164. {
  165. return true;
  166. }
  167. /**
  168. * Visit a function.
  169. * @param owner The owner of the expression, to which the expression can
  170. * be reset if rewriting takes place.
  171. * @param func The function reference object.
  172. * @return true if the sub expressions should be traversed.
  173. */
  174. public boolean visitFunction(ExpressionOwner owner, Function func)
  175. {
  176. return true;
  177. }
  178. /**
  179. * Visit a match pattern.
  180. * @param owner The owner of the expression, to which the expression can
  181. * be reset if rewriting takes place.
  182. * @param pattern The match pattern object.
  183. * @return true if the sub expressions should be traversed.
  184. */
  185. public boolean visitMatchPattern(ExpressionOwner owner, StepPattern pattern)
  186. {
  187. return true;
  188. }
  189. /**
  190. * Visit a union pattern.
  191. * @param owner The owner of the expression, to which the expression can
  192. * be reset if rewriting takes place.
  193. * @param pattern The union pattern object.
  194. * @return true if the sub expressions should be traversed.
  195. */
  196. public boolean visitUnionPattern(ExpressionOwner owner, UnionPattern pattern)
  197. {
  198. return true;
  199. }
  200. /**
  201. * Visit a string literal.
  202. * @param owner The owner of the expression, to which the expression can
  203. * be reset if rewriting takes place.
  204. * @param str The string literal object.
  205. * @return true if the sub expressions should be traversed.
  206. */
  207. public boolean visitStringLiteral(ExpressionOwner owner, XString str)
  208. {
  209. return true;
  210. }
  211. /**
  212. * Visit a number literal.
  213. * @param owner The owner of the expression, to which the expression can
  214. * be reset if rewriting takes place.
  215. * @param num The number literal object.
  216. * @return true if the sub expressions should be traversed.
  217. */
  218. public boolean visitNumberLiteral(ExpressionOwner owner, XNumber num)
  219. {
  220. return true;
  221. }
  222. }