Search in sources :

Example 1 with Annotation

use of org.exist.xquery.Annotation 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 Annotation

use of org.exist.xquery.Annotation in project exist by eXist-db.

the class ExtTestFinishedFunction method eval.

@Override
public Sequence eval(final Sequence contextSequence, final Item contextItem) throws XPathException {
    final Sequence arg1 = getCurrentArguments()[0];
    final String name = arg1.itemAt(0).getStringValue();
    // notify JUnit
    notifier.fireTestFinished(Description.createTestDescription(suiteName, name, new Annotation[0]));
    return Sequence.EMPTY_SEQUENCE;
}
Also used : Sequence(org.exist.xquery.value.Sequence) Annotation(org.exist.xquery.Annotation)

Example 3 with Annotation

use of org.exist.xquery.Annotation in project exist by eXist-db.

the class ExtTestIgnoredFunction method eval.

@Override
public Sequence eval(final Sequence contextSequence, final Item contextItem) throws XPathException {
    final Sequence arg1 = getCurrentArguments()[0];
    final String name = arg1.itemAt(0).getStringValue();
    // notify JUnit
    notifier.fireTestIgnored(Description.createTestDescription(suiteName, name, new Annotation[0]));
    return Sequence.EMPTY_SEQUENCE;
}
Also used : Sequence(org.exist.xquery.value.Sequence) Annotation(org.exist.xquery.Annotation)

Example 4 with Annotation

use of org.exist.xquery.Annotation in project exist by eXist-db.

the class ExtTestStartedFunction method eval.

@Override
public Sequence eval(final Sequence contextSequence, final Item contextItem) throws XPathException {
    final Sequence arg1 = getCurrentArguments()[0];
    final String name = arg1.itemAt(0).getStringValue();
    // notify JUnit
    notifier.fireTestStarted(Description.createTestDescription(suiteName, name, new Annotation[0]));
    return Sequence.EMPTY_SEQUENCE;
}
Also used : Sequence(org.exist.xquery.value.Sequence) Annotation(org.exist.xquery.Annotation)

Aggregations

Annotation (org.exist.xquery.Annotation)4 Sequence (org.exist.xquery.value.Sequence)3 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 UserDefinedFunction (org.exist.xquery.UserDefinedFunction)1 ExQueryException (org.exquery.ExQueryException)1 AnnotationException (org.exquery.annotation.AnnotationException)1 ResourceFunction (org.exquery.restxq.ResourceFunction)1 RestXqService (org.exquery.restxq.RestXqService)1