public void execute() throws BuildException {
// Create a Velocity Context and a Velocity Template
VelocityContext ctx = new VelocityContext();
Template template = null;
// Output to a file
FileWriter writer = null;
// XmlBeans
SchemaTypeSystem schemaTypeSystem = null;
try {
// Initialize Velocity
Velocity.init();
log.info("Using the Velocity template, " + this.template);
template = Velocity.getTemplate(this.template);
// Create Schema Type System
log.info("Using the xml schema, " + this.schema);
schemaTypeSystem = XmlBeans.compileXsd(
new XmlObject[] { XmlBeans.typeLoaderForClassLoader(this.getClass().getClassLoader()).
parse(new File(this.schema), null, null) },
XmlBeans.getBuiltinTypeSystem(),
null);
// Place SchemaTypeSystem in the Velocity Context
ctx.put("xsd", schemaTypeSystem);
// Place a exported key Map in the Velocity Context
ctx.put("exportedKeyMap", createExportedKeyMap(schemaTypeSystem));
// Write to the file
log.info("Using the output file, " + this.output);
writer = new FileWriter(new File(this.output));
template.merge(ctx, writer);
writer.close();
} catch (Exception e) {
throw new BuildException(e);
}
}
Puts the XmlBeans SchemaTypeSystem into the Velocity Context |