@Override
public void doFreemarkerGenerate() throws IOException, TemplateException {
File genDir = getGenerateDir();
if (!isUpToDate(genDir)) {
EnunciateFreemarkerModel model = getModel();
model.put("Introspector", BeansWrapper.getDefaultInstance().getStaticModels().get("java.beans.Introspector"));
Map<String, WsdlInfo> ns2wsdl = model.getNamespacesToWSDLs();
URL requestBeanTemplate = JAXWSSupportDeploymentModule.class.getResource("request-bean.fmt");
URL responseBeanTemplate = JAXWSSupportDeploymentModule.class.getResource("response-bean.fmt");
URL faultBeanTemplate = JAXWSSupportDeploymentModule.class.getResource("fault-bean.fmt");
TreeSet<WebFault> visitedFaults = new TreeSet<WebFault>(new TypeDeclarationComparator());
for (WsdlInfo wsdlInfo : ns2wsdl.values()) {
for (EndpointInterface ei : wsdlInfo.getEndpointInterfaces()) {
for (WebMethod webMethod : ei.getWebMethods()) {
for (WebMessage webMessage : webMethod.getMessages()) {
if (webMessage instanceof RequestWrapper) {
model.put("message", webMessage);
processTemplate(requestBeanTemplate, model);
}
else if (webMessage instanceof ResponseWrapper) {
model.put("message", webMessage);
processTemplate(responseBeanTemplate, model);
}
else if ((webMessage instanceof WebFault) && ((WebFault) webMessage).isImplicitSchemaElement() && visitedFaults.add((WebFault) webMessage)) {
model.put("message", webMessage);
processTemplate(faultBeanTemplate, model);
}
}
}
}
}
//we're going to process the JAX-RS thrown types annotated with @WebFault in case we ever want to serialize the fault beans as XML...
for (RootResource rootResource : model.getRootResources()) {
for (ResourceMethod resourceMethod : rootResource.getResourceMethods(true)) {
for (ReferenceType referenceType : resourceMethod.getThrownTypes()) {
if (!(referenceType instanceof DeclaredType)) {
throw new ValidationException(resourceMethod.getPosition(), "Method " + resourceMethod + " of " + resourceMethod.getParent().getQualifiedName() + ": thrown type must be a declared type.");
}
TypeDeclaration declaration = ((DeclaredType) referenceType).getDeclaration();
if (declaration == null) {
throw new ValidationException(resourceMethod.getPosition(), "Method " + resourceMethod + " of " + resourceMethod.getParent().getQualifiedName() + ": unknown declaration for " + referenceType);
}
else if (declaration.getAnnotation(javax.xml.ws.WebFault.class) != null) {
WebFault fault = new WebFault((ClassDeclaration) declaration);
if (fault.isImplicitSchemaElement() && visitedFaults.add(fault)) {
model.put("message", fault);
processTemplate(faultBeanTemplate, model);
}
}
}
}