Search in sources :

Example 1 with WadlParamType

use of org.glassfish.jersey.server.wadl.internal.generators.resourcedoc.model.WadlParamType in project jersey by jersey.

the class WadlGeneratorResourceDocSupport method createResponses.

/**
     * @param r Jersey resource component.
     * @param m resource method.
     * @return the enhanced {@link com.sun.research.ws.wadl.Response}.
     * @see org.glassfish.jersey.server.wadl.WadlGenerator#createResponses(org.glassfish.jersey.server.model.Resource,
     * org.glassfish.jersey.server.model.ResourceMethod)
     */
public List<Response> createResponses(final org.glassfish.jersey.server.model.Resource r, final org.glassfish.jersey.server.model.ResourceMethod m) {
    final ResponseDocType responseDoc = resourceDoc.getResponse(m.getInvocable().getDefinitionMethod().getDeclaringClass(), m.getInvocable().getDefinitionMethod());
    List<Response> responses = new ArrayList<Response>();
    if (responseDoc != null && responseDoc.hasRepresentations()) {
        for (final RepresentationDocType representationDoc : responseDoc.getRepresentations()) {
            final Response response = new Response();
            final Representation wadlRepresentation = new Representation();
            wadlRepresentation.setElement(representationDoc.getElement());
            wadlRepresentation.setMediaType(representationDoc.getMediaType());
            addDocForExample(wadlRepresentation.getDoc(), representationDoc.getExample());
            addDoc(wadlRepresentation.getDoc(), representationDoc.getDoc());
            response.getStatus().add(representationDoc.getStatus());
            response.getRepresentation().add(wadlRepresentation);
            responses.add(response);
        }
        if (!responseDoc.getWadlParams().isEmpty()) {
            for (final WadlParamType wadlParamType : responseDoc.getWadlParams()) {
                final Param param = new Param();
                param.setName(wadlParamType.getName());
                param.setStyle(ParamStyle.fromValue(wadlParamType.getStyle()));
                param.setType(wadlParamType.getType());
                addDoc(param.getDoc(), wadlParamType.getDoc());
                for (final Response response : responses) {
                    response.getParam().add(param);
                }
            }
        }
        if (!isEmpty(responseDoc.getReturnDoc())) {
            for (final Response response : responses) {
                addDoc(response.getDoc(), responseDoc.getReturnDoc());
            }
        }
    } else {
        responses = delegate.createResponses(r, m);
    }
    return responses;
}
Also used : Response(com.sun.research.ws.wadl.Response) WadlParamType(org.glassfish.jersey.server.wadl.internal.generators.resourcedoc.model.WadlParamType) ResponseDocType(org.glassfish.jersey.server.wadl.internal.generators.resourcedoc.model.ResponseDocType) ArrayList(java.util.ArrayList) Param(com.sun.research.ws.wadl.Param) Representation(com.sun.research.ws.wadl.Representation) RepresentationDocType(org.glassfish.jersey.server.wadl.internal.generators.resourcedoc.model.RepresentationDocType)

Example 2 with WadlParamType

use of org.glassfish.jersey.server.wadl.internal.generators.resourcedoc.model.WadlParamType in project jersey by jersey.

the class ResourceDoclet method addResponseDoc.

private static void addResponseDoc(final MethodDoc methodDoc, final MethodDocType methodDocType) {
    final ResponseDocType responseDoc = new ResponseDocType();
    final Tag returnTag = getSingleTagOrNull(methodDoc, "return");
    if (returnTag != null) {
        responseDoc.setReturnDoc(returnTag.text());
    }
    final Tag[] responseParamTags = methodDoc.tags("response.param");
    for (final Tag responseParamTag : responseParamTags) {
        // LOG.info( "Have responseparam tag: " + print( responseParamTag ) );
        final WadlParamType wadlParam = new WadlParamType();
        for (final Tag inlineTag : responseParamTag.inlineTags()) {
            final String tagName = inlineTag.name();
            final String tagText = inlineTag.text();
            /* skip empty tags
                 */
            if (isEmpty(tagText)) {
                if (LOG.isLoggable(Level.FINE)) {
                    LOG.fine("Skipping empty inline tag of @response.param in method " + methodDoc.qualifiedName() + ": " + tagName);
                }
                continue;
            }
            switch(tagName) {
                case "@name":
                    wadlParam.setName(tagText);
                    break;
                case "@style":
                    wadlParam.setStyle(tagText);
                    break;
                case "@type":
                    wadlParam.setType(QName.valueOf(tagText));
                    break;
                case "@doc":
                    wadlParam.setDoc(tagText);
                    break;
                default:
                    LOG.warning("Unknown inline tag of @response.param in method " + methodDoc.qualifiedName() + ": " + tagName + " (value: " + tagText + ")");
                    break;
            }
        }
        responseDoc.getWadlParams().add(wadlParam);
    }
    final Map<String, List<Tag>> tagsByStatus = getResponseRepresentationTags(methodDoc);
    for (final Entry<String, List<Tag>> entry : tagsByStatus.entrySet()) {
        final RepresentationDocType representationDoc = new RepresentationDocType();
        representationDoc.setStatus(Long.valueOf(entry.getKey()));
        for (final Tag tag : entry.getValue()) {
            if (tag.name().endsWith(".qname")) {
                representationDoc.setElement(QName.valueOf(tag.text()));
            } else if (tag.name().endsWith(".mediaType")) {
                representationDoc.setMediaType(tag.text());
            } else if (tag.name().endsWith(".example")) {
                representationDoc.setExample(getSerializedExample(tag));
            } else if (tag.name().endsWith(".doc")) {
                representationDoc.setDoc(tag.text());
            } else {
                LOG.warning("Unknown response representation tag " + tag.name());
            }
        }
        responseDoc.getRepresentations().add(representationDoc);
    }
    methodDocType.setResponseDoc(responseDoc);
}
Also used : WadlParamType(org.glassfish.jersey.server.wadl.internal.generators.resourcedoc.model.WadlParamType) ResponseDocType(org.glassfish.jersey.server.wadl.internal.generators.resourcedoc.model.ResponseDocType) ArrayList(java.util.ArrayList) List(java.util.List) Tag(com.sun.javadoc.Tag) ParamTag(com.sun.javadoc.ParamTag) SeeTag(com.sun.javadoc.SeeTag) RepresentationDocType(org.glassfish.jersey.server.wadl.internal.generators.resourcedoc.model.RepresentationDocType)

Aggregations

ArrayList (java.util.ArrayList)2 RepresentationDocType (org.glassfish.jersey.server.wadl.internal.generators.resourcedoc.model.RepresentationDocType)2 ResponseDocType (org.glassfish.jersey.server.wadl.internal.generators.resourcedoc.model.ResponseDocType)2 WadlParamType (org.glassfish.jersey.server.wadl.internal.generators.resourcedoc.model.WadlParamType)2 ParamTag (com.sun.javadoc.ParamTag)1 SeeTag (com.sun.javadoc.SeeTag)1 Tag (com.sun.javadoc.Tag)1 Param (com.sun.research.ws.wadl.Param)1 Representation (com.sun.research.ws.wadl.Representation)1 Response (com.sun.research.ws.wadl.Response)1 List (java.util.List)1