URL jsonComplexTypeTemplate = getTemplateURL("json-complex-type.fmt");
URL jsonSimpleTypeTemplate = getTemplateURL("json-simple-type.fmt");
URL jsonEnumTypeTemplate = getTemplateURL("json-enum-type.fmt");
EnunciateFreemarkerModel model = getModel();
Map<String, String> conversions = getClientPackageConversions();
ClientClassnameForMethod classnameFor = new ClientClassnameForMethod(conversions);
classnameFor.setJdk15(true);
model.put("packageFor", new ClientPackageForMethod(conversions));
model.put("classnameFor", classnameFor);
model.put("simpleNameFor", new SimpleNameWithParamsMethod(classnameFor));
debug("Generating the Java client classes...");
model.setFileOutputDirectory(getClientGenerateDir());
HashMap<String, WebFault> allFaults = new HashMap<String, WebFault>();
Set<String> seeAlsos = new TreeSet<String>();
// Process the annotations, the request/response beans, and gather the set of web faults
// for each endpoint interface.
for (WsdlInfo wsdlInfo : model.getNamespacesToWSDLs().values()) {
for (EndpointInterface ei : wsdlInfo.getEndpointInterfaces()) {
if (FacetFilter.accept(ei)) {
for (WebMethod webMethod : ei.getWebMethods()) {
if (FacetFilter.accept(webMethod)) {
for (WebMessage webMessage : webMethod.getMessages()) {
if (webMessage instanceof RequestWrapper) {
model.put("message", webMessage);
processTemplate(requestBeanTemplate, model);
seeAlsos.add(getBeanName(classnameFor, ((RequestWrapper) webMessage).getRequestBeanName()));
}
else if (webMessage instanceof ResponseWrapper) {
model.put("message", webMessage);
processTemplate(responseBeanTemplate, model);
seeAlsos.add(getBeanName(classnameFor, ((ResponseWrapper) webMessage).getResponseBeanName()));
}
else if (webMessage instanceof WebFault) {
WebFault fault = (WebFault) webMessage;
allFaults.put(fault.getQualifiedName(), fault);
}
}
}
}
}
}
}
//gather the annotation information and process the possible beans for each web fault.
for (WebFault webFault : allFaults.values()) {
boolean implicit = webFault.isImplicitSchemaElement();
String faultBean = implicit ? getBeanName(classnameFor, webFault.getImplicitFaultBeanQualifiedName()) : classnameFor.convert(webFault.getExplicitFaultBeanType());
seeAlsos.add(faultBean);
if (implicit) {
model.put("fault", webFault);
processTemplate(faultBeanTemplate, model);
}
}
model.put("seeAlsoBeans", seeAlsos);
for (WsdlInfo wsdlInfo : model.getNamespacesToWSDLs().values()) {
if (wsdlInfo.getProperty("filename") == null) {
throw new EnunciateException("WSDL " + wsdlInfo.getId() + " doesn't have a filename.");
}
model.put("wsdlFileName", wsdlInfo.getProperty("filename"));
for (EndpointInterface ei : wsdlInfo.getEndpointInterfaces()) {
if (FacetFilter.accept(ei)) {
model.put("endpointInterface", ei);
processTemplate(eiTemplate, model);
processTemplate(soapImplTemplate, model);
}
}
}
AntPatternMatcher matcher = new AntPatternMatcher();
matcher.setPathSeparator(".");
for (WebFault webFault : allFaults.values()) {
if (useServerSide(webFault, matcher)) {
SourcePosition position = webFault.getPosition();
if (position == null || position.file() == null) {
throw new IllegalStateException("Unable to find source file for " + webFault.getQualifiedName());
}
File sourceFile = position.file();
getEnunciate().copyFile(sourceFile, getServerSideDestFile(sourceFile, webFault));
}
else {
ClassDeclaration superFault = webFault.getSuperclass().getDeclaration();
if (superFault != null && allFaults.containsKey(superFault.getQualifiedName()) && allFaults.get(superFault.getQualifiedName()).isImplicitSchemaElement()) {
model.put("superFault", allFaults.get(superFault.getQualifiedName()));
}
else {
model.remove("superFault");
}
model.put("fault", webFault);
processTemplate(faultTemplate, model);
}
}
final Set<String> uniquePackages = new TreeSet<String>();
for (SchemaInfo schemaInfo : model.getNamespacesToSchemas().values()) {
for (TypeDefinition typeDefinition : schemaInfo.getTypeDefinitions()) {
if (FacetFilter.accept(typeDefinition)) {
if (useServerSide(typeDefinition, matcher)) {
SourcePosition position = typeDefinition.getPosition();
if (position == null || position.file() == null) {
throw new IllegalStateException("Unable to find source file for " + typeDefinition.getQualifiedName());
}
File sourceFile = position.file();
getEnunciate().copyFile(sourceFile, getServerSideDestFile(sourceFile, typeDefinition));
}
else {
model.put("rootEl", model.findRootElementDeclaration(typeDefinition));
model.put("type", typeDefinition);
URL template = typeDefinition.isEnum() ? typeDefinition instanceof QNameEnumTypeDefinition ? qnameEnumTypeTemplate : enumTypeTemplate : typeDefinition.isSimple() ? simpleTypeTemplate : complexTypeTemplate;
processTemplate(template, model);
}
if (typeDefinition.getPackage() != null) {
uniquePackages.add(typeDefinition.getPackage().getQualifiedName());
}
}
}
for (Registry registry : schemaInfo.getRegistries()) {
model.put("registry", registry);
processTemplate(registryTemplate, model);
}
}
boolean generateJsonJar = isGenerateJsonJar();
model.put("generateJson", generateJsonJar);
if (generateJsonJar) {
//first set up the json client package conversions.
Map<String, String> jsonConversions = getJsonPackageConversions(uniquePackages);
model.setFileOutputDirectory(getJsonClientGenerateDir());
ClientClassnameForMethod jsonClassnameFor = new ClientClassnameForMethod(jsonConversions);
jsonClassnameFor.setJdk15(true);
model.put("packageFor", new ClientPackageForMethod(jsonConversions));
model.put("classnameFor", jsonClassnameFor);
model.put("simpleNameFor", new SimpleNameWithParamsMethod(jsonClassnameFor));
debug("Generating the Java JSON client classes...");
for (SchemaInfo schemaInfo : model.getNamespacesToSchemas().values()) {
for (TypeDefinition typeDefinition : schemaInfo.getTypeDefinitions()) {
if (FacetFilter.accept(typeDefinition)) {
model.put("type", typeDefinition);
URL template = typeDefinition.isEnum() ? jsonEnumTypeTemplate : typeDefinition.isSimple() ? jsonSimpleTypeTemplate : jsonComplexTypeTemplate;
processTemplate(template, model);
}
}
}