Search in sources :

Example 1 with CustomizationParser

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);
    }
}
Also used : InputSource(org.xml.sax.InputSource) CustomizationParser(org.apache.cxf.tools.wadlto.jaxb.CustomizationParser) ClassCollector(org.apache.cxf.tools.util.ClassCollector) File(java.io.File) ClassUtils(org.apache.cxf.tools.common.ClassUtils)

Aggregations

File (java.io.File)1 ClassUtils (org.apache.cxf.tools.common.ClassUtils)1 ClassCollector (org.apache.cxf.tools.util.ClassCollector)1 CustomizationParser (org.apache.cxf.tools.wadlto.jaxb.CustomizationParser)1 InputSource (org.xml.sax.InputSource)1