use of org.exist.xquery.value.SequenceType 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.SequenceType 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.SequenceType in project exist by eXist-db.
the class FunReverse method analyze.
public void analyze(final AnalyzeContextInfo contextInfo) throws XPathException {
inPredicate = (contextInfo.getFlags() & IN_PREDICATE) > 0;
contextId = contextInfo.getContextId();
contextInfo.setParent(this);
final SequenceType[] argumentTypes = getSignature().getArgumentTypes();
for (int i = 0; i < getArgumentCount(); i++) {
final Expression arg = getArgument(i);
// call analyze for each argument
final AnalyzeContextInfo argContextInfo = new AnalyzeContextInfo(contextInfo);
arg.analyze(argContextInfo);
if (i == 0) {
contextInfo.setStaticReturnType(argContextInfo.getStaticReturnType());
}
if (!argumentsChecked) {
// statically check the argument
SequenceType argType = null;
if (argumentTypes != null && i < argumentTypes.length) {
argType = argumentTypes[i];
}
checkArgument(arg, argType, argContextInfo, i + 1);
}
}
argumentsChecked = true;
}
use of org.exist.xquery.value.SequenceType 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.SequenceType in project exist by eXist-db.
the class Function method analyze.
@Override
public void analyze(final AnalyzeContextInfo contextInfo) throws XPathException {
inPredicate = (contextInfo.getFlags() & IN_PREDICATE) > 0;
unordered = (contextInfo.getFlags() & UNORDERED) > 0;
contextId = contextInfo.getContextId();
contextInfo.setParent(this);
final SequenceType[] argumentTypes = mySignature.getArgumentTypes();
for (int i = 0; i < getArgumentCount(); i++) {
final Expression arg = getArgument(i);
if (arg != null) {
// call analyze for each argument
final AnalyzeContextInfo argContextInfo = new AnalyzeContextInfo(contextInfo);
arg.analyze(argContextInfo);
if (!argumentsChecked) {
// statically check the argument
SequenceType argType = null;
if (argumentTypes != null && i < argumentTypes.length) {
argType = argumentTypes[i];
}
checkArgument(arg, argType, argContextInfo, i + 1);
}
}
}
argumentsChecked = true;
}
Aggregations