use of org.exist.xquery.FunctionSignature in project exist by eXist-db.
the class InspectFunction method eval.
@Override
public Sequence eval(final Sequence[] args, final Sequence contextSequence) throws XPathException {
final FunctionReference ref = (FunctionReference) args[0].itemAt(0);
final FunctionSignature sig = ref.getSignature();
try {
context.pushDocumentContext();
final MemTreeBuilder builder = context.getDocumentBuilder();
final int nodeNr = InspectFunctionHelper.generateDocs(sig, null, builder);
return builder.getDocument().getNode(nodeNr);
} finally {
context.popDocumentContext();
}
}
use of org.exist.xquery.FunctionSignature in project exist by eXist-db.
the class AbstractExtractFunction method eval.
@Override
public Sequence eval(Sequence[] args, Sequence contextSequence) throws XPathException {
this.contextSequence = contextSequence;
if (args[0].isEmpty())
return Sequence.EMPTY_SEQUENCE;
// get the entry-filter function and check its types
if (!(args[1].itemAt(0) instanceof FunctionReference))
throw new XPathException("No entry-filter function provided.");
entryFilterFunction = (FunctionReference) args[1].itemAt(0);
FunctionSignature entryFilterFunctionSig = entryFilterFunction.getSignature();
if (entryFilterFunctionSig.getArgumentCount() < 3)
throw new XPathException("entry-filter function must take at least 3 arguments.");
filterParam = args[2];
// get the entry-data function and check its types
if (!(args[3].itemAt(0) instanceof FunctionReference))
throw new XPathException("No entry-data function provided.");
entryDataFunction = (FunctionReference) args[3].itemAt(0);
FunctionSignature entryDataFunctionSig = entryDataFunction.getSignature();
if (entryDataFunctionSig.getArgumentCount() < 3)
throw new XPathException("entry-data function must take at least 3 arguments");
storeParam = args[4];
try {
final Charset encoding;
if ((args.length >= 6) && !args[5].isEmpty()) {
encoding = Charset.forName(args[5].getStringValue());
} else {
encoding = StandardCharsets.UTF_8;
}
BinaryValue compressedData = ((BinaryValue) args[0].itemAt(0));
return processCompressedData(compressedData, encoding);
} catch (final UnsupportedCharsetException | XMLDBException e) {
throw new XPathException(this, e.getMessage(), e);
} finally {
entryDataFunction.close();
entryFilterFunction.close();
}
}
use of org.exist.xquery.FunctionSignature in project exist by eXist-db.
the class AdaptiveWriter method writeFunctionItem.
private void writeFunctionItem(final FunctionReference item) throws XPathException, SAXException {
final FunctionReference ref = item;
final FunctionSignature signature = ref.getSignature();
final QName fn = signature.getName();
final String name;
if (fn == InlineFunction.INLINE_FUNCTION_QNAME) {
name = "(anonymous-function)";
} else {
switch(fn.getNamespaceURI()) {
case Namespaces.XPATH_FUNCTIONS_NS:
name = "fn:" + fn.getLocalPart();
break;
case Namespaces.XPATH_FUNCTIONS_MATH_NS:
name = MathModule.PREFIX + ':' + fn.getLocalPart();
break;
case MapModule.NAMESPACE_URI:
name = MapModule.PREFIX + ':' + fn.getLocalPart();
break;
case ArrayModule.NAMESPACE_URI:
name = ArrayModule.PREFIX + ':' + fn.getLocalPart();
break;
case Namespaces.SCHEMA_NS:
name = "xs:" + fn.getLocalPart();
break;
default:
name = "Q{" + fn.getNamespaceURI() + '}' + fn.getLocalPart();
break;
}
}
writeText(name + '#' + signature.getArgumentCount());
}
Aggregations