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