org.w3c.dom.xpath.XPathEvaluator Java Examples

The following examples show how to use org.w3c.dom.xpath.XPathEvaluator. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SqlXmlUtil.java    From spliceengine with GNU Affero General Public License v3.0 4 votes vote down vote up
/**
 * Take the received string, which is an XML query expression,
 * compile it, and store the compiled query locally.  Note
 * that for now, we only support XPath because that's what
 * Xalan supports.
 *
 * @param queryExpr The XPath expression to compile
 */
public void compileXQExpr(String queryExpr, String opName)
    throws StandardException
{
    try {

        /* The following XPath constructor compiles the expression
         * as part of the construction process.  We pass a null
         * namespace resolver object so that the implementation will
         * provide one for us, which means prefixes will not be resolved
         * in the query (Xalan will just throw an error if a prefix
         * is used).  In the future we may want to revisit this
         * to make it easier for users to query based on namespaces.
         */
        XPathEvaluator eval = (XPathEvaluator)
            dBuilder.getDOMImplementation().getFeature("+XPath", "3.0");
        query = eval.createExpression(queryExpr, null);

        this.queryExpr = queryExpr;
        this.opName = opName;
        this.recompileQuery = false;

    } catch (Throwable te) {

        /* Something went wrong during compilation of the
         * expression; wrap the error and re-throw it.
         * Note: we catch "Throwable" here to catch as many
         * Xalan-produced errors as possible in order to
         * minimize the chance of an uncaught Xalan error
         * (such as a NullPointerException) causing Derby
         * to fail in a more serious way.  In particular, an
         * uncaught Java exception like NPE can result in
         * Derby throwing "ERROR 40XT0: An internal error was
         * identified by RawStore module" for all statements on
         * the connection after the failure--which we clearly
         * don't want.  If we catch the error and wrap it,
         * though, the statement will fail but Derby will
         * continue to run as normal. 
         */
        throw StandardException.newException(
            SQLState.LANG_XML_QUERY_ERROR, te, opName, te.getMessage());

    }
}