1 22 package org.jboss.management.j2ee; 23 24 import org.jboss.logging.Logger; 25 26 import javax.management.JMException ; 27 import javax.management.MBeanServer ; 28 import javax.management.MalformedObjectNameException ; 29 import javax.management.ObjectName ; 30 import java.net.URL ; 31 import java.security.InvalidParameterException ; 32 import java.util.ArrayList ; 33 import java.util.Hashtable ; 34 import java.util.List ; 35 36 46 public class J2EEApplication extends J2EEDeployedObject 47 implements J2EEApplicationMBean 48 { 49 50 private static Logger log = Logger.getLogger(J2EEApplication.class); 52 53 56 private List moduleNames = new ArrayList (); 57 58 60 69 public static ObjectName create(MBeanServer mbeanServer, String earName, URL url) 70 { 71 String lDD = null; 72 ObjectName jsr77Name = null; 73 ObjectName j2eeServerName = J2EEDomain.getDomainServerName(mbeanServer); 74 lDD = J2EEDeployedObject.getDeploymentDescriptor(url, J2EEDeployedObject.APPLICATION); 76 try 77 { 78 J2EEApplication j2eeApp = new J2EEApplication(earName, j2eeServerName, lDD); 80 jsr77Name = j2eeApp.getObjectName(); 81 87 if (mbeanServer.isRegistered(jsr77Name) == true) 88 { 89 String [] tmpModules = (String []) mbeanServer.getAttribute(jsr77Name, "modules"); 91 mbeanServer.unregisterMBean(jsr77Name); 93 mbeanServer.registerMBean(j2eeApp, jsr77Name); 94 if (tmpModules != null) 96 { 97 for (int m = 0; m < tmpModules.length; m++) 98 j2eeApp.addChild(newObjectName(tmpModules[m])); 99 } 100 } 101 else 102 { 103 mbeanServer.registerMBean(j2eeApp, jsr77Name); 104 } 105 log.debug("Created JSR-77 J2EEApplication: " + earName); 106 } 107 catch (Exception e) 108 { 109 log.debug("Could not create JSR-77 J2EEApplication: " + jsr77Name, e); 110 } 111 return jsr77Name; 112 } 113 114 120 public static void destroy(MBeanServer mbeanServer, ObjectName jsr77Name) 121 { 122 try 123 { 124 mbeanServer.unregisterMBean(jsr77Name); 125 log.debug("Destroyed JSR-77 J2EEApplication: " + jsr77Name); 126 } 127 catch (javax.management.InstanceNotFoundException infe) 128 { 129 } 130 catch (Exception e) 131 { 132 log.debug("Could not destroy JSR-77 J2EEApplication: " + jsr77Name, e); 133 } 134 } 135 136 138 145 public J2EEApplication(String name, ObjectName mbeanServer, String pDeploymentDescriptor) 146 throws MalformedObjectNameException , InvalidParentException 147 { 148 super(J2EETypeConstants.J2EEApplication, name, mbeanServer, pDeploymentDescriptor); 149 } 150 151 153 155 158 public String [] getmodules() 159 { 160 return (String []) moduleNames.toArray(new String [moduleNames.size()]); 161 } 162 163 166 public String getmodule(int pIndex) 167 { 168 if (pIndex >= 0 && pIndex < moduleNames.size()) 169 { 170 return (String ) moduleNames.get(pIndex); 171 } 172 return null; 173 } 174 175 177 public void addChild(ObjectName pChild) 178 { 179 String lType = J2EEManagedObject.getType(pChild); 180 if ( 181 J2EETypeConstants.EJBModule.equals(lType) || 182 J2EETypeConstants.WebModule.equals(lType) || 183 J2EETypeConstants.ResourceAdapterModule.equals(lType) || 184 J2EETypeConstants.ServiceModule.equals(lType) 185 ) 186 { 187 moduleNames.add(pChild.getCanonicalName()); 188 try 189 { 190 server.invoke(newObjectName(getparent()), 193 "addChild", 194 new Object []{pChild}, 195 new String []{ObjectName .class.getName()}); 196 } 197 catch (JMException jme) 198 { 199 } 201 } 202 } 203 204 public void removeChild(ObjectName pChild) 205 { 206 String lType = J2EEManagedObject.getType(pChild); 207 if ( 208 J2EETypeConstants.EJBModule.equals(lType) || 209 J2EETypeConstants.WebModule.equals(lType) || 210 J2EETypeConstants.ResourceAdapterModule.equals(lType) || 211 J2EETypeConstants.ServiceModule.equals(lType) 212 ) 213 { 214 moduleNames.remove(pChild.getCanonicalName()); 215 try 216 { 217 server.invoke(newObjectName(getparent()), 220 "removeChild", 221 new Object []{pChild}, 222 new String []{ObjectName .class.getName()}); 223 } 224 catch (JMException jme) 225 { 226 } 228 } 229 } 230 231 233 public String toString() 234 { 235 return "J2EEApplication { " + super.toString() + " } [ " + 236 "modules: " + moduleNames + 237 " ]"; 238 } 239 240 242 244 247 protected Hashtable getParentKeys(ObjectName pParent) 248 { 249 Hashtable lReturn = new Hashtable (); 250 Hashtable lProperties = pParent.getKeyPropertyList(); 251 lReturn.put(J2EETypeConstants.J2EEServer, lProperties.get("name")); 252 253 return lReturn; 254 } 255 256 258 } 260 | Popular Tags |