Search in sources :

Example 1 with Representation

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

the class WadlBuilder method setRepresentationForMediaType.

/**
     * Create the wadl {@link Representation} for the specified {@link MediaType} if not yet existing for the wadl {@link Request}
     * and return it.
     *
     * @param r           the resource
     * @param m           the resource method
     * @param mediaType   an accepted media type of the resource method
     * @param wadlRequest the wadl request the wadl representation is to be created for (if not yet existing).
     * @return the wadl request representation for the specified {@link MediaType}.
     */
private Representation setRepresentationForMediaType(org.glassfish.jersey.server.model.Resource r, final org.glassfish.jersey.server.model.ResourceMethod m, MediaType mediaType, Request wadlRequest) {
    try {
        Representation wadlRepresentation = getRepresentationByMediaType(wadlRequest.getRepresentation(), mediaType);
        if (wadlRepresentation == null) {
            wadlRepresentation = _wadlGenerator.createRequestRepresentation(r, m, mediaType);
            wadlRequest.getRepresentation().add(wadlRepresentation);
        }
        return wadlRepresentation;
    } catch (Exception e) {
        throw new ProcessingException(LocalizationMessages.ERROR_WADL_BUILDER_GENERATION_REQUEST_MEDIA_TYPE(mediaType, m, r), e);
    }
}
Also used : Representation(com.sun.research.ws.wadl.Representation) ProcessingException(javax.ws.rs.ProcessingException) ProcessingException(javax.ws.rs.ProcessingException)

Example 2 with Representation

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

the class WadlGeneratorImpl method createRequestRepresentation.

@Override
public Representation createRequestRepresentation(org.glassfish.jersey.server.model.Resource r, ResourceMethod m, MediaType mediaType) {
    Representation wadlRepresentation = new Representation();
    wadlRepresentation.setMediaType(mediaType.toString());
    return wadlRepresentation;
}
Also used : Representation(com.sun.research.ws.wadl.Representation)

Example 3 with Representation

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

the class WadlGeneratorResourceDocSupport method createRequestRepresentation.

/**
     * @param r Jersey resource component.
     * @param m resource method.
     * @param mediaType media type.
     * @return the enhanced {@link com.sun.research.ws.wadl.Representation}.
     * @see org.glassfish.jersey.server.wadl.WadlGenerator#createRequestRepresentation(org.glassfish.jersey.server.model.Resource,
     * org.glassfish.jersey.server.model.ResourceMethod, javax.ws.rs.core.MediaType)
     */
public Representation createRequestRepresentation(final org.glassfish.jersey.server.model.Resource r, final org.glassfish.jersey.server.model.ResourceMethod m, final MediaType mediaType) {
    final Representation result = delegate.createRequestRepresentation(r, m, mediaType);
    final RepresentationDocType requestRepresentation = resourceDoc.getRequestRepresentation(m.getInvocable().getDefinitionMethod().getDeclaringClass(), m.getInvocable().getDefinitionMethod(), result.getMediaType());
    if (requestRepresentation != null) {
        result.setElement(requestRepresentation.getElement());
        addDocForExample(result.getDoc(), requestRepresentation.getExample());
    }
    return result;
}
Also used : Representation(com.sun.research.ws.wadl.Representation) RepresentationDocType(org.glassfish.jersey.server.wadl.internal.generators.resourcedoc.model.RepresentationDocType)

Example 4 with Representation

use of com.sun.research.ws.wadl.Representation 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 5 with Representation

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

the class WadlGeneratorImpl method createResponses.

@Override
public List<Response> createResponses(org.glassfish.jersey.server.model.Resource r, ResourceMethod m) {
    final Response response = new Response();
    // add mediaType="*/*" in case that no mediaType was specified
    if (hasEmptyProducibleMediaTypeSet(m)) {
        Representation wadlRepresentation = createResponseRepresentation(r, m, MediaType.WILDCARD_TYPE);
        response.getRepresentation().add(wadlRepresentation);
    } else {
        for (MediaType mediaType : m.getProducedTypes()) {
            Representation wadlRepresentation = createResponseRepresentation(r, m, mediaType);
            response.getRepresentation().add(wadlRepresentation);
        }
    }
    List<Response> responses = new ArrayList<Response>();
    responses.add(response);
    return responses;
}
Also used : Response(com.sun.research.ws.wadl.Response) ArrayList(java.util.ArrayList) MediaType(javax.ws.rs.core.MediaType) Representation(com.sun.research.ws.wadl.Representation)

Aggregations

Representation (com.sun.research.ws.wadl.Representation)6 Response (com.sun.research.ws.wadl.Response)2 ArrayList (java.util.ArrayList)2 RepresentationDocType (org.glassfish.jersey.server.wadl.internal.generators.resourcedoc.model.RepresentationDocType)2 Param (com.sun.research.ws.wadl.Param)1 ProcessingException (javax.ws.rs.ProcessingException)1 MediaType (javax.ws.rs.core.MediaType)1 ResponseDocType (org.glassfish.jersey.server.wadl.internal.generators.resourcedoc.model.ResponseDocType)1 WadlParamType (org.glassfish.jersey.server.wadl.internal.generators.resourcedoc.model.WadlParamType)1