Search in sources :

Example 1 with ResourceFunction

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;
}
Also used : AnnotationAdapter(org.exist.extensions.exquery.restxq.impl.adapters.AnnotationAdapter) UserDefinedFunction(org.exist.xquery.UserDefinedFunction) ExQueryException(org.exquery.ExQueryException) ArrayList(java.util.ArrayList) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) Annotation(org.exist.xquery.Annotation) RestXqService(org.exquery.restxq.RestXqService) ResourceFunction(org.exquery.restxq.ResourceFunction) AnnotationException(org.exquery.annotation.AnnotationException) HashSet(java.util.HashSet)

Example 2 with ResourceFunction

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();
}
Also used : RestXqService(org.exquery.restxq.RestXqService) ResourceFunction(org.exquery.restxq.ResourceFunction)

Aggregations

ResourceFunction (org.exquery.restxq.ResourceFunction)2 RestXqService (org.exquery.restxq.RestXqService)2 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 AnnotationAdapter (org.exist.extensions.exquery.restxq.impl.adapters.AnnotationAdapter)1 Annotation (org.exist.xquery.Annotation)1 UserDefinedFunction (org.exist.xquery.UserDefinedFunction)1 ExQueryException (org.exquery.ExQueryException)1 AnnotationException (org.exquery.annotation.AnnotationException)1