Search in sources :

Example 1 with JPConverter

use of net.sf.saxon.expr.JPConverter 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)

Example 2 with JPConverter

use of net.sf.saxon.expr.JPConverter in project teiid by teiid.

the class XQueryEvaluator method convertToAtomicValue.

public static AtomicValue convertToAtomicValue(Object value) throws TransformerException {
    if (value instanceof java.util.Date) {
        // special handling for time types
        java.util.Date d = (java.util.Date) value;
        DateTimeValue tdv = DateTimeValue.fromJavaDate(d);
        if (value instanceof Date) {
            value = new DateValue(tdv.getYear(), tdv.getMonth(), tdv.getDay(), tdv.getTimezoneInMinutes(), true);
        } else if (value instanceof Time) {
            value = new TimeValue(tdv.getHour(), tdv.getMinute(), tdv.getSecond(), tdv.getMicrosecond(), tdv.getTimezoneInMinutes());
        } else if (value instanceof Timestamp) {
            Timestamp ts = (Timestamp) value;
            value = tdv.add(DayTimeDurationValue.fromMicroseconds(ts.getNanos() / 1000));
        }
        return (AtomicValue) value;
    }
    JPConverter converter = JPConverter.allocate(value.getClass(), null, null);
    return (AtomicValue) converter.convert(value, null);
}
Also used : JPConverter(net.sf.saxon.expr.JPConverter) DateTimeValue(net.sf.saxon.value.DateTimeValue) DateValue(net.sf.saxon.value.DateValue) Time(java.sql.Time) AtomicValue(net.sf.saxon.value.AtomicValue) Timestamp(java.sql.Timestamp) Date(java.sql.Date) TimeValue(net.sf.saxon.value.TimeValue) DateTimeValue(net.sf.saxon.value.DateTimeValue)

Aggregations

JPConverter (net.sf.saxon.expr.JPConverter)2 Date (java.sql.Date)1 Time (java.sql.Time)1 Timestamp (java.sql.Timestamp)1 Nullable (javax.annotation.Nullable)1 XPathFunctionException (javax.xml.xpath.XPathFunctionException)1 XPathContextMajor (net.sf.saxon.expr.XPathContextMajor)1 Sequence (net.sf.saxon.om.Sequence)1 AtomicValue (net.sf.saxon.value.AtomicValue)1 DateTimeValue (net.sf.saxon.value.DateTimeValue)1 DateValue (net.sf.saxon.value.DateValue)1 TimeValue (net.sf.saxon.value.TimeValue)1