if (donotOverride && GeneratorUtil.classExists(options, className)) {
log("Class " + className + " exists. Not overriding.");
return;
}
JDefinedClass cls;
try {
cls = getClass(className, ClassType.CLASS);
} catch (JClassAlreadyExistsException e) {
receiver.error(service.getLocator(), GeneratorMessages.GENERATOR_SERVICE_CLASS_ALREADY_EXIST(className, service.getName()));
return;
}
cls._extends(javax.xml.ws.Service.class);
String serviceFieldName = JAXBRIContext.mangleNameToClassName(service.getName().getLocalPart()).toUpperCase();
String wsdlLocationName = serviceFieldName + "_WSDL_LOCATION";
JFieldVar urlField = cls.field(JMod.PRIVATE | JMod.STATIC | JMod.FINAL, URL.class, wsdlLocationName);
JFieldVar exField = cls.field(JMod.PRIVATE | JMod.STATIC | JMod.FINAL, WebServiceException.class, serviceFieldName+"_EXCEPTION");
String serviceName = serviceFieldName + "_QNAME";
cls.field(JMod.PRIVATE | JMod.STATIC | JMod.FINAL, QName.class, serviceName,
JExpr._new(cm.ref(QName.class)).arg(service.getName().getNamespaceURI()).arg(service.getName().getLocalPart()));
JClass qNameCls = cm.ref(QName.class);
JInvocation inv;
inv = JExpr._new(qNameCls);
inv.arg("namespace");
inv.arg("localpart");
if (wsdlLocation.startsWith("http://") || wsdlLocation.startsWith("https://") || wsdlLocation.startsWith("file:/")) {
writeAbsWSDLLocation(cls, urlField, exField);
} else if (wsdlLocation.startsWith("META-INF/")) {
writeClassLoaderResourceWSDLLocation(className, cls, urlField, exField);
} else {
writeResourceWSDLLocation(className, cls, urlField, exField);
}
//write class comment - JAXWS warning
JDocComment comment = cls.javadoc();
if (service.getJavaDoc() != null) {
comment.add(service.getJavaDoc());
comment.add("\n\n");
}
for (String doc : getJAXWSClassComment()) {
comment.add(doc);
}
// Generating constructor
// for e.g: public ExampleService()
JMethod constructor1 = cls.constructor(JMod.PUBLIC);
String constructor1Str = String.format("super(__getWsdlLocation(), %s);", serviceName);
constructor1.body().directStatement(constructor1Str);
// Generating constructor
// for e.g: public ExampleService(WebServiceFeature ... features)
if (options.target.isLaterThan(Options.Target.V2_2)) {
JMethod constructor2 = cls.constructor(JMod.PUBLIC);
constructor2.varParam(WebServiceFeature.class, "features");
String constructor2Str = String.format("super(__getWsdlLocation(), %s, features);", serviceName);
constructor2.body().directStatement(constructor2Str);
}
// Generating constructor
// for e.g: public ExampleService(URL wsdlLocation)
if (options.target.isLaterThan(Options.Target.V2_2)) {
JMethod constructor3 = cls.constructor(JMod.PUBLIC);
constructor3.param(URL.class, "wsdlLocation");
String constructor3Str = String.format("super(wsdlLocation, %s);", serviceName);
constructor3.body().directStatement(constructor3Str);
}
// Generating constructor
// for e.g: public ExampleService(URL wsdlLocation, WebServiceFeature ... features)
if (options.target.isLaterThan(Options.Target.V2_2)) {
JMethod constructor4 = cls.constructor(JMod.PUBLIC);
constructor4.param(URL.class, "wsdlLocation");
constructor4.varParam(WebServiceFeature.class, "features");
String constructor4Str = String.format("super(wsdlLocation, %s, features);", serviceName);
constructor4.body().directStatement(constructor4Str);
}
// Generating constructor
// for e.g: public ExampleService(URL wsdlLocation, QName serviceName)
JMethod constructor5 = cls.constructor(JMod.PUBLIC);
constructor5.param(URL.class, "wsdlLocation");
constructor5.param(QName.class, "serviceName");
constructor5.body().directStatement("super(wsdlLocation, serviceName);");
// Generating constructor
// for e.g: public ExampleService(URL, QName, WebServiceFeature ...)
if (options.target.isLaterThan(Options.Target.V2_2)) {
JMethod constructor6 = cls.constructor(JMod.PUBLIC);
constructor6.param(URL.class, "wsdlLocation");
constructor6.param(QName.class, "serviceName");
constructor6.varParam(WebServiceFeature.class, "features");
constructor6.body().directStatement("super(wsdlLocation, serviceName, features);");
}
//@WebService
JAnnotationUse webServiceClientAnn = cls.annotate(cm.ref(WebServiceClient.class));
writeWebServiceClientAnnotation(service, webServiceClientAnn);
//@HandlerChain
writeHandlerConfig(Names.customJavaTypeClassName(service.getJavaInterface()), cls, options);