use of org.apache.cxf.jaxrs.model.ResourceTypes in project cxf by apache.
the class WadlGenerator method generateWADL.
public StringBuilder generateWADL(String baseURI, List<ClassResourceInfo> cris, boolean isJson, Message m, UriInfo ui) {
StringBuilder sbMain = new StringBuilder();
if (!isJson && stylesheetReference != null && !applyStylesheetLocally) {
sbMain.append("<?xml-stylesheet ").append(getStylesheetInstructionData(baseURI)).append("?>");
}
sbMain.append("<application");
if (!isJson) {
sbMain.append(" xmlns=\"").append(getNamespace()).append("\" xmlns:xs=\"").append(Constants.URI_2001_SCHEMA_XSD).append("\"");
}
StringBuilder sbGrammars = new StringBuilder();
sbGrammars.append("<grammars>");
StringBuilder sbResources = new StringBuilder();
sbResources.append("<resources base=\"").append(baseURI).append("\">");
MessageBodyWriter<?> jaxbWriter = (m != null && useJaxbContextForQnames) ? ServerProviderFactory.getInstance(m).getDefaultJaxbWriter() : null;
ResourceTypes resourceTypes = ResourceUtils.getAllRequestResponseTypes(cris, useJaxbContextForQnames, jaxbWriter);
checkXmlSeeAlso(resourceTypes);
Set<Class<?>> allTypes = resourceTypes.getAllTypes().keySet();
JAXBContext jaxbContext = null;
if (useJaxbContextForQnames && !allTypes.isEmpty()) {
jaxbContext = ResourceUtils.createJaxbContext(new HashSet<>(allTypes), null, jaxbContextProperties);
if (jaxbContext == null) {
LOG.warning("JAXB Context is null: possibly due to one of input classes being not accepted");
}
}
SchemaWriter schemaWriter = createSchemaWriter(resourceTypes, jaxbContext, ui);
ElementQNameResolver qnameResolver = schemaWriter == null ? null : createElementQNameResolver(jaxbContext);
Map<Class<?>, QName> clsMap = new IdentityHashMap<>();
Set<ClassResourceInfo> visitedResources = new LinkedHashSet<>();
for (ClassResourceInfo cri : cris) {
startResourceTag(sbResources, cri, cri.getURITemplate().getValue());
Annotation description = AnnotationUtils.getClassAnnotation(cri.getServiceClass(), Description.class);
if (description == null) {
description = AnnotationUtils.getClassAnnotation(cri.getServiceClass(), Descriptions.class);
}
if (description != null) {
handleDocs(new Annotation[] { description }, sbResources, DocTarget.RESOURCE, true, isJson);
} else {
handleClassJavaDocs(cri, sbResources);
}
handleResource(sbResources, allTypes, qnameResolver, clsMap, cri, visitedResources, isJson);
sbResources.append("</resource>");
}
sbResources.append("</resources>");
handleGrammars(sbMain, sbGrammars, schemaWriter, clsMap);
sbGrammars.append("</grammars>");
sbMain.append(">");
handleApplicationDocs(sbMain);
sbMain.append(sbGrammars.toString());
sbMain.append(sbResources.toString());
sbMain.append("</application>");
return sbMain;
}
Aggregations