Search in sources :

Example 1 with ExtensionFunctionCall

use of net.sf.saxon.lib.ExtensionFunctionCall in project camel by apache.

the class MyExtensionFunction1 method makeCallExpression.

@Override
public ExtensionFunctionCall makeCallExpression() {
    return new ExtensionFunctionCall() {

        private static final long serialVersionUID = 1L;

        @Override
        public Sequence call(XPathContext xPathContext, Sequence[] arguments) throws XPathException {
            // 1st argument (mandatory, index 0)
            Int64Value arg1 = (Int64Value) arguments[0].iterate().next();
            int arg1Int = arg1.getDecimalValue().toBigInteger().intValue();
            // 2nd argument (mandatory, index 1)
            Int64Value arg2 = (Int64Value) arguments[1].iterate().next();
            int arg2Int = arg2.getDecimalValue().toBigInteger().intValue();
            // Functionality goes here
            int resultInt = arg1Int + arg2Int;
            Item result = new Int64Value(resultInt);
            return SequenceTool.toLazySequence(SingletonIterator.makeIterator(result));
        }
    };
}
Also used : Item(net.sf.saxon.om.Item) Int64Value(net.sf.saxon.value.Int64Value) ExtensionFunctionCall(net.sf.saxon.lib.ExtensionFunctionCall) XPathContext(net.sf.saxon.expr.XPathContext)

Example 2 with ExtensionFunctionCall

use of net.sf.saxon.lib.ExtensionFunctionCall in project camel by apache.

the class MyExtensionFunction2 method makeCallExpression.

@Override
public ExtensionFunctionCall makeCallExpression() {
    return new ExtensionFunctionCall() {

        private static final long serialVersionUID = 1L;

        @Override
        public Sequence call(XPathContext xPathContext, Sequence[] arguments) throws XPathException {
            // 1st argument (mandatory, index 0)
            StringValue arg1 = (StringValue) arguments[0].iterate().next();
            String arg1Str = arg1.getStringValue();
            // 2nd argument (optional, index 1)
            String arg2Str = "";
            if (arguments.length > 1) {
                StringValue arg2 = (StringValue) arguments[1].iterate().next();
                arg2Str = arg2.getStringValue();
            }
            // Functionality goes here
            String resultStr = arg1Str + arg2Str;
            Item result = new StringValue(resultStr);
            return SequenceTool.toLazySequence(SingletonIterator.makeIterator(result));
        }
    };
}
Also used : Item(net.sf.saxon.om.Item) ExtensionFunctionCall(net.sf.saxon.lib.ExtensionFunctionCall) XPathContext(net.sf.saxon.expr.XPathContext) StringValue(net.sf.saxon.value.StringValue)

Aggregations

XPathContext (net.sf.saxon.expr.XPathContext)2 ExtensionFunctionCall (net.sf.saxon.lib.ExtensionFunctionCall)2 Item (net.sf.saxon.om.Item)2 Int64Value (net.sf.saxon.value.Int64Value)1 StringValue (net.sf.saxon.value.StringValue)1