JDefinedClass servCls = model._class(portName);
servCls._extends(javax.xml.ws.Service.class);
String wsdlUrl = context.getWsdlLocation();
JAnnotationUse clientAnn = servCls.annotate(WebServiceClient.class);
clientAnn.param("targetNamespace", ns);
clientAnn.param("name", name);
clientAnn.param("wsdlLocation", wsdlUrl);
JType qnameType = model._ref(QName.class);
/**
* Constructor
*/
JMethod constructor = servCls.constructor(JMod.PUBLIC);
constructor._throws(MalformedURLException.class);
JType urlType = model._ref(URL.class);
JInvocation newURL = JExpr._new(urlType).arg(wsdlUrl);
JInvocation newSN = JExpr._new(qnameType).arg(ns).arg(name);
JInvocation superService = JExpr.invoke("super").arg(newURL).arg(newSN);
constructor.body().add(superService);
boolean addedLocal = false;
JBlock staticBlock = servCls.init();
JType hashMapType = model._ref(HashMap.class);
JType mapType = model._ref(Map.class);
JVar portsVar = servCls.field(JMod.PRIVATE + JMod.STATIC,
mapType, "ports", JExpr._new(hashMapType));
JMethod method = servCls.method(JMod.PUBLIC + JMod.STATIC, mapType, "getPortClassMap");
method.body()._return(JExpr.ref("ports"));
for (Service service : services)
{
JClass serviceIntf = (JClass) service.getProperty(ServiceInterfaceGenerator.SERVICE_INTERFACE);
JFieldVar intfClass = servCls.field(JMod.STATIC + JMod.PUBLIC,
Class.class,
javify(serviceIntf.name()),
JExpr.dotclass(serviceIntf));
// hack to get local support
if (!addedLocal)
{
Soap11Binding localBind = new Soap11Binding(new QName(ns, name + "LocalBinding"),
LocalTransport.BINDING_ID,
service);
service.addBinding(localBind);
service.addEndpoint(new QName(ns, name + "LocalPort"), localBind, "xfire.local://" + name);
addedLocal = true;
}
for (Iterator itr = service.getEndpoints().iterator(); itr.hasNext();)
{
Endpoint endpoint = (Endpoint) itr.next();
JInvocation newQN = JExpr._new(qnameType);
newQN.arg(endpoint.getName().getNamespaceURI());
newQN.arg(endpoint.getName().getLocalPart());
JInvocation bindingQN = JExpr._new(qnameType);
bindingQN.arg(endpoint.getBinding().getName().getNamespaceURI());
bindingQN.arg(endpoint.getBinding().getName().getLocalPart());
// Add a getFooEndpointMethod
JMethod getFooEndpoint = servCls.method(JMod.PUBLIC, serviceIntf, javify("get" + endpoint.getName().getLocalPart()));
JBlock geBody = getFooEndpoint.body();
geBody._return(JExpr.cast(serviceIntf, JExpr.direct("this").invoke("getPort").arg(newQN).arg(intfClass)));
JAnnotationUse weAnn = getFooEndpoint.annotate(WebEndpoint.class);
weAnn.param("name", endpoint.getName().getLocalPart());
staticBlock.add(portsVar.invoke("put").arg(newQN).arg(intfClass));
}
}
}