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