1 22 package org.jboss.management.j2ee.factory; 23 24 import org.jboss.deployment.DeploymentInfo; 25 import org.jboss.logging.Logger; 26 import org.jboss.management.j2ee.Servlet; 27 import org.jboss.management.j2ee.WebModule; 28 29 import javax.management.MBeanServer ; 30 import javax.management.ObjectName ; 31 import java.util.HashMap ; 32 import java.util.Iterator ; 33 34 40 public class WebModuleFactory 41 implements ManagedObjectFactory 42 { 43 private static Logger log = Logger.getLogger(WebModuleFactory.class); 44 private HashMap deploymentToModuleNameMap = new HashMap (); 45 private HashMap containerToModuleNameMap = new HashMap (); 46 47 53 public ObjectName create(MBeanServer server, Object data) 54 { 55 if ((data instanceof DeploymentInfo) == false) 56 return null; 57 58 DeploymentInfo di = (DeploymentInfo) data; 59 String warName = di.shortName; 60 ObjectName webModuleService = di.deployedObject; 61 String earName = di.parent == null ? null : di.parent.shortName; 62 ObjectName jsr77Name = WebModule.create(server, 63 earName, warName, di.localUrl, webModuleService); 64 deploymentToModuleNameMap.put(di, jsr77Name); 65 Iterator servlets = di.mbeans.iterator(); 66 while (servlets.hasNext()) 67 { 68 Object next = servlets.next(); 69 try 70 { 71 ObjectName servletName = (ObjectName ) next; 72 createServlet(server, jsr77Name, servletName); 73 } 74 catch (Throwable e) 75 { 76 log.debug("Failed to create JSR-77 servlet: " + next, e); 77 } 78 } 79 return jsr77Name; 80 } 81 82 88 public void destroy(MBeanServer server, Object data) 89 { 90 if ((data instanceof DeploymentInfo) == false) 91 return; 92 93 DeploymentInfo di = (DeploymentInfo) data; 94 ObjectName jsr77Name = (ObjectName ) deploymentToModuleNameMap.remove(di); 95 96 log.debug("Destroy module: " + jsr77Name); 97 Iterator servlets = di.mbeans.iterator(); 98 while (servlets.hasNext()) 99 { 100 Object next = servlets.next(); 101 try 102 { 103 ObjectName servletName = (ObjectName ) next; 104 destroyServlet(server, servletName); 105 } 106 catch (Throwable e) 107 { 108 log.debug("Failed to destroy JSR-77 servlet: " + next, e); 109 } 110 } 111 112 if (jsr77Name != null) 113 { 114 WebModule.destroy(server, jsr77Name); 115 } 116 } 117 118 125 public ObjectName createServlet(MBeanServer mbeanServer, ObjectName webModuleName, 126 ObjectName servletServiceName) 127 { 128 ObjectName jsr77Name = null; 129 ObjectName webContainerName = null; 131 try 132 { 133 log.debug("Creating servlet: " + servletServiceName); 134 String servletName = servletServiceName.getKeyProperty("name"); 135 if (servletName != null) 136 { 137 jsr77Name = Servlet.create(mbeanServer, webModuleName, 139 webContainerName, servletServiceName); 140 containerToModuleNameMap.put(servletServiceName, jsr77Name); 141 log.debug("Created servlet: " + servletServiceName + ", module: " + jsr77Name); 142 } 143 } 144 catch (Exception e) 145 { 146 log.debug("Failed to create servlet: " + servletServiceName, e); 147 } 148 149 return jsr77Name; 150 } 151 152 158 public void destroyServlet(MBeanServer server, ObjectName servletServiceName) 159 { 160 ObjectName jsr77Name = (ObjectName ) containerToModuleNameMap.remove(servletServiceName); 161 162 log.debug("Destroy container: " + servletServiceName + ", module: " + jsr77Name); 163 if (jsr77Name != null) 164 { 165 Servlet.destroy(server, jsr77Name); 166 } 167 } 168 169 } 170 | Popular Tags |