Search in sources :

Example 1 with EnunciateContext

use of com.webcohesion.enunciate.EnunciateContext in project enunciate by stoicflame.

the class JaxrsModule method call.

@Override
public void call(EnunciateContext context) {
    jaxrsContext = new EnunciateJaxrsContext(context, isDisableExamples());
    DataTypeDetectionStrategy detectionStrategy = getDataTypeDetectionStrategy();
    String relativeContextPath = "";
    if (detectionStrategy != DataTypeDetectionStrategy.passive) {
        Set<? extends Element> elements = detectionStrategy == DataTypeDetectionStrategy.local ? context.getLocalApiElements() : context.getApiElements();
        for (Element declaration : elements) {
            LinkedList<Element> contextStack = new LinkedList<>();
            contextStack.push(declaration);
            try {
                if (declaration instanceof TypeElement) {
                    TypeElement element = (TypeElement) declaration;
                    if ("org.glassfish.jersey.server.wadl.internal.WadlResource".equals(element.getQualifiedName().toString())) {
                        // known internal wadl resource not to be documented.
                        continue;
                    }
                    if (isIgnored(declaration)) {
                        continue;
                    }
                    javax.ws.rs.Path pathInfo = declaration.getAnnotation(javax.ws.rs.Path.class);
                    jakarta.ws.rs.Path pathInfo2 = declaration.getAnnotation(jakarta.ws.rs.Path.class);
                    if (pathInfo != null || pathInfo2 != null) {
                        // add root resource.
                        RootResource rootResource = new RootResource(element, jaxrsContext);
                        jaxrsContext.add(rootResource);
                        for (ResourceMethod resourceMethod : rootResource.getResourceMethods(true)) {
                            addReferencedDataTypeDefinitions(resourceMethod, contextStack);
                        }
                    }
                    javax.ws.rs.ext.Provider providerInfo = declaration.getAnnotation(javax.ws.rs.ext.Provider.class);
                    jakarta.ws.rs.ext.Provider providerInfo2 = declaration.getAnnotation(jakarta.ws.rs.ext.Provider.class);
                    if (providerInfo != null || providerInfo2 != null) {
                        // add jax-rs provider
                        jaxrsContext.addJAXRSProvider(element);
                    }
                    javax.ws.rs.ApplicationPath applicationPathInfo = declaration.getAnnotation(javax.ws.rs.ApplicationPath.class);
                    jakarta.ws.rs.ApplicationPath applicationPathInfo2 = declaration.getAnnotation(jakarta.ws.rs.ApplicationPath.class);
                    if (applicationPathInfo != null || applicationPathInfo2 != null) {
                        relativeContextPath = applicationPathInfo != null ? applicationPathInfo.value() : applicationPathInfo2.value();
                    }
                }
            } catch (RuntimeException e) {
                if (e.getClass().getName().endsWith("CompletionFailure")) {
                    throw new CompletionFailureException(contextStack, e);
                }
                throw e;
            } finally {
                contextStack.pop();
            }
        }
    }
    // tidy up the application path.
    relativeContextPath = this.config.getString("application[@path]", relativeContextPath);
    relativeContextPath = sanitizeContextPath(relativeContextPath);
    jaxrsContext.setRelativeContextPath(relativeContextPath);
    jaxrsContext.setGroupingStrategy(getGroupingStrategy());
    jaxrsContext.setPathSortStrategy(getPathSortStrategy());
    if (jaxrsContext.getRootResources().size() > 0) {
        this.enunciate.addArtifact(new JaxrsRootResourceClassListArtifact(this.jaxrsContext));
    }
    if (this.jaxrsContext.getProviders().size() > 0) {
        this.enunciate.addArtifact(new JaxrsProviderClassListArtifact(this.jaxrsContext));
    }
}
Also used : Element(javax.lang.model.element.Element) TypeElement(javax.lang.model.element.TypeElement) EnunciateContext(com.webcohesion.enunciate.EnunciateContext) TypeElement(javax.lang.model.element.TypeElement) CompletionFailureException(com.webcohesion.enunciate.CompletionFailureException)

Aggregations

CompletionFailureException (com.webcohesion.enunciate.CompletionFailureException)1 EnunciateContext (com.webcohesion.enunciate.EnunciateContext)1 Element (javax.lang.model.element.Element)1 TypeElement (javax.lang.model.element.TypeElement)1