List<URL> urls = new ArrayList<URL>();
for (EJB21Deployable ejb21Deployable : ejbs) {
try {
urls.add(ejb21Deployable.getArchive().getURL());
} catch (ArchiveException e) {
throw new DeployerException("Cannot get the URL for the archive '" + ejb21Deployable.getArchive()
+ "'", e);
}
}
// Get classpath of the EJBs
URL[] compilationURLs = null;
// content of the ear loader (application wide resources)
URL[] myApplicationJars = earClassLoader.getURLs();
// content of the apps loader (system wide resources)
URL[] appsJars = ((URLClassLoader) earClassLoader.getParent()).getURLs();
// merge the 3 Set of URLs
compilationURLs = new URL[myApplicationJars.length + appsJars.length + urls.size()];
System.arraycopy(urls.toArray(new URL[urls.size()]), 0, compilationURLs, 0, urls.size());
System.arraycopy(appsJars, 0, compilationURLs, urls.size(), appsJars.length);
System.arraycopy(myApplicationJars, 0, compilationURLs, urls.size() + appsJars.length, myApplicationJars.length);
// Call automatic GenIC on the URLs of the EJB 2.1
if (this.checkGenICMethod != null) {
for (EJB21Deployable ejb : ejbs) {
URL ejbURL = null;
try {
ejbURL = ejb.getArchive().getURL();
} catch (ArchiveException e) {
throw new DeployerException("Cannot get the URL on the deployable '" + ejb + "'", e);
}
logger.debug("Calling GenIC on the EJB ''{0}'' with compilation URL ''{1}''.", ejbURL, Arrays
.asList(compilationURLs));
invoke(this.checkGenICMethod, this.ejb21Service, ejbURL.getFile(), compilationURLs);
}
}
// Deploy EJB 2.1 on JOnAS service
Context ctx = new ContextImpl(earURL.toExternalForm());
try {
ctx.rebind("earUrl", earURL);
ctx.rebind("earRootUrl", earURL);
} catch (NamingException e) {
throw new DeployerException("Cannot add the EAR URL parameter '" + earURL + "'", e);
}
try {
ctx.rebind("jarURLs", urls.toArray(new URL[urls.size()]));
} catch (NamingException e) {
throw new DeployerException("Cannot add the urls parameter '" + urls + "'", e);
}
try {
ctx.rebind("earClassLoader", earClassLoader);
} catch (NamingException e) {
throw new DeployerException("Cannot add the earClassLoader parameter '" + earClassLoader + "'", e);
}
// Bind the EJB classloader
try {
ctx.rebind("ejbClassLoader", ejbClassLoader);
} catch (NamingException e) {
throw new DeployerException("Cannot add the ejbClassLoader parameter '" + ejbClassLoader + "'", e);
}
// Role names
try {
ctx.rebind("roleNames", new String[0]);
} catch (NamingException e) {
throw new DeployerException("Cannot add the altDDs parameter.'", e);
}
try {
this.deployMethodejb21Service.invoke(this.ejb21Service, ctx);
} catch (IllegalArgumentException e) {
throw new DeployerException("Cannot deploy the EJB 2.1'", e);
} catch (IllegalAccessException e) {
throw new DeployerException("Cannot deploy the EJB 2.1'", e);
} catch (InvocationTargetException e) {
throw new DeployerException("Cannot deploy the EJB 2.1'", e.getTargetException());
}
}
}
}