Search in sources :

Example 16 with ClassCollector

use of org.apache.cxf.tools.util.ClassCollector in project cxf by apache.

the class JAXBDataBinding method addedToClassCollector.

private boolean addedToClassCollector(String packageName) {
    ClassCollector classCollector = context.get(ClassCollector.class);
    Collection<String> files = classCollector.getGeneratedFileInfo();
    for (String file : files) {
        int dotIndex = file.lastIndexOf(".");
        String sub = dotIndex <= 0 ? "" : file.substring(0, dotIndex - 1);
        if (sub.equals(packageName)) {
            return true;
        }
    }
    return false;
}
Also used : ClassCollector(org.apache.cxf.tools.util.ClassCollector)

Example 17 with ClassCollector

use of org.apache.cxf.tools.util.ClassCollector in project cxf by apache.

the class XmlSeeAlsoAnnotatorTest method testAddXmlSeeAlsoAnnotation.

@Test
public void testAddXmlSeeAlsoAnnotation() throws Exception {
    JavaInterface intf = new JavaInterface();
    assertFalse(intf.getImports().hasNext());
    ClassCollector collector = new ClassCollector();
    collector.getTypesPackages().add(ObjectFactory.class.getPackage().getName());
    intf.annotate(new XmlSeeAlsoAnnotator(collector));
    Iterator<String> iter = intf.getImports();
    assertEquals("javax.xml.bind.annotation.XmlSeeAlso", iter.next());
    assertEquals("@XmlSeeAlso({" + ObjectFactory.class.getName() + ".class})", intf.getAnnotations().iterator().next().toString());
}
Also used : JavaInterface(org.apache.cxf.tools.common.model.JavaInterface) ObjectFactory(org.apache.cxf.tools.wsdlto.frontend.jaxws.processor.internal.annotator.types.ObjectFactory) ClassCollector(org.apache.cxf.tools.util.ClassCollector) Test(org.junit.Test)

Example 18 with ClassCollector

use of org.apache.cxf.tools.util.ClassCollector 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)

Example 19 with ClassCollector

use of org.apache.cxf.tools.util.ClassCollector in project cxf by apache.

the class AbstractCXFToolContainer method createClassCollector.

protected ClassCollector createClassCollector() {
    ClassCollector collector = new ClassCollector();
    String[] reserved = (String[]) context.get(ToolConstants.CFG_RESERVE_NAME);
    if (reserved != null) {
        for (String r : reserved) {
            collector.reserveClass(r);
        }
    }
    return collector;
}
Also used : ClassCollector(org.apache.cxf.tools.util.ClassCollector)

Aggregations

ClassCollector (org.apache.cxf.tools.util.ClassCollector)19 ToolException (org.apache.cxf.tools.common.ToolException)6 File (java.io.File)4 IOException (java.io.IOException)4 Message (org.apache.cxf.common.i18n.Message)4 ArrayList (java.util.ArrayList)3 QName (javax.xml.namespace.QName)3 URL (java.net.URL)2 HashSet (java.util.HashSet)2 SchemaCollection (org.apache.cxf.common.xmlschema.SchemaCollection)2 ServiceInfo (org.apache.cxf.service.model.ServiceInfo)2 ClassUtils (org.apache.cxf.tools.common.ClassUtils)2 JavaInterface (org.apache.cxf.tools.common.model.JavaInterface)2 JavaModel (org.apache.cxf.tools.common.model.JavaModel)2 JavaPort (org.apache.cxf.tools.common.model.JavaPort)2 JavaServiceClass (org.apache.cxf.tools.common.model.JavaServiceClass)2 JAXWSBinding (org.apache.cxf.tools.wsdlto.frontend.jaxws.customization.JAXWSBinding)2 Test (org.junit.Test)2 InputSource (org.xml.sax.InputSource)2 JClass (com.sun.codemodel.JClass)1