if (classLoader == null) {
classLoader = Thread.currentThread().getContextClassLoader();
}
URL u = composeUrl(wsdlUrl);
LOG.log(Level.FINE, "Creating client from URL " + u.toString());
ClientImpl client = new ClientImpl(bus, u, service, port,
getEndpointImplFactory());
Service svc = client.getEndpoint().getService();
//all SI's should have the same schemas
Collection<SchemaInfo> schemas = svc.getServiceInfos().get(0).getSchemas();
SchemaCompiler compiler;
try {
compiler = JAXBUtils.createSchemaCompiler();
} catch (JAXBException e1) {
throw new IllegalStateException("Unable to create schema compiler", e1);
}
Object elForRun = ReflectionInvokationHandler
.createProxyWrapper(new InnerErrorListener(wsdlUrl),
JAXBUtils.getParamClass(compiler, "setErrorListener"));
compiler.setErrorListener(elForRun);
Object allocator = ReflectionInvokationHandler
.createProxyWrapper(new ClassNameAllocatorImpl(),
JAXBUtils.getParamClass(compiler, "setClassNameAllocator"));
compiler.setClassNameAllocator(allocator);
addSchemas(wsdlUrl, schemas, compiler);
addBindingFiles(bindingFiles, compiler);
S2JJAXBModel intermediateModel = compiler.bind();
JCodeModel codeModel = intermediateModel.generateCode(null, elForRun);
StringBuilder sb = new StringBuilder();
boolean firstnt = false;
for (Iterator<JPackage> packages = codeModel.packages(); packages.hasNext();) {
JPackage jpackage = packages.next();
if (!isValidPackage(jpackage)) {
continue;
}
if (firstnt) {
sb.append(':');
} else {
firstnt = true;
}
sb.append(jpackage.name());
}
outputDebug(codeModel);
String packageList = sb.toString();
// our hashcode + timestamp ought to be enough.
String stem = toString() + "-" + System.currentTimeMillis();
File src = new File(tmpdir, stem + "-src");
if (!src.mkdir()) {
throw new IllegalStateException("Unable to create working directory " + src.getPath());
}
try {
Object writer = JAXBUtils.createFileCodeWriter(src);
codeModel.build(writer);
} catch (Exception e) {
throw new IllegalStateException("Unable to write generated Java files for schemas: "
+ e.getMessage(), e);
}
File classes = new File(tmpdir, stem + "-classes");
if (!classes.mkdir()) {
throw new IllegalStateException("Unable to create working directory " + classes.getPath());
}
StringBuilder classPath = new StringBuilder();
try {
setupClasspath(classPath, classLoader);
} catch (Exception ex) {
throw new RuntimeException(ex);
}
List<File> srcFiles = FileUtils.getFilesRecurse(src, ".+\\.java$");
if (!compileJavaSrc(classPath.toString(), srcFiles, classes.toString())) {
LOG.log(Level.SEVERE , new Message("COULD_NOT_COMPILE_SRC", LOG, wsdlUrl).toString());
}
FileUtils.removeDir(src);
URLClassLoader cl;
try {
cl = new URLClassLoader(new URL[] {classes.toURI().toURL()}, classLoader);
} catch (MalformedURLException mue) {
throw new IllegalStateException("Internal error; a directory returns a malformed URL: "
+ mue.getMessage(), mue);
}
JAXBContext context;
Map<String, Object> contextProperties = jaxbContextProperties;
if (contextProperties == null) {
contextProperties = Collections.emptyMap();
}
try {
if (StringUtils.isEmpty(packageList)) {
context = JAXBContext.newInstance(new Class[0], contextProperties);
} else {
context = JAXBContext.newInstance(packageList, cl, contextProperties);
}
} catch (JAXBException jbe) {
throw new IllegalStateException("Unable to create JAXBContext for generated packages: "
+ jbe.getMessage(), jbe);
}
JAXBDataBinding databinding = new JAXBDataBinding();
databinding.setContext(context);
svc.setDataBinding(databinding);
ServiceInfo svcfo = client.getEndpoint().getEndpointInfo().getService();
// Setup the new classloader!
Thread.currentThread().setContextClassLoader(cl);
TypeClassInitializer visitor = new TypeClassInitializer(svcfo,