class DebuggableVmHackery implements DynamicDeployer {
public AppModule deploy(AppModule appModule) throws OpenEJBException {
for (EjbModule ejbModule : appModule.getEjbModules()) {
EjbJar ejbJar = ejbModule.getEjbJar();
OpenejbJar openejbJar = ejbModule.getOpenejbJar();
Map<String, EjbDeployment> deployments = openejbJar.getDeploymentsByEjbName();
ejbJar.setRelationships(null);
List<String> removed = new ArrayList<String>();
for (EnterpriseBean bean : ejbJar.getEnterpriseBeans()) {
String ejbName = bean.getEjbName();
EjbDeployment ejbDeployment = deployments.get(ejbName);
pruneRefs(bean, ejbDeployment);
if (!(bean instanceof MessageDrivenBean) && !(bean instanceof EntityBean)) {
continue;
}
ejbJar.removeEnterpriseBean(ejbName);
openejbJar.removeEjbDeployment(ejbDeployment);
removed.add(ejbName);
AssemblyDescriptor assemblyDescriptor = ejbJar.getAssemblyDescriptor();
if (assemblyDescriptor != null){
for (MethodPermission permission : copy(assemblyDescriptor.getMethodPermission())) {
for (Method method : copy(permission.getMethod())) {
if (method.getEjbName().equals(ejbName)) {
permission.getMethod().remove(method);
}
}
if (permission.getMethod().size() == 0) {
assemblyDescriptor.getMethodPermission().remove(permission);
}
}
for (ContainerTransaction transaction : copy(assemblyDescriptor.getContainerTransaction())) {
for (Method method : copy(transaction.getMethod())) {
if (method.getEjbName().equals(ejbName)) {
transaction.getMethod().remove(method);
}
}
if (transaction.getMethod().size() == 0) {
assemblyDescriptor.getContainerTransaction().remove(transaction);
}
}
for (InterceptorBinding binding : copy(assemblyDescriptor.getInterceptorBinding())) {
if (binding.getEjbName().equals(ejbName)) {
assemblyDescriptor.getInterceptorBinding().remove(binding);
}
}
}
}
// Drop any ejb ref to with an ejb-link to a removed ejb
for (EnterpriseBean bean : ejbJar.getEnterpriseBeans()) {
bean.getEjbLocalRefMap().keySet().removeAll(removed);
bean.getEjbRefMap().keySet().removeAll(removed);
}
for (Interceptor interceptor : ejbJar.getInterceptors()) {
pruneRefs(interceptor, new EjbDeployment());
}
}
return appModule;