Search in sources :

Example 1 with VelocityGenerator

use of org.apache.cxf.tools.common.VelocityGenerator in project cxf by apache.

the class BeanGenerator method generateAndCompile.

public void generateAndCompile(Collection<JavaClass> wrapperClasses, File dir) {
    VelocityGenerator generator = new VelocityGenerator(false);
    generator.setBaseDir(dir.toString());
    List<File> generatedFiles = new ArrayList<>();
    try {
        for (JavaClass wrapperClass : wrapperClasses) {
            generator.setCommonAttributes();
            generator.setAttributes("bean", wrapperClass);
            File file = generator.parseOutputName(wrapperClass.getPackageName(), wrapperClass.getName());
            generatedFiles.add(file);
            generator.doWrite(TEMPLATE, new FileWriterUtil(file.getParent(), getOutputStreamCreator()).getWriter(file, (String) getToolContext().get(ToolConstants.CFG_ENCODING)));
            generator.clearAttributes();
        }
        // compile the classes
        Compiler compiler = new Compiler();
        compiler.setOutputDir(compileToDir);
        List<String> files = new ArrayList<>(generatedFiles.size());
        for (File file : generatedFiles) {
            files.add(file.getAbsolutePath());
        }
        compiler.compileFiles(files.toArray(new String[files.size()]));
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : Compiler(org.apache.cxf.common.util.Compiler) VelocityGenerator(org.apache.cxf.tools.common.VelocityGenerator) JavaClass(org.apache.cxf.tools.common.model.JavaClass) FileWriterUtil(org.apache.cxf.tools.util.FileWriterUtil) ArrayList(java.util.ArrayList) File(java.io.File)

Example 2 with VelocityGenerator

use of org.apache.cxf.tools.common.VelocityGenerator in project cxf by apache.

the class DateTypeCustomGenerator method generate.

public File generate(File outputdir) {
    Class<?> dateType = getDateType();
    File xjb = getJAXBCustFile(outputdir);
    if (dateType != null) {
        VelocityGenerator generator = new VelocityGenerator(false);
        generator.setCommonAttributes();
        generator.setAttributes("parseMethod", getAdapterMethod(dateType, ".parseDateTime"));
        generator.setAttributes("printMethod", getAdapterMethod(dateType, ".printDateTime"));
        generator.setAttributes("datetype", dateType.getName());
        if (allowImports()) {
            if (schemaFiles.isEmpty()) {
                return null;
            }
            generator.setAttributes("schemaFiles", schemaFiles);
        } else {
            generator.setAttributes("wsdlName", wsdlName);
            List<String> ns = getSchemaNamespaces();
            if (ns.isEmpty()) {
                return null;
            }
            generator.setAttributes("targetNamespaces", ns);
        }
        try {
            generator.doWrite(getTemplate(), new FileWriterUtil(xjb.getParent(), getOutputStreamCreator()).getWriter(xjb, StandardCharsets.UTF_8.name()));
        } catch (Exception e) {
            e.printStackTrace();
        }
        generator.clearAttributes();
    }
    return xjb;
}
Also used : VelocityGenerator(org.apache.cxf.tools.common.VelocityGenerator) FileWriterUtil(org.apache.cxf.tools.util.FileWriterUtil) File(java.io.File)

Aggregations

File (java.io.File)2 VelocityGenerator (org.apache.cxf.tools.common.VelocityGenerator)2 FileWriterUtil (org.apache.cxf.tools.util.FileWriterUtil)2 ArrayList (java.util.ArrayList)1 Compiler (org.apache.cxf.common.util.Compiler)1 JavaClass (org.apache.cxf.tools.common.model.JavaClass)1