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