//load the references to the templates....
URL amfEndpointTemplate = getTemplateURL("amf-endpoint.fmt");
URL amfTypeTemplate = getTemplateURL("amf-type.fmt");
URL amfTypeMapperTemplate = getTemplateURL("amf-type-mapper.fmt");
EnunciateFreemarkerModel model = getModel();
model.setFileOutputDirectory(serverGenerateDir);
model.put("useSpringDI", this.springDIFound);
TreeMap<String, String> packages = new TreeMap<String, String>(new Comparator<String>() {
public int compare(String package1, String package2) {
int comparison = package1.length() - package2.length();
if (comparison == 0) {
return package1.compareTo(package2);
}
return comparison;
}
});
for (SchemaInfo schemaInfo : model.getNamespacesToSchemas().values()) {
for (TypeDefinition typeDefinition : schemaInfo.getTypeDefinitions()) {
if (!isFacetExcluded(typeDefinition)) {
String packageName = typeDefinition.getPackage().getQualifiedName();
packages.put(packageName, packageName + ".amf");
}
}
}
debug("Generating the AMF externalizable types and their associated mappers...");
AMFClassnameForMethod amfClassnameForMethod = new AMFClassnameForMethod(packages);
model.put("simpleNameFor", new SimpleNameWithParamsMethod(amfClassnameForMethod));
model.put("classnameFor", amfClassnameForMethod);
for (SchemaInfo schemaInfo : model.getNamespacesToSchemas().values()) {
for (TypeDefinition typeDefinition : schemaInfo.getTypeDefinitions()) {
if (!isFacetExcluded(typeDefinition)) {
model.put("type", typeDefinition);
processTemplate(amfTypeTemplate, model);
processTemplate(amfTypeMapperTemplate, model);
}
}
}
debug("Generating the AMF endpoint beans...");
for (WsdlInfo wsdlInfo : model.getNamespacesToWSDLs().values()) {
for (EndpointInterface ei : wsdlInfo.getEndpointInterfaces()) {
if (!isFacetExcluded(ei)) {
model.put("endpointInterface", ei);
processTemplate(amfEndpointTemplate, model);
}
}
}
URL endpointTemplate = getTemplateURL("as3-endpoint.fmt");
URL typeTemplate = getTemplateURL("as3-type.fmt");
URL enumTypeTemplate = getTemplateURL("as3-enum-type.fmt");
//build up the list of as3Aliases...
HashMap<String, String> as3Aliases = new HashMap<String, String>();
for (SchemaInfo schemaInfo : model.getNamespacesToSchemas().values()) {
for (TypeDefinition typeDefinition : schemaInfo.getTypeDefinitions()) {
if (!isFacetExcluded(typeDefinition)) {
as3Aliases.put(amfClassnameForMethod.convert(typeDefinition), typeDefinition.getClientSimpleName());
}
}
}
model.setFileOutputDirectory(clientGenerateDir);
HashMap<String, String> conversions = new HashMap<String, String>();
//todo: accept client-side package mappings?
ClientPackageForMethod as3PackageFor = new ClientPackageForMethod(conversions);
as3PackageFor.setUseClientNameConversions(true);
model.put("packageFor", as3PackageFor);
AS3UnqualifiedClassnameForMethod as3ClassnameFor = new AS3UnqualifiedClassnameForMethod(conversions);
as3ClassnameFor.setUseClientNameConversions(true);
model.put("classnameFor", as3ClassnameFor);
model.put("simpleNameFor", new SimpleNameWithParamsMethod(as3ClassnameFor));
ComponentTypeForMethod as3ComponentTypeFor = new ComponentTypeForMethod(conversions);
as3ComponentTypeFor.setUseClientNameConversions(true);
model.put("componentTypeFor", as3ComponentTypeFor);
model.put("amfClassnameFor", amfClassnameForMethod);
model.put("amfComponentTypeFor", new ComponentTypeForMethod(packages));
model.put("forEachAS3Import", new ForEachAS3ImportTransform(null, as3ClassnameFor));
model.put("accessorOverridesAnother", new AccessorOverridesAnotherMethod());
model.put("as3Aliases", as3Aliases);
debug("Generating the ActionScript types...");
for (SchemaInfo schemaInfo : model.getNamespacesToSchemas().values()) {
for (TypeDefinition typeDefinition : schemaInfo.getTypeDefinitions()) {
if (!isFacetExcluded(typeDefinition)) {
model.put("type", typeDefinition);
URL template = typeDefinition.isEnum() ? enumTypeTemplate : typeTemplate;
processTemplate(template, model);
}
}
}
for (WsdlInfo wsdlInfo : model.getNamespacesToWSDLs().values()) {
for (EndpointInterface ei : wsdlInfo.getEndpointInterfaces()) {
if (!isFacetExcluded(ei)) {
model.put("endpointInterface", ei);
processTemplate(endpointTemplate, model);
}
}
}
File servicesConfigXML = new File(xmlGenerateDir, "services-config.xml");
URL servicesConfigTemplate = getTemplateURL("services-config-xml.fmt");
model.setFileOutputDirectory(xmlGenerateDir);
debug("Generating the configuration files.");
processTemplate(servicesConfigTemplate, model);
File mergeTarget = new File(xmlGenerateDir, "merged-services-config.xml");
if (this.mergeServicesConfigXML != null) {
URL servicesConfigXmlToMerge = enunciate.resolvePath(this.mergeServicesConfigXML).toURL();
try {
model.put("source1", loadMergeXmlModel(servicesConfigXmlToMerge.openStream()));
model.put("source2", loadMergeXmlModel(new FileInputStream(servicesConfigXML)));
processTemplate(getMergeServicesConfigXmlTemplateURL(), model);
}
catch (TemplateException e) {
throw new EnunciateException("Error while merging services-config xml files.", e);
}