use of org.exist.xquery.UserDefinedFunction 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;
}
Aggregations