View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *     http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.apache.commons.jxpath.ri;
18  
19  import java.util.Iterator;
20  
21  import org.apache.commons.jxpath.ri.compiler.Expression;
22  import org.apache.commons.jxpath.CompiledExpression;
23  import org.apache.commons.jxpath.JXPathContext;
24  import org.apache.commons.jxpath.Pointer;
25  
26  /**
27   * RI of CompiledExpression.
28   *
29   * @author Dmitri Plotnikov
30   * @version $Revision: 652845 $ $Date: 2008-05-02 13:46:46 -0400 (Fri, 02 May 2008) $
31   */
32  public class JXPathCompiledExpression implements CompiledExpression {
33  
34      private String xpath;
35      private Expression expression;
36  
37      /**
38       * Create a new JXPathCompiledExpression.
39       * @param xpath source
40       * @param expression compiled
41       */
42      public JXPathCompiledExpression(String xpath, Expression expression) {
43          this.xpath = xpath;
44          this.expression = expression;
45      }
46  
47      /**
48       * Get the source expression.
49       * @return String
50       */
51      protected String getXPath() {
52          return xpath;
53      }
54  
55      /**
56       * Get the compiled expression.
57       * @return Expression
58       */
59      protected Expression getExpression() {
60          return expression;
61      }
62  
63      public String toString() {
64          return xpath;
65      }
66  
67      public Object getValue(JXPathContext context) {
68          return ((JXPathContextReferenceImpl) context).
69                      getValue(xpath, expression);
70      }
71  
72      public Object getValue(JXPathContext context, Class requiredType) {
73          return ((JXPathContextReferenceImpl) context).
74                      getValue(xpath, expression, requiredType);
75      }
76  
77      public void setValue(JXPathContext context, Object value) {
78          ((JXPathContextReferenceImpl) context).
79                      setValue(xpath, expression, value);
80      }
81  
82      public Pointer createPath(JXPathContext context) {
83          return ((JXPathContextReferenceImpl) context).
84                      createPath(xpath, expression);
85      }
86  
87      public Pointer createPathAndSetValue(JXPathContext context, Object value) {
88          return ((JXPathContextReferenceImpl) context).
89                      createPathAndSetValue(xpath, expression, value);
90      }
91  
92      public Iterator iterate(JXPathContext context) {
93          return ((JXPathContextReferenceImpl) context).
94                      iterate(xpath, expression);
95      }
96  
97      public Pointer getPointer(JXPathContext context, String xpath) {
98          return ((JXPathContextReferenceImpl) context).
99                      getPointer(xpath, expression);
100     }
101 
102     public Iterator iteratePointers(JXPathContext context) {
103         return ((JXPathContextReferenceImpl) context).
104                     iteratePointers(xpath, expression);
105     }
106 
107     public void removePath(JXPathContext context) {
108         ((JXPathContextReferenceImpl) context).removePath(xpath, expression);
109     }
110 
111     public void removeAll(JXPathContext context) {
112         ((JXPathContextReferenceImpl) context).removeAll(xpath, expression);
113     }
114 }