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.ri;
  17. import java.util.Iterator;
  18. import org.apache.commons.jxpath.ri.compiler.Expression;
  19. import org.apache.commons.jxpath.CompiledExpression;
  20. import org.apache.commons.jxpath.JXPathContext;
  21. import org.apache.commons.jxpath.Pointer;
  22. /**
  23. *
  24. *
  25. * @author Dmitri Plotnikov
  26. * @version $Revision: 1.9 $ $Date: 2004/02/29 14:17:45 $
  27. */
  28. public class JXPathCompiledExpression implements CompiledExpression {
  29. private String xpath;
  30. private Expression expression;
  31. public JXPathCompiledExpression(String xpath, Expression expression) {
  32. this.xpath = xpath;
  33. this.expression = expression;
  34. }
  35. protected String getXPath() {
  36. return xpath;
  37. }
  38. protected Expression getExpression() {
  39. return expression;
  40. }
  41. public String toString() {
  42. return xpath;
  43. }
  44. /**
  45. * @see CompiledExpression#getValue(JXPathContext)
  46. */
  47. public Object getValue(JXPathContext context) {
  48. return ((JXPathContextReferenceImpl) context).
  49. getValue(xpath, expression);
  50. }
  51. /**
  52. * @see CompiledExpression#getValue(JXPathContext, Class)
  53. */
  54. public Object getValue(JXPathContext context, Class requiredType) {
  55. return ((JXPathContextReferenceImpl) context).
  56. getValue(xpath, expression, requiredType);
  57. }
  58. /**
  59. * @see CompiledExpression#setValue(JXPathContext, Object)
  60. */
  61. public void setValue(JXPathContext context, Object value) {
  62. ((JXPathContextReferenceImpl) context).
  63. setValue(xpath, expression, value);
  64. }
  65. /**
  66. * @see CompiledExpression#createPath(JXPathContext)
  67. */
  68. public Pointer createPath(JXPathContext context) {
  69. return ((JXPathContextReferenceImpl) context).
  70. createPath(xpath, expression);
  71. }
  72. /**
  73. * @see CompiledExpression#createPathAndSetValue(JXPathContext, Object)
  74. */
  75. public Pointer createPathAndSetValue(JXPathContext context, Object value) {
  76. return ((JXPathContextReferenceImpl) context).
  77. createPathAndSetValue(xpath, expression, value);
  78. }
  79. /**
  80. * @see CompiledExpression#iterate(JXPathContext)
  81. */
  82. public Iterator iterate(JXPathContext context) {
  83. return ((JXPathContextReferenceImpl) context).
  84. iterate(xpath, expression);
  85. }
  86. /**
  87. * @see CompiledExpression#getPointer(JXPathContext, String)
  88. */
  89. public Pointer getPointer(JXPathContext context, String xpath) {
  90. return ((JXPathContextReferenceImpl) context).
  91. getPointer(xpath, expression);
  92. }
  93. /**
  94. * @see CompiledExpression#iteratePointers(JXPathContext)
  95. */
  96. public Iterator iteratePointers(JXPathContext context) {
  97. return ((JXPathContextReferenceImpl) context).
  98. iteratePointers(xpath, expression);
  99. }
  100. /**
  101. * @see CompiledExpression#removePath(JXPathContext)
  102. */
  103. public void removePath(JXPathContext context) {
  104. ((JXPathContextReferenceImpl) context).removePath(xpath, expression);
  105. }
  106. /**
  107. * @see CompiledExpression#removeAll(JXPathContext)
  108. */
  109. public void removeAll(JXPathContext context) {
  110. ((JXPathContextReferenceImpl) context).removeAll(xpath, expression);
  111. }
  112. }