Search in sources :

Example 1 with NamedValueType

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

the class WadlGeneratorResourceDocSupportTest method wadlIsGeneratedWithUnknownCustomParameterAnnotation.

@Test
public void wadlIsGeneratedWithUnknownCustomParameterAnnotation() throws JAXBException {
    /* Set up a ClassDocType that has something for a custom-annotated parameter */
    ClassDocType cdt = new ClassDocType();
    cdt.setClassName(TestResource.class.getName());
    MethodDocType mdt = new MethodDocType();
    mdt.setMethodName("method");
    cdt.getMethodDocs().add(mdt);
    ParamDocType pdt = new ParamDocType("x", "comment about x");
    mdt.getParamDocs().add(pdt);
    AnnotationDocType adt = new AnnotationDocType();
    adt.setAnnotationTypeName(CustomParam.class.getName());
    adt.getAttributeDocs().add(new NamedValueType("value", "x"));
    pdt.getAnnotationDocs().add(adt);
    ResourceDocType rdt = new ResourceDocType();
    rdt.getDocs().add(cdt);
    /* Generate WADL for that class */
    WadlGenerator wg = new WadlGeneratorResourceDocSupport(new WadlGeneratorImpl(), rdt);
    WadlBuilder wb = new WadlBuilder(wg, false, null);
    Resource resource = Resource.from(TestResource.class);
    ApplicationDescription app = wb.generate(Collections.singletonList(resource));
    /* Confirm that it can be marshalled without error */
    StringWriter sw = new StringWriter();
    JAXBContext context = JAXBContext.newInstance(Application.class);
    Marshaller m = context.createMarshaller();
    m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
    m.marshal(app.getApplication(), sw);
}
Also used : WadlGeneratorImpl(org.glassfish.jersey.server.wadl.internal.WadlGeneratorImpl) Marshaller(javax.xml.bind.Marshaller) ClassDocType(org.glassfish.jersey.server.wadl.internal.generators.resourcedoc.model.ClassDocType) NamedValueType(org.glassfish.jersey.server.wadl.internal.generators.resourcedoc.model.NamedValueType) Resource(org.glassfish.jersey.server.model.Resource) AnnotationDocType(org.glassfish.jersey.server.wadl.internal.generators.resourcedoc.model.AnnotationDocType) WadlBuilder(org.glassfish.jersey.server.wadl.internal.WadlBuilder) JAXBContext(javax.xml.bind.JAXBContext) ApplicationDescription(org.glassfish.jersey.server.wadl.internal.ApplicationDescription) WadlGenerator(org.glassfish.jersey.server.wadl.WadlGenerator) StringWriter(java.io.StringWriter) MethodDocType(org.glassfish.jersey.server.wadl.internal.generators.resourcedoc.model.MethodDocType) ResourceDocType(org.glassfish.jersey.server.wadl.internal.generators.resourcedoc.model.ResourceDocType) WadlGeneratorResourceDocSupport(org.glassfish.jersey.server.wadl.internal.generators.resourcedoc.WadlGeneratorResourceDocSupport) ParamDocType(org.glassfish.jersey.server.wadl.internal.generators.resourcedoc.model.ParamDocType) Test(org.junit.Test)

Example 2 with NamedValueType

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

the class ResourceDoclet method addParamDocs.

private static void addParamDocs(final MethodDoc methodDoc, final MethodDocType methodDocType, final DocProcessor docProcessor) {
    final Parameter[] parameters = methodDoc.parameters();
    final ParamTag[] paramTags = methodDoc.paramTags();
    /* only use both javadoc and reflection information when the number
         * of params are the same
         */
    if (parameters != null && paramTags != null && parameters.length == paramTags.length) {
        for (int i = 0; i < parameters.length; i++) {
            final Parameter parameter = parameters[i];
            /* TODO: this only works if the params and tags are in the same
                 * order. If the param tags are mixed up, the comments for parameters
                 * will be wrong.
                 */
            final ParamTag paramTag = paramTags[i];
            final ParamDocType paramDocType = new ParamDocType();
            paramDocType.setParamName(paramTag.parameterName());
            paramDocType.setCommentText(paramTag.parameterComment());
            docProcessor.processParamTag(paramTag, parameter, paramDocType);
            final AnnotationDesc[] annotations = parameter.annotations();
            if (annotations != null) {
                for (final AnnotationDesc annotationDesc : annotations) {
                    final AnnotationDocType annotationDocType = new AnnotationDocType();
                    final String typeName = annotationDesc.annotationType().qualifiedName();
                    annotationDocType.setAnnotationTypeName(typeName);
                    for (final ElementValuePair elementValuePair : annotationDesc.elementValues()) {
                        final NamedValueType namedValueType = new NamedValueType();
                        namedValueType.setName(elementValuePair.element().name());
                        namedValueType.setValue(elementValuePair.value().value().toString());
                        annotationDocType.getAttributeDocs().add(namedValueType);
                    }
                    paramDocType.getAnnotationDocs().add(annotationDocType);
                }
            }
            methodDocType.getParamDocs().add(paramDocType);
        }
    }
}
Also used : ParamTag(com.sun.javadoc.ParamTag) ElementValuePair(com.sun.javadoc.AnnotationDesc.ElementValuePair) NamedValueType(org.glassfish.jersey.server.wadl.internal.generators.resourcedoc.model.NamedValueType) Parameter(com.sun.javadoc.Parameter) AnnotationDocType(org.glassfish.jersey.server.wadl.internal.generators.resourcedoc.model.AnnotationDocType) ParamDocType(org.glassfish.jersey.server.wadl.internal.generators.resourcedoc.model.ParamDocType) AnnotationDesc(com.sun.javadoc.AnnotationDesc)

Aggregations

AnnotationDocType (org.glassfish.jersey.server.wadl.internal.generators.resourcedoc.model.AnnotationDocType)2 NamedValueType (org.glassfish.jersey.server.wadl.internal.generators.resourcedoc.model.NamedValueType)2 ParamDocType (org.glassfish.jersey.server.wadl.internal.generators.resourcedoc.model.ParamDocType)2 AnnotationDesc (com.sun.javadoc.AnnotationDesc)1 ElementValuePair (com.sun.javadoc.AnnotationDesc.ElementValuePair)1 ParamTag (com.sun.javadoc.ParamTag)1 Parameter (com.sun.javadoc.Parameter)1 StringWriter (java.io.StringWriter)1 JAXBContext (javax.xml.bind.JAXBContext)1 Marshaller (javax.xml.bind.Marshaller)1 Resource (org.glassfish.jersey.server.model.Resource)1 WadlGenerator (org.glassfish.jersey.server.wadl.WadlGenerator)1 ApplicationDescription (org.glassfish.jersey.server.wadl.internal.ApplicationDescription)1 WadlBuilder (org.glassfish.jersey.server.wadl.internal.WadlBuilder)1 WadlGeneratorImpl (org.glassfish.jersey.server.wadl.internal.WadlGeneratorImpl)1 WadlGeneratorResourceDocSupport (org.glassfish.jersey.server.wadl.internal.generators.resourcedoc.WadlGeneratorResourceDocSupport)1 ClassDocType (org.glassfish.jersey.server.wadl.internal.generators.resourcedoc.model.ClassDocType)1 MethodDocType (org.glassfish.jersey.server.wadl.internal.generators.resourcedoc.model.MethodDocType)1 ResourceDocType (org.glassfish.jersey.server.wadl.internal.generators.resourcedoc.model.ResourceDocType)1 Test (org.junit.Test)1