use of org.exist.xquery.value.FunctionParameterSequenceType in project exist by eXist-db.
the class DescribeFunction method writeSignature.
/**
* @param signature
* @param builder
* @throws XPathException if an internal error occurs
*/
private void writeSignature(FunctionSignature signature, MemTreeBuilder builder) throws XPathException {
final AttributesImpl attribs = new AttributesImpl();
attribs.addAttribute("", "arguments", "arguments", "CDATA", Integer.toString(signature.getArgumentCount()));
builder.startElement("", "prototype", "prototype", attribs);
attribs.clear();
builder.startElement("", "signature", "signature", attribs);
builder.characters(signature.toString());
builder.endElement();
writeAnnotations(signature, builder);
if (signature.getDescription() != null) {
builder.startElement("", "description", "description", attribs);
final StringBuilder description = new StringBuilder();
description.append(signature.getDescription());
description.append("\n\n");
final SequenceType[] argumentTypes = signature.getArgumentTypes();
if (argumentTypes != null && argumentTypes.length > 0) {
final StringBuilder args = new StringBuilder();
int noArgs = 0;
for (final SequenceType argumentType : argumentTypes) {
if (argumentType instanceof FunctionParameterSequenceType) {
noArgs++;
final FunctionParameterSequenceType fp = (FunctionParameterSequenceType) argumentType;
args.append("$");
args.append(fp.getAttributeName());
args.append(" : ");
args.append(fp.getDescription());
args.append("\n");
}
}
// only add if there were good arguments
if (noArgs > 0) {
description.append("Parameters:\n");
description.append(args);
}
}
final SequenceType returnType = signature.getReturnType();
if (returnType != null) {
if (returnType instanceof FunctionReturnSequenceType) {
description.append("\n");
description.append("Returns ");
final FunctionReturnSequenceType fp = (FunctionReturnSequenceType) returnType;
description.append(fp.getDescription());
description.append("\n");
}
}
builder.characters(description.toString());
builder.endElement();
}
if (signature.getDeprecated() != null) {
builder.startElement("", "deprecated", "deprecated", attribs);
builder.characters(signature.getDeprecated());
builder.endElement();
}
builder.endElement();
}
use of org.exist.xquery.value.FunctionParameterSequenceType 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]);
}
use of org.exist.xquery.value.FunctionParameterSequenceType in project exist by eXist-db.
the class XQDocHelper method enhance.
protected void enhance(final FunctionSignature signature) {
signature.setDescription(description.toString().trim());
if (returnValue != null) {
final SequenceType returnType = signature.getReturnType();
final FunctionReturnSequenceType newType = new FunctionReturnSequenceType(returnType.getPrimaryType(), returnType.getCardinality(), returnValue);
signature.setReturnType(newType);
}
final SequenceType[] args = signature.getArgumentTypes();
for (final SequenceType type : args) {
if (type instanceof FunctionParameterSequenceType) {
final FunctionParameterSequenceType argType = (FunctionParameterSequenceType) type;
final String desc = parameters.get(argType.getAttributeName());
if (desc != null) {
argType.setDescription(desc);
}
}
}
for (final Map.Entry<String, String> entry : meta.entrySet()) {
String key = entry.getKey();
if (key.length() > 1 && key.charAt(0) == '@') {
key = key.substring(1);
}
signature.addMetadata(key, entry.getValue());
}
}
use of org.exist.xquery.value.FunctionParameterSequenceType in project exist by eXist-db.
the class InspectFunctionHelper method writeParameters.
private static void writeParameters(final FunctionSignature sig, final MemTreeBuilder builder) {
final SequenceType[] arguments = sig.getArgumentTypes();
if (arguments != null) {
final AttributesImpl attribs = new AttributesImpl();
for (final SequenceType type : arguments) {
attribs.clear();
attribs.addAttribute("", "type", "type", "CDATA", Type.getTypeName(type.getPrimaryType()));
attribs.addAttribute("", "cardinality", "cardinality", "CDATA", type.getCardinality().getHumanDescription());
if (type instanceof FunctionParameterSequenceType) {
attribs.addAttribute("", "var", "var", "CDATA", ((FunctionParameterSequenceType) type).getAttributeName());
}
builder.startElement(ARGUMENT_QNAME, attribs);
if (type instanceof FunctionParameterSequenceType) {
builder.characters(((FunctionParameterSequenceType) type).getDescription());
}
builder.endElement();
}
}
}
Aggregations