use of org.apache.cxf.tools.wadlto.jaxb.CustomizationParser in project cxf by apache.
the class JAXRSContainer method processWadl.
private void processWadl() {
File outDir = new File((String) context.get(WadlToolConstants.CFG_OUTPUTDIR));
String wadlURL = getAbsoluteWadlURL();
String authentication = (String) context.get(WadlToolConstants.CFG_AUTHENTICATION);
String wadl = readWadl(wadlURL, authentication);
SourceGenerator sg = new SourceGenerator();
sg.setBus(getBus());
boolean generateImpl = context.optionSet(WadlToolConstants.CFG_IMPL);
sg.setGenerateImplementation(generateImpl);
if (generateImpl) {
sg.setGenerateInterfaces(context.optionSet(WadlToolConstants.CFG_INTERFACE));
}
sg.setPackageName((String) context.get(WadlToolConstants.CFG_PACKAGENAME));
sg.setResourceName((String) context.get(WadlToolConstants.CFG_RESOURCENAME));
sg.setEncoding((String) context.get(WadlToolConstants.CFG_ENCODING));
sg.setAuthentication(authentication);
String wadlNs = (String) context.get(WadlToolConstants.CFG_WADL_NAMESPACE);
if (wadlNs != null) {
sg.setWadlNamespace(wadlNs);
}
sg.setJaxbClassNameSuffix((String) context.get(WadlToolConstants.CFG_JAXB_CLASS_NAME_SUFFIX));
sg.setSupportMultipleXmlReps(context.optionSet(WadlToolConstants.CFG_MULTIPLE_XML_REPS));
sg.setSupportBeanValidation(context.optionSet(WadlToolConstants.CFG_BEAN_VALIDATION));
sg.setCreateJavaDocs(context.optionSet(WadlToolConstants.CFG_CREATE_JAVA_DOCS));
// set the base path
sg.setWadlPath(wadlURL);
CustomizationParser parser = new CustomizationParser(context);
parser.parse(context);
List<InputSource> bindingFiles = parser.getJaxbBindings();
sg.setBindingFiles(bindingFiles);
sg.setCompilerArgs(parser.getCompilerArgs());
List<InputSource> schemaPackageFiles = parser.getSchemaPackageFiles();
sg.setSchemaPackageFiles(schemaPackageFiles);
sg.setSchemaPackageMap(context.getNamespacePackageMap());
sg.setJavaTypeMap(DEFAULT_JAVA_TYPE_MAP);
sg.setSchemaTypeMap(getSchemaTypeMap());
sg.setMediaTypeMap(getMediaTypeMap());
sg.setSuspendedAsyncMethods(getSuspendedAsyncMethods());
sg.setResponseMethods(getResponseMethods());
sg.setOnewayMethods(getOnewayMethods());
sg.setGenerateEnums(context.optionSet(WadlToolConstants.CFG_GENERATE_ENUMS));
sg.setValidateWadl(context.optionSet(WadlToolConstants.CFG_VALIDATE_WADL));
boolean inheritResourceParams = context.optionSet(WadlToolConstants.CFG_INHERIT_PARAMS);
sg.setInheritResourceParams(inheritResourceParams);
if (inheritResourceParams) {
sg.setInheritResourceParamsFirst(isInheritResourceParamsFirst());
}
sg.setSkipSchemaGeneration(context.optionSet(WadlToolConstants.CFG_NO_TYPES));
boolean noVoidForEmptyResponses = context.optionSet(WadlToolConstants.CFG_NO_VOID_FOR_EMPTY_RESPONSES);
if (noVoidForEmptyResponses) {
sg.setUseVoidForEmptyResponses(false);
}
sg.setGenerateResponseIfHeadersSet(context.optionSet(WadlToolConstants.CFG_GENERATE_RESPONSE_IF_HEADERS_SET));
// generate
String codeType = context.optionSet(WadlToolConstants.CFG_TYPES) ? SourceGenerator.CODE_TYPE_GRAMMAR : SourceGenerator.CODE_TYPE_PROXY;
sg.generateSource(wadl, outDir, codeType);
// compile
if (context.optionSet(WadlToolConstants.CFG_COMPILE)) {
ClassCollector collector = createClassCollector();
List<String> generatedServiceClasses = sg.getGeneratedServiceClasses();
for (String className : generatedServiceClasses) {
int index = className.lastIndexOf(".");
collector.addServiceClassName(className.substring(0, index), className.substring(index + 1), className);
}
List<String> generatedTypeClasses = sg.getGeneratedTypeClasses();
for (String className : generatedTypeClasses) {
int index = className.lastIndexOf(".");
collector.addTypesClassName(className.substring(0, index), className.substring(index + 1), className);
}
context.put(ClassCollector.class, collector);
new ClassUtils().compile(context);
}
}
Aggregations