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);
}
}
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);
}
Aggregations