jaxp/src/java.xml/share/classes/com/sun/org/apache/xpath/internal/jaxp/XPathImpl.java
author joehw
Tue, 27 Jan 2015 22:01:46 -0800
changeset 28695 427254b89b9e
parent 25868 686eef1e7a79
child 39907 db51759e3695
permissions -rw-r--r--
8054196: XPath: support any type Reviewed-by: alanb, lancea, dfuchs
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6
7f561c08de6b Initial load
duke
parents:
diff changeset
     1
/*
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
     2
 * Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved.
6
7f561c08de6b Initial load
duke
parents:
diff changeset
     3
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
     4
/*
7f561c08de6b Initial load
duke
parents:
diff changeset
     5
 * Copyright 1999-2004 The Apache Software Foundation.
7f561c08de6b Initial load
duke
parents:
diff changeset
     6
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
     7
 * Licensed under the Apache License, Version 2.0 (the "License");
7f561c08de6b Initial load
duke
parents:
diff changeset
     8
 * you may not use this file except in compliance with the License.
7f561c08de6b Initial load
duke
parents:
diff changeset
     9
 * You may obtain a copy of the License at
7f561c08de6b Initial load
duke
parents:
diff changeset
    10
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    11
 *     http://www.apache.org/licenses/LICENSE-2.0
7f561c08de6b Initial load
duke
parents:
diff changeset
    12
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    13
 * Unless required by applicable law or agreed to in writing, software
7f561c08de6b Initial load
duke
parents:
diff changeset
    14
 * distributed under the License is distributed on an "AS IS" BASIS,
7f561c08de6b Initial load
duke
parents:
diff changeset
    15
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
7f561c08de6b Initial load
duke
parents:
diff changeset
    16
 * See the License for the specific language governing permissions and
7f561c08de6b Initial load
duke
parents:
diff changeset
    17
 * limitations under the License.
7f561c08de6b Initial load
duke
parents:
diff changeset
    18
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
    19
// $Id: XPathImpl.java,v 1.2 2005/08/16 22:41:08 jeffsuttor Exp $
7f561c08de6b Initial load
duke
parents:
diff changeset
    20
7f561c08de6b Initial load
duke
parents:
diff changeset
    21
package com.sun.org.apache.xpath.internal.jaxp;
7f561c08de6b Initial load
duke
parents:
diff changeset
    22
7f561c08de6b Initial load
duke
parents:
diff changeset
    23
import javax.xml.namespace.QName;
7f561c08de6b Initial load
duke
parents:
diff changeset
    24
import javax.xml.namespace.NamespaceContext;
7f561c08de6b Initial load
duke
parents:
diff changeset
    25
import javax.xml.xpath.XPathExpressionException;
7f561c08de6b Initial load
duke
parents:
diff changeset
    26
import javax.xml.xpath.XPathConstants;
7f561c08de6b Initial load
duke
parents:
diff changeset
    27
import javax.xml.xpath.XPathFunctionResolver;
7f561c08de6b Initial load
duke
parents:
diff changeset
    28
import javax.xml.xpath.XPathVariableResolver;
7f561c08de6b Initial load
duke
parents:
diff changeset
    29
import javax.xml.xpath.XPathExpression;
7f561c08de6b Initial load
duke
parents:
diff changeset
    30
import com.sun.org.apache.xpath.internal.*;
7f561c08de6b Initial load
duke
parents:
diff changeset
    31
import com.sun.org.apache.xpath.internal.objects.XObject;
21467
ed77f0ff062c 8004476: XSLT Extension Functions Don't Work in WebStart
joehw
parents: 12458
diff changeset
    32
import com.sun.org.apache.xalan.internal.utils.FeatureManager;
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    33
import org.w3c.dom.Document;
7f561c08de6b Initial load
duke
parents:
diff changeset
    34
import org.xml.sax.InputSource;
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
    35
import javax.xml.transform.TransformerException;
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
    36
import javax.xml.xpath.XPathEvaluationResult;
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    37
7f561c08de6b Initial load
duke
parents:
diff changeset
    38
/**
7f561c08de6b Initial load
duke
parents:
diff changeset
    39
 * The XPathImpl class provides implementation for the methods defined  in
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
    40
 * javax.xml.xpath.XPath interface. This provides simple access to the results
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    41
 * of an XPath expression.
7f561c08de6b Initial load
duke
parents:
diff changeset
    42
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    43
 * @author  Ramesh Mandava
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
    44
 *
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
    45
 * Updated 12/04/2014:
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
    46
 * New methods: evaluateExpression
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
    47
 * Refactored to share code with XPathExpressionImpl.
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    48
 */
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
    49
public class XPathImpl extends XPathImplUtil implements javax.xml.xpath.XPath {
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    50
7f561c08de6b Initial load
duke
parents:
diff changeset
    51
    // Private variables
7f561c08de6b Initial load
duke
parents:
diff changeset
    52
    private XPathVariableResolver origVariableResolver;
7f561c08de6b Initial load
duke
parents:
diff changeset
    53
    private XPathFunctionResolver origFunctionResolver;
7f561c08de6b Initial load
duke
parents:
diff changeset
    54
    private NamespaceContext namespaceContext=null;
7f561c08de6b Initial load
duke
parents:
diff changeset
    55
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
    56
    XPathImpl(XPathVariableResolver vr, XPathFunctionResolver fr) {
21467
ed77f0ff062c 8004476: XSLT Extension Functions Don't Work in WebStart
joehw
parents: 12458
diff changeset
    57
        this(vr, fr, false, true, new FeatureManager());
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    58
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
    59
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
    60
    XPathImpl(XPathVariableResolver vr, XPathFunctionResolver fr,
21467
ed77f0ff062c 8004476: XSLT Extension Functions Don't Work in WebStart
joehw
parents: 12458
diff changeset
    61
            boolean featureSecureProcessing, boolean useServiceMechanism,
ed77f0ff062c 8004476: XSLT Extension Functions Don't Work in WebStart
joehw
parents: 12458
diff changeset
    62
            FeatureManager featureManager) {
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    63
        this.origVariableResolver = this.variableResolver = vr;
7f561c08de6b Initial load
duke
parents:
diff changeset
    64
        this.origFunctionResolver = this.functionResolver = fr;
7f561c08de6b Initial load
duke
parents:
diff changeset
    65
        this.featureSecureProcessing = featureSecureProcessing;
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
    66
        this.useServiceMechanism = useServiceMechanism;
21467
ed77f0ff062c 8004476: XSLT Extension Functions Don't Work in WebStart
joehw
parents: 12458
diff changeset
    67
        this.featureManager = featureManager;
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    68
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
    69
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
    70
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
    71
    //-Override-
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    72
    public void setXPathVariableResolver(XPathVariableResolver resolver) {
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
    73
        requireNonNull(resolver, "XPathVariableResolver");
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    74
        this.variableResolver = resolver;
7f561c08de6b Initial load
duke
parents:
diff changeset
    75
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
    76
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
    77
    //-Override-
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    78
    public XPathVariableResolver getXPathVariableResolver() {
7f561c08de6b Initial load
duke
parents:
diff changeset
    79
        return variableResolver;
7f561c08de6b Initial load
duke
parents:
diff changeset
    80
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
    81
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
    82
    //-Override-
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    83
    public void setXPathFunctionResolver(XPathFunctionResolver resolver) {
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
    84
        requireNonNull(resolver, "XPathFunctionResolver");
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    85
        this.functionResolver = resolver;
7f561c08de6b Initial load
duke
parents:
diff changeset
    86
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
    87
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
    88
    //-Override-
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    89
    public XPathFunctionResolver getXPathFunctionResolver() {
7f561c08de6b Initial load
duke
parents:
diff changeset
    90
        return functionResolver;
7f561c08de6b Initial load
duke
parents:
diff changeset
    91
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
    92
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
    93
    //-Override-
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    94
    public void setNamespaceContext(NamespaceContext nsContext) {
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
    95
        requireNonNull(nsContext, "NamespaceContext");
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    96
        this.namespaceContext = nsContext;
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
    97
        this.prefixResolver = new JAXPPrefixResolver (nsContext);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    98
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
    99
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   100
    //-Override-
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   101
    public NamespaceContext getNamespaceContext() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   102
        return namespaceContext;
7f561c08de6b Initial load
duke
parents:
diff changeset
   103
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   104
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   105
    /**
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   106
     * Evaluate an {@code XPath} expression in the specified context.
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   107
     * @param expression The XPath expression.
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   108
     * @param contextItem The starting context.
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   109
     * @return an XObject as the result of evaluating the expression
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   110
     * @throws TransformerException if evaluating fails
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   111
     */
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   112
    private XObject eval(String expression, Object contextItem)
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   113
        throws TransformerException {
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   114
        requireNonNull(expression, "XPath expression");
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   115
        com.sun.org.apache.xpath.internal.XPath xpath = new com.sun.org.apache.xpath.internal.XPath(expression,
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   116
            null, prefixResolver, com.sun.org.apache.xpath.internal.XPath.SELECT);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   117
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   118
        return eval(contextItem, xpath);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   119
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   120
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   121
    //-Override-
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   122
    public Object evaluate(String expression, Object item, QName returnType)
7f561c08de6b Initial load
duke
parents:
diff changeset
   123
            throws XPathExpressionException {
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   124
        //this check is necessary before calling eval to maintain binary compatibility
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   125
        requireNonNull(expression, "XPath expression");
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   126
        isSupported(returnType);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   127
7f561c08de6b Initial load
duke
parents:
diff changeset
   128
        try {
7f561c08de6b Initial load
duke
parents:
diff changeset
   129
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   130
            XObject resultObject = eval(expression, item);
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   131
            return getResultAsType(resultObject, returnType);
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   132
        } catch (java.lang.NullPointerException npe) {
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   133
            // If VariableResolver returns null Or if we get
7f561c08de6b Initial load
duke
parents:
diff changeset
   134
            // NullPointerException at this stage for some other reason
7f561c08de6b Initial load
duke
parents:
diff changeset
   135
            // then we have to reurn XPathException
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   136
            throw new XPathExpressionException (npe);
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   137
        } catch (TransformerException te) {
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   138
            Throwable nestedException = te.getException();
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   139
            if (nestedException instanceof javax.xml.xpath.XPathFunctionException) {
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   140
                throw (javax.xml.xpath.XPathFunctionException)nestedException;
7f561c08de6b Initial load
duke
parents:
diff changeset
   141
            } else {
7f561c08de6b Initial load
duke
parents:
diff changeset
   142
                // For any other exceptions we need to throw
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   143
                // XPathExpressionException (as per spec)
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   144
                throw new XPathExpressionException (te);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   145
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   146
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   147
7f561c08de6b Initial load
duke
parents:
diff changeset
   148
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   149
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   150
    //-Override-
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   151
    public String evaluate(String expression, Object item)
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   152
        throws XPathExpressionException {
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   153
        return (String)this.evaluate(expression, item, XPathConstants.STRING);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   154
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   155
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   156
    //-Override-
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   157
    public XPathExpression compile(String expression)
7f561c08de6b Initial load
duke
parents:
diff changeset
   158
        throws XPathExpressionException {
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   159
        requireNonNull(expression, "XPath expression");
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   160
        try {
7f561c08de6b Initial load
duke
parents:
diff changeset
   161
            com.sun.org.apache.xpath.internal.XPath xpath = new XPath (expression, null,
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   162
                    prefixResolver, com.sun.org.apache.xpath.internal.XPath.SELECT);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   163
            // Can have errorListener
7f561c08de6b Initial load
duke
parents:
diff changeset
   164
            XPathExpressionImpl ximpl = new XPathExpressionImpl (xpath,
7f561c08de6b Initial load
duke
parents:
diff changeset
   165
                    prefixResolver, functionResolver, variableResolver,
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   166
                    featureSecureProcessing, useServiceMechanism, featureManager);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   167
            return ximpl;
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   168
        } catch (TransformerException te) {
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   169
            throw new XPathExpressionException (te) ;
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   170
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   171
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   172
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   173
    //-Override-
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   174
    public Object evaluate(String expression, InputSource source,
7f561c08de6b Initial load
duke
parents:
diff changeset
   175
            QName returnType) throws XPathExpressionException {
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   176
        isSupported(returnType);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   177
7f561c08de6b Initial load
duke
parents:
diff changeset
   178
        try {
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   179
            Document document = getDocument(source);
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   180
            XObject resultObject = eval(expression, document);
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   181
            return getResultAsType(resultObject, returnType);
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   182
        } catch (TransformerException te) {
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   183
            Throwable nestedException = te.getException();
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   184
            if (nestedException instanceof javax.xml.xpath.XPathFunctionException) {
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   185
                throw (javax.xml.xpath.XPathFunctionException)nestedException;
7f561c08de6b Initial load
duke
parents:
diff changeset
   186
            } else {
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   187
                throw new XPathExpressionException (te);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   188
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   189
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   190
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   191
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   192
    //-Override-
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   193
    public String evaluate(String expression, InputSource source)
7f561c08de6b Initial load
duke
parents:
diff changeset
   194
        throws XPathExpressionException {
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   195
        return (String)this.evaluate(expression, source, XPathConstants.STRING);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   196
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   197
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   198
    //-Override-
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   199
    public void reset() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   200
        this.variableResolver = this.origVariableResolver;
7f561c08de6b Initial load
duke
parents:
diff changeset
   201
        this.functionResolver = this.origFunctionResolver;
7f561c08de6b Initial load
duke
parents:
diff changeset
   202
        this.namespaceContext = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   203
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   204
28695
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   205
    //-Override-
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   206
    public <T> T evaluateExpression(String expression, Object item, Class<T> type)
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   207
            throws XPathExpressionException {
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   208
        isSupportedClassType(type);
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   209
        try {
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   210
            XObject resultObject = eval(expression, item);
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   211
            if (type.isAssignableFrom(XPathEvaluationResult.class)) {
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   212
                return getXPathResult(resultObject, type);
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   213
            } else {
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   214
                return XPathResultImpl.getValue(resultObject, type);
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   215
            }
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   216
        } catch (TransformerException te) {
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   217
            throw new XPathExpressionException (te);
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   218
        }
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   219
    }
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   220
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   221
    //-Override-
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   222
    public XPathEvaluationResult<?> evaluateExpression(String expression, Object item)
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   223
            throws XPathExpressionException {
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   224
        return evaluateExpression(expression, item, XPathEvaluationResult.class);
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   225
    }
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   226
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   227
    //-Override-
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   228
    public <T> T evaluateExpression(String expression, InputSource source, Class<T> type)
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   229
            throws XPathExpressionException {
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   230
        Document document = getDocument(source);
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   231
        return evaluateExpression(expression, document, type);
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   232
    }
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   233
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   234
    //-Override-
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   235
    public XPathEvaluationResult<?> evaluateExpression(String expression, InputSource source)
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   236
            throws XPathExpressionException {
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   237
        return evaluateExpression(expression, source, XPathEvaluationResult.class);
427254b89b9e 8054196: XPath: support any type
joehw
parents: 25868
diff changeset
   238
    }
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   239
}