dataModel.put("schema", schema);
dataModel.put("metadata", metadata);
dataModel.put("className", className);
dataModel.put("packageName", packageName);
TemplateRepresentation templateRepresentation = new TemplateRepresentation(
entityTmpl, fmc, dataModel, MediaType.TEXT_PLAIN);
templateRepresentation.setCharacterSet(CharacterSet.UTF_8);
// Write the template representation as a Java class
templateRepresentation.write(new FileOutputStream(new File(
packageDir, type.getClassName() + ".java")));
}
for (ComplexType type : schema.getComplexTypes()) {
String className = type.getClassName();
Map<String, Object> dataModel = new HashMap<String, Object>();
dataModel.put("type", type);
dataModel.put("schema", schema);
dataModel.put("metadata", metadata);
dataModel.put("className", className);
dataModel.put("packageName", packageName);
TemplateRepresentation templateRepresentation = new TemplateRepresentation(
complexTmpl, fmc, dataModel, MediaType.TEXT_PLAIN);
templateRepresentation.setCharacterSet(CharacterSet.UTF_8);
// Write the template representation as a Java class
templateRepresentation.write(new FileOutputStream(new File(
packageDir, type.getClassName() + ".java")));
}
}
}
if (metadata.getContainers() != null
&& !metadata.getContainers().isEmpty()) {
for (EntityContainer entityContainer : metadata.getContainers()) {
Schema schema = entityContainer.getSchema();
// Generate Service subclass
StringBuffer className = new StringBuffer();
if (serviceClassName != null) {
// Try to use the Client preference
if (entityContainer.isDefaultEntityContainer()) {
className.append(serviceClassName);
} else if (metadata.getContainers().size() == 1) {
className.append(serviceClassName);
} else {
className.append(schema.getNamespace()
.getNormalizedName().substring(0, 1)
.toUpperCase());
className.append(schema.getNamespace()
.getNormalizedName().substring(1));
className.append("Service");
}
} else {
className.append(schema.getNamespace().getNormalizedName()
.substring(0, 1).toUpperCase());
className.append(schema.getNamespace().getNormalizedName()
.substring(1));
className.append("Service");
}
Map<String, Object> dataModel = new HashMap<String, Object>();
dataModel.put("schema", schema);
dataModel.put("metadata", metadata);
dataModel.put("className", className);
dataModel.put("dataServiceUri", this.serviceRef.getTargetRef());
dataModel.put("entityContainer", entityContainer);
TemplateRepresentation templateRepresentation = new TemplateRepresentation(
serviceTmpl, fmc, dataModel, MediaType.TEXT_PLAIN);
templateRepresentation.setCharacterSet(CharacterSet.UTF_8);
// Write the template representation as a Java class
templateRepresentation.write(new FileOutputStream(new File(
outputDir, className + ".java")));
}
}
}