public ClientService getClientService() throws ClientServicesException {
// If the client service class is defined, then we instanciate it
String cls = getClientServiceClass();
if(StringUtil.isNotEmpty(cls)) {
try {
ClientService clientService = null;
// order of precedence for the classloader to use
Context ctx = Context.getUnchecked();
Application app = Application.getUnchecked();
ClassLoader cl = Thread.currentThread().getContextClassLoader();
if (ctx!=null) {
clientService = (ClientService)ctx.getClassLoader().loadClass(cls).newInstance();
} else if(app!=null) {
clientService = (ClientService)app.getClassLoader().loadClass(cls).newInstance();
} else if(cl!=null) {
clientService = (ClientService)cl.loadClass(cls).newInstance();
} else {
clientService = (ClientService)Class.forName(cls).newInstance();
}
// set endpoint
clientService.setEndpoint(this);
return clientService;
} catch(Exception ex) {
throw new ClientServicesException(ex,"Cannot create ClientService class {0}",cls);
}