Search in sources :

Example 1 with SerializationAnnotation

use of org.exquery.serialization.annotation.SerializationAnnotation in project exist by eXist-db.

the class RegistryFunctions method serializeAnnotations.

private static void serializeAnnotations(final MemTreeBuilder builder, final ResourceFunction resourceFn) {
    final List<Annotation> annotations = new ArrayList<>();
    annotations.addAll(resourceFn.getHttpMethodAnnotations());
    annotations.addAll(resourceFn.getConsumesAnnotations());
    annotations.addAll(resourceFn.getProducesAnnotations());
    for (final Annotation annotation : annotations) {
        builder.startElement(QName.fromJavaQName(annotation.getName()), null);
        final Literal[] literals = annotation.getLiterals();
        if (literals != null) {
            for (final Literal literal : literals) {
                if (annotation instanceof ConsumesAnnotation || annotation instanceof ProducesAnnotation) {
                    builder.startElement(INTERNET_MEDIA_TYPE, null);
                    builder.characters(literal.getValue());
                    builder.endElement();
                }
            }
        }
        builder.endElement();
    }
    // path annotation
    if (resourceFn.getPathAnnotation() != null) {
        final PathAnnotation pathAnnotation = resourceFn.getPathAnnotation();
        final AttributesImpl attrs = new AttributesImpl();
        attrs.addAttribute(null, SPECIFICITY_METRIC, "", "string", Long.toString(pathAnnotation.getPathSpecificityMetric()));
        builder.startElement(QName.fromJavaQName(pathAnnotation.getName()), attrs);
        final String[] segments = pathAnnotation.getLiterals()[0].getValue().split("/");
        for (final String segment : segments) {
            if (!segment.isEmpty()) {
                builder.startElement(SEGMENT, null);
                builder.characters(segment);
                builder.endElement();
            }
        }
        builder.endElement();
    }
    // parameter annotations
    for (final ParameterAnnotation parameterAnnotation : resourceFn.getParameterAnnotations()) {
        final Literal[] literals = parameterAnnotation.getLiterals();
        final AttributesImpl attrs = new AttributesImpl();
        attrs.addAttribute(null, NAME, "", "string", literals[0].getValue());
        attrs.addAttribute(null, ARGUMENT, "", "string", literals[1].getValue());
        if (literals.length == 3) {
            attrs.addAttribute(null, DEFAULT_VALUE, "", "string", literals[2].getValue());
        }
        builder.startElement(QName.fromJavaQName(parameterAnnotation.getName()), attrs);
        builder.endElement();
    }
    // serialization annotations
    for (final SerializationAnnotation serializationAnnotation : resourceFn.getSerializationAnnotations()) {
        serializeSerializationAnnotation(builder, serializationAnnotation);
    }
}
Also used : ArrayList(java.util.ArrayList) SerializationAnnotation(org.exquery.serialization.annotation.SerializationAnnotation) Annotation(org.exquery.xquery3.Annotation) AbstractYesNoSerializationAnnotation(org.exquery.serialization.annotation.AbstractYesNoSerializationAnnotation) MethodAnnotation(org.exquery.serialization.annotation.MethodAnnotation) SerializationAnnotation(org.exquery.serialization.annotation.SerializationAnnotation) AbstractYesNoSerializationAnnotation(org.exquery.serialization.annotation.AbstractYesNoSerializationAnnotation) AttributesImpl(org.xml.sax.helpers.AttributesImpl) Literal(org.exquery.xquery.Literal)

Aggregations

ArrayList (java.util.ArrayList)1 AbstractYesNoSerializationAnnotation (org.exquery.serialization.annotation.AbstractYesNoSerializationAnnotation)1 MethodAnnotation (org.exquery.serialization.annotation.MethodAnnotation)1 SerializationAnnotation (org.exquery.serialization.annotation.SerializationAnnotation)1 Literal (org.exquery.xquery.Literal)1 Annotation (org.exquery.xquery3.Annotation)1 AttributesImpl (org.xml.sax.helpers.AttributesImpl)1