Example usage for javax.xml.xpath XPathFactory getClass

List of usage examples for javax.xml.xpath XPathFactory getClass

Introduction

In this page you can find the example usage for javax.xml.xpath XPathFactory getClass.

Prototype

@HotSpotIntrinsicCandidate
public final native Class<?> getClass();

Source Link

Document

Returns the runtime class of this Object .

Usage

From source file:org.apache.ode.bpel.compiler.v1.xpath10.jaxp.JaxpXPath10ExpressionCompilerImpl.java

/**
 * Verifies validity of a xpath expression.
 */// ww w  . j a v  a  2 s.c  o m
protected void doJaxpCompile(OXPath10Expression out, Expression source) throws CompilationException {
    String xpathStr;
    Node node = source.getExpression();
    if (node == null) {
        throw new IllegalStateException("XPath string and xpath node are both null");
    }

    xpathStr = node.getNodeValue();
    xpathStr = xpathStr.trim();
    if (xpathStr.length() == 0) {
        throw new CompilationException(__msgs.errXPathSyntax(xpathStr));
    }

    try {
        __log.debug("JAXP compile: xpath = " + xpathStr);
        // use default XPath implementation
        XPathFactory xpf = XPathFactory.newInstance();
        __log.debug("JAXP compile: XPathFactory impl = " + xpf.getClass());
        XPath xpath = xpf.newXPath();
        xpath.setXPathFunctionResolver(
                new JaxpFunctionResolver(_compilerContext, out, source.getNamespaceContext(), _bpelNsURI));
        xpath.setXPathVariableResolver(new JaxpVariableResolver(_compilerContext, out));
        xpath.setNamespaceContext(source.getNamespaceContext());
        XPathExpression xpe = xpath.compile(xpathStr);
        // dummy evaluation to resolve variables and functions (hopefully complete...)
        xpe.evaluate(DOMUtils.newDocument());
        out.xpath = xpathStr;
    } catch (XPathExpressionException e) {
        throw new CompilationException(__msgs.errUnexpectedCompilationError(e.getMessage()), e);
    }
}

From source file:org.apache.ode.bpel.rtrep.v1.xpath10.jaxp.JaxpXPath10ExpressionRuntime.java

private Object evaluate(OExpression cexp, EvaluationContext ctx, QName type) throws FaultException {
    try {//from   w ww. ja  v a2  s.  c om
        OXPath10Expression oxpath = (OXPath10Expression) cexp;
        __log.debug("JAXP runtime: evaluating " + oxpath.xpath);
        // use default XPath implementation
        XPathFactory xpf = XPathFactory.newInstance();
        __log.debug("JAXP runtime: XPathFactory impl = " + xpf.getClass());
        XPath xpe = xpf.newXPath();
        xpe.setXPathFunctionResolver(new JaxpFunctionResolver(ctx, oxpath));
        xpe.setXPathVariableResolver(new JaxpVariableResolver(ctx, oxpath));
        xpe.setNamespaceContext(oxpath.namespaceCtx);
        XPathExpression expr = xpe.compile(((OXPath10Expression) cexp).xpath);
        Object evalResult = expr
                .evaluate(ctx.getRootNode() == null ? DOMUtils.newDocument() : ctx.getRootNode(), type);
        if (evalResult != null && __log.isDebugEnabled()) {
            __log.debug("Expression " + cexp.toString() + " generated result " + evalResult + " - type="
                    + evalResult.getClass().getName());
            if (ctx.getRootNode() != null)
                __log.debug("Was using context node " + DOMUtils.domToString(ctx.getRootNode()));
        }
        return evalResult;
    } catch (XPathExpressionException e) {
        // Extracting the real cause from all this wrapping isn't a simple task
        Throwable cause = e.getCause() != null ? e.getCause() : e;
        throw new FaultException(cexp.getOwner().constants.qnSubLanguageExecutionFault, cause.getMessage(),
                cause);
    } catch (WrappedFaultException wre) {
        __log.debug("Could not evaluate expression because of ", wre);
        throw (FaultException) wre.getCause();
    } catch (Throwable t) {
        __log.debug("Could not evaluate expression because of ", t);
        throw new FaultException(cexp.getOwner().constants.qnSubLanguageExecutionFault, t.getMessage(), t);
    }

}