use of org.exquery.restxq.ResourceFunction in project exist by eXist-db.
the class XQueryInspector method findServices.
public static List<RestXqService> findServices(final CompiledXQuery compiled) throws ExQueryException {
final List<RestXqService> services = new ArrayList<>();
try {
// look at each function
final Iterator<UserDefinedFunction> itFunctions = compiled.getContext().localFunctions();
final Set<URI> xqueryLocations = new HashSet<>();
while (itFunctions.hasNext()) {
final UserDefinedFunction function = itFunctions.next();
final Annotation[] annotations = function.getSignature().getAnnotations();
Set<org.exquery.xquery3.Annotation> functionRestAnnotations = null;
// process the function annotations
for (final Annotation annotation : annotations) {
if (RestAnnotationFactory.isRestXqAnnotation(annotation.getName().toJavaQName())) {
final org.exquery.xquery3.Annotation restAnnotation = RestAnnotationFactory.getAnnotation(new AnnotationAdapter(annotation));
if (functionRestAnnotations == null) {
functionRestAnnotations = new HashSet<>();
}
functionRestAnnotations.add(restAnnotation);
}
}
if (functionRestAnnotations != null) {
final ResourceFunction resourceFunction = ResourceFunctionFactory.create(new URI(compiled.getSource().path()), functionRestAnnotations);
final RestXqService service = new RestXqServiceImpl(resourceFunction, compiled.getContext().getBroker().getBrokerPool());
// record the xquerylocation
xqueryLocations.add(resourceFunction.getXQueryLocation());
// add the service to the list of services for this query
services.add(service);
}
}
for (final URI xqueryLocation : xqueryLocations) {
// add service location and compiled query to the cache
RestXqServiceCompiledXQueryCacheImpl.getInstance().returnCompiledQuery(xqueryLocation, compiled);
}
} catch (final URISyntaxException | AnnotationException use) {
throw new ExQueryException(use.getMessage(), use);
}
return services;
}
use of org.exquery.restxq.ResourceFunction in project exist by eXist-db.
the class RegistryFunctions method serializeRestXqServices.
/**
* Serializes RESTXQ Services to an XML description
*
* @param builder The receiver for the serialization
* @param services The services to describe
*
* @return The XML Document constructed from serializing the
* services to the MemTreeBuilder
*/
public static Document serializeRestXqServices(final MemTreeBuilder builder, final Iterable<RestXqService> services) {
builder.startDocument();
builder.startElement(RESOURCE_FUNCTIONS, null);
for (final RestXqService service : services) {
final ResourceFunction resourceFn = service.getResourceFunction();
serializeResourceFunction(builder, resourceFn);
}
builder.endElement();
builder.endDocument();
return builder.getDocument();
}
Aggregations