use of org.glassfish.jersey.server.wadl.internal.generators.resourcedoc.model.MethodDocType 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);
}
use of org.glassfish.jersey.server.wadl.internal.generators.resourcedoc.model.MethodDocType in project jersey by jersey.
the class WadlGeneratorResourceDocSupport method createMethod.
/**
* @param resource Jersey resource component.
* @param resourceMethod resource method.
* @return the enhanced {@link com.sun.research.ws.wadl.Method}.
* @see org.glassfish.jersey.server.wadl.WadlGenerator#createMethod(org.glassfish.jersey.server.model.Resource,
* org.glassfish.jersey.server.model.ResourceMethod)
*/
public Method createMethod(final org.glassfish.jersey.server.model.Resource resource, final ResourceMethod resourceMethod) {
final Method result = delegate.createMethod(resource, resourceMethod);
final java.lang.reflect.Method method = resourceMethod.getInvocable().getDefinitionMethod();
final MethodDocType methodDoc = resourceDoc.getMethodDoc(method.getDeclaringClass(), method);
if (methodDoc != null && !isEmpty(methodDoc.getCommentText())) {
final Doc doc = new Doc();
doc.getContent().add(methodDoc.getCommentText());
// doc.getOtherAttributes().put( new QName( "xmlns" ), "http://www.w3.org/1999/xhtml" );
result.getDoc().add(doc);
}
return result;
}
use of org.glassfish.jersey.server.wadl.internal.generators.resourcedoc.model.MethodDocType in project jersey by jersey.
the class ResourceDoclet method start.
/**
* Start the doclet.
*
* @param root the root JavaDoc document.
* @return true if no exception is thrown.
*/
public static boolean start(final RootDoc root) {
final String output = getOptionArg(root.options(), OPTION_OUTPUT);
final String classpath = getOptionArg(root.options(), OPTION_CLASSPATH);
// LOG.info( "Have classpath: " + classpath );
final String[] classpathElements = classpath.split(File.pathSeparator);
final ClassLoader cl = Thread.currentThread().getContextClassLoader();
final ClassLoader ncl = new Loader(classpathElements, ResourceDoclet.class.getClassLoader());
Thread.currentThread().setContextClassLoader(ncl);
final String docProcessorOption = getOptionArg(root.options(), OPTION_DOC_PROCESSORS);
final String[] docProcessors = docProcessorOption != null ? docProcessorOption.split(":") : null;
final DocProcessorWrapper docProcessor = new DocProcessorWrapper();
try {
if (docProcessors != null && docProcessors.length > 0) {
final Class<?> clazz = Class.forName(docProcessors[0], true, Thread.currentThread().getContextClassLoader());
final Class<? extends DocProcessor> dpClazz = clazz.asSubclass(DocProcessor.class);
docProcessor.add(dpClazz.newInstance());
}
} catch (final Exception e) {
LOG.log(Level.SEVERE, "Could not load docProcessors " + docProcessorOption, e);
}
try {
final ResourceDocType result = new ResourceDocType();
final ClassDoc[] classes = root.classes();
for (final ClassDoc classDoc : classes) {
LOG.fine("Writing class " + classDoc.qualifiedTypeName());
final ClassDocType classDocType = new ClassDocType();
classDocType.setClassName(classDoc.qualifiedTypeName());
classDocType.setCommentText(classDoc.commentText());
docProcessor.processClassDoc(classDoc, classDocType);
for (final MethodDoc methodDoc : classDoc.methods()) {
final MethodDocType methodDocType = new MethodDocType();
methodDocType.setMethodName(methodDoc.name());
methodDocType.setMethodSignature(methodDoc.signature());
methodDocType.setCommentText(methodDoc.commentText());
docProcessor.processMethodDoc(methodDoc, methodDocType);
addParamDocs(methodDoc, methodDocType, docProcessor);
addRequestRepresentationDoc(methodDoc, methodDocType);
addResponseDoc(methodDoc, methodDocType);
classDocType.getMethodDocs().add(methodDocType);
}
result.getDocs().add(classDocType);
}
try {
final Class<?>[] clazzes = getJAXBContextClasses(result, docProcessor);
final JAXBContext c = JAXBContext.newInstance(clazzes);
final Marshaller m = c.createMarshaller();
m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
final OutputStream out = new BufferedOutputStream(new FileOutputStream(output));
final String[] cdataElements = getCDataElements(docProcessor);
final XMLSerializer serializer = getXMLSerializer(out, cdataElements);
m.marshal(result, serializer);
out.close();
LOG.info("Wrote " + output);
} catch (final Exception e) {
LOG.log(Level.SEVERE, "Could not serialize ResourceDoc.", e);
return false;
}
} finally {
Thread.currentThread().setContextClassLoader(cl);
}
return true;
}
use of org.glassfish.jersey.server.wadl.internal.generators.resourcedoc.model.MethodDocType in project jersey by jersey.
the class ResourceDocAccessor method getMethodDoc.
public MethodDocType getMethodDoc(Class<?> resourceClass, Method method) {
if (resourceClass == null || method == null) {
return null;
}
final ClassDocType classDoc = getClassDoc(resourceClass);
if (classDoc == null) {
return null;
}
MethodDocType candidate = null;
int candidateCount = 0;
final String methodName = method.getName();
final String methodSignature = computeSignature(method);
for (MethodDocType methodDocType : classDoc.getMethodDocs()) {
if (methodName.equals(methodDocType.getMethodName())) {
candidateCount++;
if (candidate == null) {
candidate = methodDocType;
}
final String docMethodSignature = methodDocType.getMethodSignature();
if (docMethodSignature != null && docMethodSignature.equals(methodSignature)) {
return methodDocType;
}
}
}
if (candidate != null && candidateCount > 1 && LOGGER.isLoggable(Level.CONFIG)) {
LOGGER.config(LocalizationMessages.WADL_RESOURCEDOC_AMBIGUOUS_METHOD_ENTRIES(resourceClass.getName(), methodName, methodSignature, candidateCount));
}
return candidate;
}
Aggregations