Package org.exquery.restxq

Examples of org.exquery.restxq.ResourceFunction


                        functionRestAnnotations.add(restAnnotation);
                    }
                }

                if(functionRestAnnotations != null) {
                    final ResourceFunction resourceFunction = ResourceFunctionFactory.create(new URI(compiled.getSource().getKey()), 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);
                }
            }
View Full Code Here


        builder.startDocument();
        builder.startElement(RESOURCE_FUNCTIONS, null);
       
        for(final RestXqService service : services) {
           
            final ResourceFunction resourceFn = service.getResourceFunction();
           
            AttributesImpl attrs = new AttributesImpl();
            attrs.addAttribute(null, XQUERY_URI, "", "string", resourceFn.getXQueryLocation().toString());
            builder.startElement(RESOURCE_FUNCTION, attrs);
           
            //identity
            attrs = new AttributesImpl();
            attrs.addAttribute(null, NAMESPACE, "", "string", resourceFn.getFunctionSignature().getName().getNamespaceURI());
            attrs.addAttribute(null, LOCAL_NAME, "", "string", resourceFn.getFunctionSignature().getName().getLocalPart());
            attrs.addAttribute(null, ARITY, "", "int", Integer.toString(resourceFn.getFunctionSignature().getArgumentCount()));
            builder.startElement(RESOURCE_FUNCTION_IDENTITY, attrs);
            builder.endElement();
           
            //annotations
            builder.startElement(ANNOTATIONS, null);
            final List<Annotation> annotations = new ArrayList<Annotation>();
            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();
            }
           
            if(resourceFn.getPathAnnotation() != null) {
                final PathAnnotation pathAnnotation = resourceFn.getPathAnnotation();
                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();
            }
               
            for(final ParameterAnnotation parameterAnnotation : resourceFn.getParameterAnnotations()) {
                final Literal[] literals = parameterAnnotation.getLiterals();
                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();
            }
           
            for(final SerializationAnnotation serializationAnnotation : resourceFn.getSerializationAnnotations()) {
                builder.startElement(QName.fromJavaQName(serializationAnnotation.getName()), attrs);
               
                //TODO add parameters for Serialization Annotations
               
                builder.endElement();
View Full Code Here

   
    @Test
    public void compareTo_resourceFunctions_path_before_no_path() {
       
        final PathAnnotation mockPathAnnotation = mock(PathAnnotation.class);
        final ResourceFunction mockResourceFunction = mock(ResourceFunction.class);
        final RestXqServiceMock restXqService = new RestXqServiceMock(mockResourceFunction);
       
        final ResourceFunction otherMockResourceFunction = mock(ResourceFunction.class);
        final RestXqServiceMock otherRestXqService = new RestXqServiceMock(otherMockResourceFunction);
       
        when(mockResourceFunction.getPathAnnotation()).thenReturn(mockPathAnnotation);
        when(mockPathAnnotation.getPathSpecificityMetric()).thenReturn(Long.valueOf(3));
       
        when(otherMockResourceFunction.getPathAnnotation()).thenReturn(null);
       
        final int result = restXqService.compareTo(otherRestXqService);
       
        assertEquals(-1, result);
    }
View Full Code Here

    }
   
    @Test
    public void compareTo_resourceFunctions_no_path_after_path() {
       
        final ResourceFunction mockResourceFunction = mock(ResourceFunction.class);
        final RestXqServiceMock restXqService = new RestXqServiceMock(mockResourceFunction);
       
        final PathAnnotation otherMockPathAnnotation = mock(PathAnnotation.class);
        final ResourceFunction otherMockResourceFunction = mock(ResourceFunction.class);
        final RestXqServiceMock otherRestXqService = new RestXqServiceMock(otherMockResourceFunction);
       
        when(mockResourceFunction.getPathAnnotation()).thenReturn(null);
       
        when(otherMockResourceFunction.getPathAnnotation()).thenReturn(otherMockPathAnnotation);
        when(otherMockPathAnnotation.getPathSpecificityMetric()).thenReturn(Long.valueOf(3));
       
        final int result = restXqService.compareTo(otherRestXqService);
       
        assertEquals(1, result);
View Full Code Here

   
    @Test
    public void compareTo_resourceFunctions_most_specific_path_first() {
       
        final PathAnnotation mockPathAnnotation = mock(PathAnnotation.class);
        final ResourceFunction mockResourceFunction = mock(ResourceFunction.class);
        final RestXqServiceMock restXqService = new RestXqServiceMock(mockResourceFunction);
       
        final PathAnnotation otherMockPathAnnotation = mock(PathAnnotation.class);
        final ResourceFunction otherMockResourceFunction = mock(ResourceFunction.class);
        final RestXqServiceMock otherRestXqService = new RestXqServiceMock(otherMockResourceFunction);
       
        when(mockResourceFunction.getPathAnnotation()).thenReturn(mockPathAnnotation);
        when(mockPathAnnotation.getPathSpecificityMetric()).thenReturn(Long.valueOf(3));
       
        when(otherMockResourceFunction.getPathAnnotation()).thenReturn(otherMockPathAnnotation);
        when(otherMockPathAnnotation.getPathSpecificityMetric()).thenReturn(Long.valueOf(2));
       
        final int result = restXqService.compareTo(otherRestXqService);
       
        assertEquals(-1, result);
View Full Code Here

    public void create_fails_when_there_are_no_annotations() throws URISyntaxException, ExQueryException {
        final QName qnHttpMethodAnnotation = new QName(Namespace.ANNOTATION_NS, "GET");
       
        final Set<Annotation> annotations = new HashSet<Annotation>();
       
        final ResourceFunction resourceFunction = ResourceFunctionFactory.create(new URI("/some.xquery"), annotations);
    }
View Full Code Here

        final Set<Annotation> annotations = new HashSet<Annotation>();
        annotations.add(mckPathAnnotation);
       
        when(mckPathAnnotation.getName()).thenReturn(qnPathAnnotation);
       
        final ResourceFunction resourceFunction = ResourceFunctionFactory.create(new URI("/some.xquery"), annotations);
        assertNotNull(resourceFunction);
        assertEquals(mckPathAnnotation, resourceFunction.getPathAnnotation());
    }
View Full Code Here

TOP

Related Classes of org.exquery.restxq.ResourceFunction

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.