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();
}
}
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;
}
Aggregations