Search in sources :

Example 1 with Resource

use of com.sun.research.ws.wadl.Resource in project jersey by jersey.

the class WadlBuilder method generate.

/**
     * Generate WADL for a resource.
     *
     * @param resource    the resource
     * @param description the overall application description so we can
     * @return the JAXB WADL application bean
     */
public Application generate(ApplicationDescription description, org.glassfish.jersey.server.model.Resource resource) {
    try {
        Application wadlApplication = _wadlGenerator.createApplication();
        Resources wadlResources = _wadlGenerator.createResources();
        Resource wadlResource = generateResource(resource, null);
        if (wadlResource == null) {
            return null;
        }
        wadlResources.getResource().add(wadlResource);
        wadlApplication.getResources().add(wadlResources);
        addVersion(wadlApplication);
        // Attach the data to the parts of the model
        _wadlGenerator.attachTypes(description);
        return wadlApplication;
    } catch (Exception e) {
        throw new ProcessingException(LocalizationMessages.ERROR_WADL_BUILDER_GENERATION_RESOURCE(resource), e);
    }
}
Also used : Resource(com.sun.research.ws.wadl.Resource) Resources(com.sun.research.ws.wadl.Resources) Application(com.sun.research.ws.wadl.Application) ProcessingException(javax.ws.rs.ProcessingException) ProcessingException(javax.ws.rs.ProcessingException)

Example 2 with Resource

use of com.sun.research.ws.wadl.Resource in project jersey by jersey.

the class WadlBuilder method generate.

/**
     * Generate WADL for a set of resources.
     *
     * @param resources the set of resources.
     * @return the JAXB WADL application bean.
     */
public ApplicationDescription generate(List<org.glassfish.jersey.server.model.Resource> resources) {
    Application wadlApplication = _wadlGenerator.createApplication();
    Resources wadlResources = _wadlGenerator.createResources();
    // for each resource
    for (org.glassfish.jersey.server.model.Resource r : resources) {
        Resource wadlResource = generateResource(r, r.getPath());
        if (wadlResource == null) {
            continue;
        }
        wadlResources.getResource().add(wadlResource);
    }
    wadlApplication.getResources().add(wadlResources);
    addVersion(wadlApplication);
    addHint(wadlApplication);
    // Build any external grammars
    WadlGenerator.ExternalGrammarDefinition external = _wadlGenerator.createExternalGrammar();
    //
    ApplicationDescription description = new ApplicationDescription(wadlApplication, external);
    // Attach the data to the parts of the model
    _wadlGenerator.attachTypes(description);
    return description;
}
Also used : WadlGenerator(org.glassfish.jersey.server.wadl.WadlGenerator) Resource(com.sun.research.ws.wadl.Resource) Resources(com.sun.research.ws.wadl.Resources) Application(com.sun.research.ws.wadl.Application)

Example 3 with Resource

use of com.sun.research.ws.wadl.Resource in project jersey by jersey.

the class WadlBuilder method generateResource.

private Resource generateResource(final org.glassfish.jersey.server.model.Resource resource, String path, Set<org.glassfish.jersey.server.model.Resource> visitedResources) {
    try {
        if (!detailedWadl && resource.isExtended()) {
            return null;
        }
        Resource wadlResource = _wadlGenerator.createResource(resource, path);
        // prevent infinite recursion
        if (visitedResources.contains(resource)) {
            return wadlResource;
        } else {
            visitedResources = new HashSet<>(visitedResources);
            visitedResources.add(resource);
        }
        // if the resource contains subresource locator create new resource for this locator and return it instead
        // of this resource
        final ResourceMethod locator = resource.getResourceLocator();
        if (locator != null) {
            try {
                org.glassfish.jersey.server.model.Resource.Builder builder = org.glassfish.jersey.server.model.Resource.builder(locator.getInvocable().getRawResponseType());
                if (builder == null) {
                    // for example in the case the return type of the sub resource locator is Object
                    builder = org.glassfish.jersey.server.model.Resource.builder().path(resource.getPath());
                }
                org.glassfish.jersey.server.model.Resource subResource = builder.build();
                Resource wadlSubResource = generateResource(subResource, resource.getPath(), visitedResources);
                if (wadlSubResource == null) {
                    return null;
                }
                if (locator.isExtended()) {
                    wadlSubResource.getAny().add(WadlApplicationContextImpl.EXTENDED_ELEMENT);
                }
                for (Parameter param : locator.getInvocable().getParameters()) {
                    Param wadlParam = generateParam(resource, locator, param);
                    if (wadlParam != null && wadlParam.getStyle() == ParamStyle.TEMPLATE) {
                        wadlSubResource.getParam().add(wadlParam);
                    }
                }
                return wadlSubResource;
            } catch (RuntimeException e) {
                throw new ProcessingException(LocalizationMessages.ERROR_WADL_BUILDER_GENERATION_RESOURCE_LOCATOR(locator, resource), e);
            }
        }
        Map<String, Param> wadlResourceParams = new HashMap<>();
        // for each resource method
        for (org.glassfish.jersey.server.model.ResourceMethod method : resource.getResourceMethods()) {
            if (!detailedWadl && method.isExtended()) {
                continue;
            }
            com.sun.research.ws.wadl.Method wadlMethod = generateMethod(resource, wadlResourceParams, method);
            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<>();
        Map<String, Map<String, Param>> wadlSubResourcesParams = new HashMap<>();
        for (org.glassfish.jersey.server.model.Resource childResource : resource.getChildResources()) {
            Resource childWadlResource = generateResource(childResource, childResource.getPath(), visitedResources);
            if (childWadlResource == null) {
                continue;
            }
            wadlResource.getMethodOrResource().add(childWadlResource);
        }
        return wadlResource;
    } catch (Exception e) {
        throw new ProcessingException(LocalizationMessages.ERROR_WADL_BUILDER_GENERATION_RESOURCE_PATH(resource, path), e);
    }
}
Also used : HashMap(java.util.HashMap) ResourceMethod(org.glassfish.jersey.server.model.ResourceMethod) ProcessingException(javax.ws.rs.ProcessingException) Resource(com.sun.research.ws.wadl.Resource) ProcessingException(javax.ws.rs.ProcessingException) Param(com.sun.research.ws.wadl.Param) FormParam(javax.ws.rs.FormParam) Parameter(org.glassfish.jersey.server.model.Parameter) HashMap(java.util.HashMap) Map(java.util.Map) ResourceMethod(org.glassfish.jersey.server.model.ResourceMethod)

Example 4 with Resource

use of com.sun.research.ws.wadl.Resource in project jersey by jersey.

the class WadlGeneratorResourceDocSupport method createResource.

/**
     * @param r Jersey resource component for which the WADL reource is to be created.
     * @param path path where the resource is exposed.
     * @return the enhanced {@link com.sun.research.ws.wadl.Resource}.
     * @see org.glassfish.jersey.server.wadl.WadlGenerator#createResource(org.glassfish.jersey.server.model.Resource, String)
     */
public Resource createResource(final org.glassfish.jersey.server.model.Resource r, final String path) {
    final Resource result = delegate.createResource(r, path);
    for (final Class<?> resourceClass : r.getHandlerClasses()) {
        final ClassDocType classDoc = resourceDoc.getClassDoc(resourceClass);
        if (classDoc != null && !isEmpty(classDoc.getCommentText())) {
            final Doc doc = new Doc();
            doc.getContent().add(classDoc.getCommentText());
            result.getDoc().add(doc);
        }
    }
    return result;
}
Also used : ClassDocType(org.glassfish.jersey.server.wadl.internal.generators.resourcedoc.model.ClassDocType) Resource(com.sun.research.ws.wadl.Resource) Doc(com.sun.research.ws.wadl.Doc)

Example 5 with Resource

use of com.sun.research.ws.wadl.Resource in project jersey by jersey.

the class WadlApplicationContextImpl method getApplication.

@Override
public Application getApplication(final UriInfo info, final org.glassfish.jersey.server.model.Resource resource, final boolean detailedWadl) {
    // Get the root application description
    //
    final ApplicationDescription description = getApplication(info, detailedWadl);
    final WadlGenerator wadlGenerator = wadlGeneratorConfig.createWadlGenerator(injectionManager);
    final Application application = new WadlBuilder(wadlGenerator, detailedWadl, info).generate(description, resource);
    if (application == null) {
        return null;
    }
    for (final Resources resources : application.getResources()) {
        resources.setBase(info.getBaseUri().toString());
    }
    // Attach any grammar we may have
    attachExternalGrammar(application, description, info.getRequestUri());
    for (final Resources resources : application.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 application;
}
Also used : WadlGenerator(org.glassfish.jersey.server.wadl.WadlGenerator) Resource(com.sun.research.ws.wadl.Resource) Resources(com.sun.research.ws.wadl.Resources) Application(com.sun.research.ws.wadl.Application)

Aggregations

Resource (com.sun.research.ws.wadl.Resource)5 Application (com.sun.research.ws.wadl.Application)3 Resources (com.sun.research.ws.wadl.Resources)3 ProcessingException (javax.ws.rs.ProcessingException)2 WadlGenerator (org.glassfish.jersey.server.wadl.WadlGenerator)2 Doc (com.sun.research.ws.wadl.Doc)1 Param (com.sun.research.ws.wadl.Param)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 FormParam (javax.ws.rs.FormParam)1 Parameter (org.glassfish.jersey.server.model.Parameter)1 ResourceMethod (org.glassfish.jersey.server.model.ResourceMethod)1 ClassDocType (org.glassfish.jersey.server.wadl.internal.generators.resourcedoc.model.ClassDocType)1