// get all of the ejb deployments
List<DeploymentInfo> deployments = new ArrayList<DeploymentInfo>();
for (EjbJarInfo ejbJarInfo : appInfo.ejbJars) {
for (EnterpriseBeanInfo beanInfo : ejbJarInfo.enterpriseBeans) {
String deploymentId = beanInfo.ejbDeploymentId;
CoreDeploymentInfo deployment = (CoreDeploymentInfo) containerSystem.getDeploymentInfo(deploymentId);
if (deployment == null) {
undeployException.getCauses().add(new Exception("deployment not found: " + deploymentId));
} else {
deployments.add(deployment);
}
}
}
// Just as with startup we need to get things in an
// order that respects the singleton @DependsOn information
// Theoreticlly if a Singleton depends on something in its
// @PostConstruct, it can depend on it in its @PreDestroy.
// Therefore we want to make sure that if A dependsOn B,
// that we destroy A first then B so that B will still be
// usable in the @PreDestroy method of A.
// Sort them into the original starting order
deployments = sort(deployments);
// reverse that to get the stopping order
Collections.reverse(deployments);
for (DeploymentInfo deployment : deployments) {
String deploymentID = deployment.getDeploymentID() + "";
try {
Container container = deployment.getContainer();
container.undeploy(deployment);
deployment.setContainer(null);
} catch (Throwable t) {
undeployException.getCauses().add(new Exception("bean: " + deploymentID + ": " + t.getMessage(), t));
} finally {
((CoreDeploymentInfo)deployment).setDestroyed(true);
}
}
// get the client ids
List<String> clientIds = new ArrayList<String>();
for (ClientInfo clientInfo : appInfo.clients) {
clientIds.add(clientInfo.moduleId);
for (String className : clientInfo.localClients) {
clientIds.add(className);
}
for (String className : clientInfo.remoteClients) {
clientIds.add(className);
}
}
// Clear out naming for all components first
for (DeploymentInfo deployment : deployments) {
String deploymentID = deployment.getDeploymentID() + "";
try {
containerSystem.removeDeploymentInfo(deployment);
} catch (Throwable t) {
undeployException.getCauses().add(new Exception(deploymentID, t));
}
JndiBuilder.Bindings bindings = deployment.get(JndiBuilder.Bindings.class);
if (bindings != null) for (String name : bindings.getBindings()) {
try {
globalContext.unbind(name);
} catch (Throwable t) {
undeployException.getCauses().add(new Exception("bean: " + deploymentID + ": " + t.getMessage(), t));