Search in sources :

Example 1 with XPathContextMajor

use of net.sf.saxon.expr.XPathContextMajor in project ph-schematron by phax.

the class XPathFunctionFromUserFunction method evaluate.

@Nullable
public Object evaluate(final List aArgs) throws XPathFunctionException {
    try {
        // Convert the parameters
        final Sequence[] aSequences = new Sequence[aArgs.size()];
        if (aArgs.size() > 0) {
            // Create a new context per evaluation
            final XPathContextMajor aXPathContext = m_aXQController.newXPathContext();
            int nIndex = 0;
            for (final Object aArg : aArgs) {
                // Ripped from Saxon itself; genericType is not needed
                final JPConverter aConverter = JPConverter.allocate(aArg.getClass(), null, m_aConfiguration);
                // Convert to Sequence
                aSequences[nIndex] = aConverter.convert(aArg, aXPathContext);
                ++nIndex;
            }
        }
        // Finally invoke user function
        return m_aUserFunc.call(aSequences, m_aXQController);
    } catch (final Exception ex) {
        // Wrap all exceptions
        throw new XPathFunctionException(ex);
    }
}
Also used : JPConverter(net.sf.saxon.expr.JPConverter) XPathFunctionException(javax.xml.xpath.XPathFunctionException) XPathContextMajor(net.sf.saxon.expr.XPathContextMajor) Sequence(net.sf.saxon.om.Sequence) XPathFunctionException(javax.xml.xpath.XPathFunctionException) Nullable(javax.annotation.Nullable)

Aggregations

Nullable (javax.annotation.Nullable)1 XPathFunctionException (javax.xml.xpath.XPathFunctionException)1 JPConverter (net.sf.saxon.expr.JPConverter)1 XPathContextMajor (net.sf.saxon.expr.XPathContextMajor)1 Sequence (net.sf.saxon.om.Sequence)1