use of org.glassfish.jersey.server.wadl.internal.generators.resourcedoc.model.ResourceDocType 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.ResourceDocType 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.ResourceDocType in project jersey by jersey.
the class WadlGeneratorResourceDocSupport method init.
public void init() throws Exception {
if (resourceDocFile == null && resourceDocStream == null) {
throw new IllegalStateException("Neither the resourceDocFile nor the resourceDocStream" + " is set, one of both is required.");
}
delegate.init();
try (final InputStream inputStream = resourceDocFile != null ? new FileInputStream(resourceDocFile) : resourceDocStream) {
final ResourceDocType resourceDocType = WadlUtils.unmarshall(inputStream, saxFactoryProvider.get(), ResourceDocType.class);
resourceDoc = new ResourceDocAccessor(resourceDocType);
} finally {
resourceDocFile = null;
}
}
Aggregations