    001    /*
    002     * Licensed to the Apache Software Foundation (ASF) under one or more
    003     * contributor license agreements.  See the NOTICE file distributed with
    004     * this work for additional information regarding copyright ownership.
    005     * The ASF licenses this file to You under the Apache License, Version 2.0
    006     * (the "License"); you may not use this file except in compliance with
    007     * the License.  You may obtain a copy of the License at
    008     *
    009     *     http://www.apache.org/licenses/LICENSE-2.0
    010     *
    011     * Unless required by applicable law or agreed to in writing, software
    012     * distributed under the License is distributed on an "AS IS" BASIS,
    013     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    014     * See the License for the specific language governing permissions and
    015     * limitations under the License.
    016     */
    017    package org.apache.commons.jxpath.ri;
    018
    019    import java.util.Iterator;
    020
    021    import org.apache.commons.jxpath.ri.compiler.Expression;
    022    import org.apache.commons.jxpath.CompiledExpression;
    023    import org.apache.commons.jxpath.JXPathContext;
    024    import org.apache.commons.jxpath.Pointer;
    025
    026    /**
    027     * RI of CompiledExpression.
    028     *
    029     * @author Dmitri Plotnikov
    030     * @version $Revision: 652845 $ $Date: 2008-05-02 12:46:46 -0500 (Fri, 02 May 2008) $
    031     */
    032    public class JXPathCompiledExpression implements CompiledExpression {
    033
    034        private String xpath;
    035        private Expression expression;
    036
    037        /**
    038         * Create a new JXPathCompiledExpression.
    039         * @param xpath source
    040         * @param expression compiled
    041         */
    042        public JXPathCompiledExpression(String xpath, Expression expression) {
    043            this.xpath = xpath;
    044            this.expression = expression;
    045        }
    046
    047        /**
    048         * Get the source expression.
    049         * @return String
    050         */
    051        protected String getXPath() {
    052            return xpath;
    053        }
    054
    055        /**
    056         * Get the compiled expression.
    057         * @return Expression
    058         */
    059        protected Expression getExpression() {
    060            return expression;
    061        }
    062
    063        public String toString() {
    064            return xpath;
    065        }
    066
    067        public Object getValue(JXPathContext context) {
    068            return ((JXPathContextReferenceImpl) context).
    069                        getValue(xpath, expression);
    070        }
    071
    072        public Object getValue(JXPathContext context, Class requiredType) {
    073            return ((JXPathContextReferenceImpl) context).
    074                        getValue(xpath, expression, requiredType);
    075        }
    076
    077        public void setValue(JXPathContext context, Object value) {
    078            ((JXPathContextReferenceImpl) context).
    079                        setValue(xpath, expression, value);
    080        }
    081
    082        public Pointer createPath(JXPathContext context) {
    083            return ((JXPathContextReferenceImpl) context).
    084                        createPath(xpath, expression);
    085        }
    086
    087        public Pointer createPathAndSetValue(JXPathContext context, Object value) {
    088            return ((JXPathContextReferenceImpl) context).
    089                        createPathAndSetValue(xpath, expression, value);
    090        }
    091
    092        public Iterator iterate(JXPathContext context) {
    093            return ((JXPathContextReferenceImpl) context).
    094                        iterate(xpath, expression);
    095        }
    096
    097        public Pointer getPointer(JXPathContext context, String xpath) {
    098            return ((JXPathContextReferenceImpl) context).
    099                        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    }