Search in sources :

Example 1 with TypedArgumentValue

use of org.exquery.xquery.TypedArgumentValue in project exist by eXist-db.

the class ResourceFunctionExecutorImpl method convertToExistFunctionArguments.

/**
 * Creates converts function arguments from EXQuery to eXist-db types
 *
 * @param xqueryContext The XQuery Context of the XQuery containing the Function Call
 * @param fn The Function in the XQuery to create a Function Call for
 * @param arguments The arguments to be passed to the Function when its invoked
 *
 * @return The arguments ready to pass to the Function Call when it is invoked
 */
private org.exist.xquery.value.Sequence[] convertToExistFunctionArguments(final XQueryContext xqueryContext, final UserDefinedFunction fn, final Iterable<TypedArgumentValue> arguments) throws XPathException, RestXqServiceException {
    final List<org.exist.xquery.value.Sequence> fnArgs = new ArrayList<>();
    for (final SequenceType argumentType : fn.getSignature().getArgumentTypes()) {
        final FunctionParameterSequenceType fnParameter = (FunctionParameterSequenceType) argumentType;
        org.exist.xquery.value.Sequence fnArg = null;
        boolean found = false;
        for (final TypedArgumentValue argument : arguments) {
            final String argumentName = argument.getArgumentName();
            if (argumentName != null && argumentName.equals(fnParameter.getAttributeName())) {
                fnArg = convertToExistSequence(xqueryContext, argument, fnParameter.getPrimaryType());
                found = true;
                break;
            }
        }
        if (!found) {
            // value is not always provided, e.g. by PathAnnotation, so use empty sequence
            // TODO do we need to check the cardinality of the receiving arg to make sure it permits ZERO?
            // argumentType.getCardinality();
            // create the empty sequence
            fnArg = org.exist.xquery.value.Sequence.EMPTY_SEQUENCE;
        }
        fnArgs.add(fnArg);
    }
    return fnArgs.toArray(new org.exist.xquery.value.Sequence[0]);
}
Also used : org.exist.xquery(org.exist.xquery) ArrayList(java.util.ArrayList) ValueSequence(org.exist.xquery.value.ValueSequence) Sequence(org.exquery.xquery.Sequence) SequenceType(org.exist.xquery.value.SequenceType) FunctionParameterSequenceType(org.exist.xquery.value.FunctionParameterSequenceType) TypedArgumentValue(org.exquery.xquery.TypedArgumentValue) FunctionParameterSequenceType(org.exist.xquery.value.FunctionParameterSequenceType)

Aggregations

ArrayList (java.util.ArrayList)1 org.exist.xquery (org.exist.xquery)1 FunctionParameterSequenceType (org.exist.xquery.value.FunctionParameterSequenceType)1 SequenceType (org.exist.xquery.value.SequenceType)1 ValueSequence (org.exist.xquery.value.ValueSequence)1 Sequence (org.exquery.xquery.Sequence)1 TypedArgumentValue (org.exquery.xquery.TypedArgumentValue)1