URL typeTemplate = getTemplateURL("gwt-type.fmt");
URL overlayTypeTemplate = getTemplateURL("gwt-overlay-type.fmt");
URL enumTypeTemplate = getTemplateURL("gwt-enum-15-type.fmt");
URL overlayEnumTypeTemplate = getTemplateURL("gwt-enum-overlay-type.fmt");
EnunciateFreemarkerModel model = getModel();
model.put("useSpringDI", this.springDIFound);
model.put("useWrappedServices", this.isUseWrappedServices());
Map<String, String> conversions = new LinkedHashMap<String, String>();
Set<String> knownGwtPackages = this.gwtClasspathHandler != null ? this.gwtClasspathHandler.getSourcePackagesToModules().keySet() : Collections.<String>emptySet();
for (String knownGwtPackage : knownGwtPackages) {
//makes sure any known gwt packages are preserved.
conversions.put(knownGwtPackage, knownGwtPackage);
}
Map<String, String> overlayConversions = new HashMap<String, String>();
String clientNamespace = this.rpcModuleNamespace + ".client";
conversions.put(this.rpcModuleNamespace, clientNamespace);
overlayConversions.put(this.rpcModuleNamespace, clientNamespace + ".json");
if (!this.enforceNamespaceConformance) {
TreeSet<WebFault> allFaults = new TreeSet<WebFault>(new TypeDeclarationComparator());
for (WsdlInfo wsdlInfo : model.getNamespacesToWSDLs().values()) {
for (EndpointInterface ei : wsdlInfo.getEndpointInterfaces()) {
if (!isFacetExcluded(ei)) {
String pckg = ei.getPackage().getQualifiedName();
if (!pckg.startsWith(this.rpcModuleNamespace) && !conversions.containsKey(pckg)) {
conversions.put(pckg, clientNamespace + "." + pckg);
}
for (WebMethod webMethod : ei.getWebMethods()) {
for (WebFault webFault : webMethod.getWebFaults()) {
allFaults.add(webFault);
}
}
}
}
}
for (WebFault webFault : allFaults) {
if (!isFacetExcluded(webFault)) {
String pckg = webFault.getPackage().getQualifiedName();
if (!pckg.startsWith(this.rpcModuleNamespace) && !conversions.containsKey(pckg) && (getKnownGwtModule(webFault) == null)) {
conversions.put(pckg, clientNamespace + "." + pckg);
}
}
}
for (SchemaInfo schemaInfo : model.getNamespacesToSchemas().values()) {
for (TypeDefinition typeDefinition : schemaInfo.getTypeDefinitions()) {
if (!isFacetExcluded(typeDefinition)) {
String pckg = typeDefinition.getPackage().getQualifiedName();
if (!pckg.startsWith(this.rpcModuleNamespace) && !conversions.containsKey(pckg)) {
if (getKnownGwtModule(typeDefinition) == null) {
conversions.put(pckg, clientNamespace + "." + pckg);
}
overlayConversions.put(pckg, clientNamespace + ".json." + pckg);
}
}
}
}
}
ClientClassnameForMethod classnameFor = new ClientClassnameForMethod(conversions);
classnameFor.setJdk15(true);
OverlayClientClassnameForMethod overlayClassnameFor = new OverlayClientClassnameForMethod(overlayConversions);
overlayClassnameFor.setJdk15(true);
model.put("packageFor", new ClientPackageForMethod(conversions));
model.put("overlayPackageFor", new ClientPackageForMethod(overlayConversions));
model.put("isAccessorOfTypeLong", new IsAccessorOfTypeLongMethod());
model.put("classnameFor", classnameFor);
model.put("overlayClassnameFor", overlayClassnameFor);
model.put("simpleNameFor", new SimpleNameWithParamsMethod(classnameFor));
model.put("overlaySimpleNameFor", new SimpleNameWithParamsMethod(overlayClassnameFor));
model.put("gwtSubcontext", getGwtSubcontext());
model.put("accessorOverridesAnother", new AccessorOverridesAnotherMethod());
model.setFileOutputDirectory(clientSideGenerateDir);
Properties gwt2jaxbMappings = new Properties();
TreeSet<WebFault> allFaults = new TreeSet<WebFault>(new TypeDeclarationComparator());
Set<String> importedModules = new TreeSet<String>();
if (isGenerateRPCSupport()) {
debug("Generating the GWT endpoints...");
for (WsdlInfo wsdlInfo : model.getNamespacesToWSDLs().values()) {
for (EndpointInterface ei : wsdlInfo.getEndpointInterfaces()) {
if (!isFacetExcluded(ei)) {
model.put("endpointInterface", ei);
processTemplate(eiTemplate, model);
for (WebMethod webMethod : ei.getWebMethods()) {
for (WebFault webFault : webMethod.getWebFaults()) {
allFaults.add(webFault);
}
}
}
}
}
debug("Generating the GWT faults...");
for (WebFault webFault : allFaults) {
if (!isFacetExcluded(webFault)) {
String knownGwtModule = getKnownGwtModule(webFault);
if (knownGwtModule == null) {
model.put("fault", webFault);
processTemplate(faultTemplate, model);
}
else {
importedModules.add(knownGwtModule);
debug("Skipping generating fault for %s because it's in a known GWT module.", webFault.getQualifiedName());
}
}
}
debug("Generating the GWT types...");
for (SchemaInfo schemaInfo : model.getNamespacesToSchemas().values()) {
for (TypeDefinition typeDefinition : schemaInfo.getTypeDefinitions()) {
if (!isFacetExcluded(typeDefinition)) {
String knownGwtModule = getKnownGwtModule(typeDefinition);
if (knownGwtModule == null) {
model.put("type", typeDefinition);
URL template = typeDefinition.isEnum() ? enumTypeTemplate : typeTemplate;
processTemplate(template, model);
}
else {
importedModules.add(knownGwtModule);
debug("Skipping generating GWT type for %s because it's in a known GWT module.", typeDefinition.getQualifiedName());
}
}
}
}
}
if (isGenerateJsonOverlays()) {
debug("Generating the GWT json overlay types...");
for (SchemaInfo schemaInfo : model.getNamespacesToSchemas().values()) {
for (TypeDefinition typeDefinition : schemaInfo.getTypeDefinitions()) {
if (!isFacetExcluded(typeDefinition)) {
model.put("type", typeDefinition);
URL template = typeDefinition.isEnum() ? overlayEnumTypeTemplate : overlayTypeTemplate;
processTemplate(template, model);
}
}
}
}
model.put("gwtModuleName", this.rpcModuleName);
model.put("importedGwtModules", importedModules);
processTemplate(moduleXmlTemplate, model);
model.setFileOutputDirectory(serverSideGenerateDir);
if (isGenerateRPCSupport()) {
debug("Generating the GWT endpoint implementations...");
for (WsdlInfo wsdlInfo : model.getNamespacesToWSDLs().values()) {
for (EndpointInterface ei : wsdlInfo.getEndpointInterfaces()) {
if (!isFacetExcluded(ei)) {
model.put("endpointInterface", ei);
processTemplate(endpointImplTemplate, model);
}
}
}
debug("Generating the GWT type mappers...");
for (SchemaInfo schemaInfo : model.getNamespacesToSchemas().values()) {
for (TypeDefinition typeDefinition : schemaInfo.getTypeDefinitions()) {
if (!isFacetExcluded(typeDefinition)) {
if (typeDefinition.isEnum()) {
model.put("type", typeDefinition);
processTemplate(enumTypeMapperTemplate, model);
gwt2jaxbMappings.setProperty(classnameFor.convert(typeDefinition), typeDefinition.getQualifiedName());
}
else if (getKnownGwtModule(typeDefinition) == null) {
if (!typeDefinition.isEnum()) {
model.put("type", typeDefinition);
processTemplate(typeMapperTemplate, model);
gwt2jaxbMappings.setProperty(classnameFor.convert(typeDefinition), typeDefinition.getQualifiedName());
}
}
else {
debug("Skipping generation of type mapper for %s because it's a known GWT type.", typeDefinition.getQualifiedName());
}
}
}
}
debug("Generating the GWT fault mappers...");
for (WebFault webFault : allFaults) {
if (!isFacetExcluded(webFault) && (getKnownGwtModule(webFault) == null)) {
model.put("fault", webFault);
processTemplate(faultMapperTemplate, model);
gwt2jaxbMappings.setProperty(classnameFor.convert(webFault), webFault.getQualifiedName());
}
}