1. /*
  2. * Copyright 1999-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. package org.apache.commons.jxpath;
  17. import java.util.Iterator;
  18. /**
  19. * Represents a compiled XPath. The interpretation of compiled XPaths
  20. * may be faster, because it bypasses the compilation step. The reference
  21. * implementation of JXPathContext also globally caches some of the
  22. * results of compilation, so the direct use of JXPathContext is not
  23. * always less efficient than the use of CompiledExpression.
  24. * <p>
  25. * Use CompiledExpression only when there is a need to evaluate the
  26. * same expression multiple times and the CompiledExpression can be
  27. * conveniently cached.
  28. * <p>
  29. * To acqure a CompiledExpression, call {@link JXPathContext#compile
  30. * JXPathContext.compile}
  31. *
  32. * @author Dmitri Plotnikov
  33. * @version $Revision: 1.6 $ $Date: 2004/02/29 14:17:42 $
  34. */
  35. public interface CompiledExpression {
  36. /**
  37. * Evaluates the xpath and returns the resulting object. Primitive
  38. * types are wrapped into objects.
  39. */
  40. Object getValue(JXPathContext context);
  41. /**
  42. * Evaluates the xpath, converts the result to the specified class and
  43. * returns the resulting object.
  44. */
  45. Object getValue(JXPathContext context, Class requiredType);
  46. /**
  47. * Modifies the value of the property described by the supplied xpath.
  48. * Will throw an exception if one of the following conditions occurs:
  49. * <ul>
  50. * <li>The xpath does not in fact describe an existing property
  51. * <li>The property is not writable (no public, non-static set method)
  52. * </ul>
  53. */
  54. void setValue(JXPathContext context, Object value);
  55. /**
  56. * Creates intermediate elements of
  57. * the path by invoking an AbstractFactory, which should first be
  58. * installed on the context by calling "setFactory".
  59. */
  60. Pointer createPath(JXPathContext context);
  61. /**
  62. * The same as setValue, except it creates intermediate elements of
  63. * the path by invoking an AbstractFactory, which should first be
  64. * installed on the context by calling "setFactory".
  65. * <p>
  66. * Will throw an exception if one of the following conditions occurs:
  67. * <ul>
  68. * <li>Elements of the xpath aleady exist, by the path does not in
  69. * fact describe an existing property
  70. * <li>The AbstractFactory fails to create an instance for an intermediate
  71. * element.
  72. * <li>The property is not writable (no public, non-static set method)
  73. * </ul>
  74. */
  75. Pointer createPathAndSetValue(JXPathContext context, Object value);
  76. /**
  77. * Traverses the xpath and returns a Iterator of all results found
  78. * for the path. If the xpath matches no properties
  79. * in the graph, the Iterator will not be null.
  80. */
  81. Iterator iterate(JXPathContext context);
  82. /**
  83. * Traverses the xpath and returns a Pointer.
  84. * A Pointer provides easy access to a property.
  85. * If the xpath matches no properties
  86. * in the graph, the pointer will be null.
  87. */
  88. Pointer getPointer(JXPathContext context, String xpath);
  89. /**
  90. * Traverses the xpath and returns an Iterator of Pointers.
  91. * A Pointer provides easy access to a property.
  92. * If the xpath matches no properties
  93. * in the graph, the Iterator be empty, but not null.
  94. */
  95. Iterator iteratePointers(JXPathContext context);
  96. /**
  97. * Remove the graph element described by this expression
  98. */
  99. void removePath(JXPathContext context);
  100. /**
  101. * Remove all graph elements described by this expression
  102. */
  103. void removeAll(JXPathContext context);
  104. }