Package com.sun.research.ws.wadl

Examples of com.sun.research.ws.wadl.Resource


        attachExternalGrammar(a, description,
                info.getRequestUri());

        for(Resources resources : a.getResources()) {
            final Resource r = resources.getResource().get(0);
            r.setPath(info.getBaseUri().relativize(info.getAbsolutePath()).toString());

            // remove path params since path is fixed at this point
            r.getParam().clear();
        }

        return a;
    }
View Full Code Here


        Application wadlApplication = _wadlGenerator.createApplication();
        Resources wadlResources = _wadlGenerator.createResources();

        // for each resource
        for (AbstractResource r : resources) {
            Resource wadlResource = generateResource(r, null);
            wadlResources.getResource().add(wadlResource);
        }
        wadlApplication.getResources().add(wadlResources);

        addVersion(wadlApplication);
View Full Code Here

    public Application generate(
            ApplicationDescription description,
            AbstractResource resource) {
        Application wadlApplication = _wadlGenerator.createApplication();
        Resources wadlResources = _wadlGenerator.createResources();
        Resource wadlResource = generateResource(resource, null);
        wadlResources.getResource().add(wadlResource);
        wadlApplication.getResources().add(wadlResources);

        addVersion(wadlApplication);
       
View Full Code Here

    public Application generate(
            ApplicationDescription description,
            AbstractResource resource, String path) {
        Application wadlApplication = _wadlGenerator.createApplication();
        Resources wadlResources = _wadlGenerator.createResources();
        Resource wadlResource = generateSubResource(resource, path);
        wadlResources.getResource().add(wadlResource);
        wadlApplication.getResources().add(wadlResources);

        addVersion(wadlApplication);
       
View Full Code Here

    private Resource generateResource(AbstractResource r, String path) {
        return generateResource(r, path, Collections.<Class<?>>emptySet());
    }

    private Resource generateResource(AbstractResource r, String path, Set<Class<?>> visitedClasses) {
        Resource wadlResource = _wadlGenerator.createResource(r, path);

        // prevent infinite recursion
        if (visitedClasses.contains(r.getResourceClass())) {
            return wadlResource;
        } else {
            visitedClasses = new HashSet<Class<?>>(visitedClasses);
            visitedClasses.add(r.getResourceClass());
        }

        Map<String, Param> wadlResourceParams = new HashMap<String, Param>();

        // add resource field/setter parameters that are associated with the resource PATH template

        List<Parameterized> fieldsOrSetters = new LinkedList<Parameterized>();

        if (r.getFields() != null) {
            fieldsOrSetters.addAll(r.getFields());
        }
        if (r.getSetterMethods() != null) {
            fieldsOrSetters.addAll(r.getSetterMethods());
        }

        for (Parameterized f : fieldsOrSetters) {
            for (Parameter fp : f.getParameters()) {
                Param wadlParam = generateParam(r, null, fp);
                if (wadlParam != null) {
                    wadlResource.getParam().add(wadlParam);
                }
            }
        }
        // for each resource method
        for (AbstractResourceMethod m : r.getResourceMethods()) {
            com.sun.research.ws.wadl.Method wadlMethod = generateMethod(r, wadlResourceParams, m);
            wadlResource.getMethodOrResource().add(wadlMethod);
        }
        // add method parameters that are associated with the resource PATH template
        for (Param wadlParam : wadlResourceParams.values()) {
            wadlResource.getParam().add(wadlParam);
        }

        // for each sub-resource method
        Map<String, Resource> wadlSubResources = new HashMap<String, Resource>();
        Map<String, Map<String, Param>> wadlSubResourcesParams =
                new HashMap<String, Map<String, Param>>();
        for (AbstractSubResourceMethod m : r.getSubResourceMethods()) {
            // find or create sub resource for uri template
            String template = m.getPath().getValue();
            Resource wadlSubResource = wadlSubResources.get(template);
            Map<String, Param> wadlSubResourceParams = wadlSubResourcesParams.get(template);
            if (wadlSubResource == null) {
                wadlSubResource = new Resource();
                wadlSubResource.setPath(template);
                wadlSubResources.put(template, wadlSubResource);
                wadlSubResourceParams = new HashMap<String, Param>();
                wadlSubResourcesParams.put(template, wadlSubResourceParams);
                wadlResource.getMethodOrResource().add(wadlSubResource);
            }
            com.sun.research.ws.wadl.Method wadlMethod = generateMethod(r, wadlSubResourceParams, m);
            wadlSubResource.getMethodOrResource().add(wadlMethod);
        }
        // add parameters that are associated with each sub-resource method PATH template
        for (Map.Entry<String, Resource> e : wadlSubResources.entrySet()) {
            String template = e.getKey();
            Resource wadlSubResource = e.getValue();
            Map<String, Param> wadlSubResourceParams = wadlSubResourcesParams.get(template);
            for (Param wadlParam : wadlSubResourceParams.values()) {
                wadlSubResource.getParam().add(wadlParam);
            }
        }

        // for each sub resource locator
        for (AbstractSubResourceLocator l : r.getSubResourceLocators()) {
            AbstractResource subResource = IntrospectionModeller.createResource(
                    l.getMethod().getReturnType());
            Resource wadlSubResource = generateResource(subResource,
                    l.getPath().getValue(), visitedClasses);
            wadlResource.getMethodOrResource().add(wadlSubResource);

            for (Parameter p : l.getParameters()) {
                Param wadlParam = generateParam(r, l, p);
                if (wadlParam != null && wadlParam.getStyle() == ParamStyle.TEMPLATE) {
                    wadlSubResource.getParam().add(wadlParam);
                }
            }
        }
        return wadlResource;
    }
View Full Code Here

        }
        return wadlResource;
    }

    private Resource generateSubResource(AbstractResource r, String path) {
        Resource wadlResource = new Resource();
        if (r.isRootResource()) {
            StringBuilder b = new StringBuilder(r.getPath().getValue());
            if (!(r.getPath().getValue().endsWith("/") || path.startsWith("/"))) {
                b.append("/");
            }
            b.append(path);
            wadlResource.setPath(b.toString());
        }
        // for each sub-resource method
        Map<String, Param> wadlSubResourceParams = new HashMap<String, Param>();
        for (AbstractSubResourceMethod m : r.getSubResourceMethods()) {
            // find or create sub resource for uri template
            String template = m.getPath().getValue();
            if (!template.equals(path)) {
                continue;
            }
            com.sun.research.ws.wadl.Method wadlMethod = generateMethod(r, wadlSubResourceParams, m);
            wadlResource.getMethodOrResource().add(wadlMethod);
        }
        // add parameters that are associated with each sub-resource method PATH template
        for (Param wadlParam : wadlSubResourceParams.values()) {
            wadlResource.getParam().add(wadlParam);
        }

        return wadlResource;
    }
View Full Code Here

        Application a = path == null ? new WadlBuilder( wadlGenerator ).generate(resource) :
            new WadlBuilder( wadlGenerator ).generate(resource, path);
       
        a.getResources().setBase(info.getBaseUri().toString());
               
        final Resource r = a.getResources().getResource().get(0);
        r.setPath(info.getBaseUri().relativize(
                info.getAbsolutePath()).toString());
       
        // remove path params since path is fixed at this point
        r.getParam().clear();
       
        return a;
    }
View Full Code Here

     * @param path
     * @return
     * @see com.sun.jersey.server.impl.wadl.WadlGenerator#createResource(com.sun.jersey.api.model.AbstractResource, java.lang.String)
     */
    public Resource createResource( AbstractResource r, String path ) {
        final Resource result = _delegate.createResource( r, path );
        final ClassDocType classDoc = _resourceDoc.getClassDoc( r.getResourceClass() );
        if ( classDoc != null && !isEmpty( classDoc.getCommentText() ) ) {
            final Doc doc = new Doc();
            doc.getContent().add( classDoc.getCommentText() );
            result.getDoc().add( doc );
        }
        return result;
    }
View Full Code Here

     * @param path
     * @return the enhanced {@link Resource}
     * @see com.sun.jersey.server.wadl.WadlGenerator#createResource(com.sun.jersey.api.model.AbstractResource, java.lang.String)
     */
    public Resource createResource( AbstractResource r, String path ) {
        final Resource result = _delegate.createResource( r, path );
        final ClassDocType classDoc = _resourceDoc.getClassDoc( r.getResourceClass() );
        if ( classDoc != null && !isEmpty( classDoc.getCommentText() ) ) {
            final Doc doc = new Doc();
            doc.getContent().add( classDoc.getCommentText() );
            result.getDoc().add( doc );
        }
        return result;
    }
View Full Code Here

        Application wadlApplication = _wadlGenerator.createApplication();
        Resources wadlResources = _wadlGenerator.createResources();

        // for each resource
        for (AbstractResource r : resources) {
            Resource wadlResource = generateResource(r, null);
            wadlResources.getResource().add(wadlResource);
        }
        wadlApplication.setResources(wadlResources);

        addVersion(wadlApplication);
View Full Code Here

TOP

Related Classes of com.sun.research.ws.wadl.Resource

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.