1 17 package org.apache.geronimo.j2ee.management.impl; 18 19 import java.util.Hashtable ; 20 import javax.management.ObjectName ; 21 22 import org.apache.geronimo.gbean.GBeanInfo; 23 import org.apache.geronimo.gbean.GBeanInfoBuilder; 24 import org.apache.geronimo.management.J2EEApplication; 25 import org.apache.geronimo.management.J2EEServer; 26 import org.apache.geronimo.management.AppClientModule; 27 import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory; 28 import org.apache.geronimo.kernel.ObjectNameUtil; 29 30 33 public class J2EEAppClientModuleImpl implements AppClientModule { 34 private final String deploymentDescriptor; 35 private final J2EEServer server; 36 private final J2EEApplication application; 37 private final ClassLoader classLoader; 38 private final String objectName; 39 40 public J2EEAppClientModuleImpl(String objectName, J2EEServer server, J2EEApplication application, String deploymentDescriptor, ClassLoader classLoader) { 41 this.objectName = objectName; 42 ObjectName myObjectName = ObjectNameUtil.getObjectName(this.objectName); 43 verifyObjectName(myObjectName); 44 45 this.server = server; 46 this.application = application; 47 this.deploymentDescriptor = deploymentDescriptor; 48 this.classLoader = classLoader; 49 } 50 51 public String getObjectName() { 52 return objectName; 53 } 54 55 public boolean isStateManageable() { 56 return true; 57 } 58 59 public boolean isStatisticsProvider() { 60 return false; 61 } 62 63 public boolean isEventProvider() { 64 return true; 65 } 66 67 72 private void verifyObjectName(ObjectName objectName) { 73 if (objectName.isPattern()) { 74 throw new InvalidObjectNameException("ObjectName can not be a pattern", objectName); 75 } 76 Hashtable keyPropertyList = objectName.getKeyPropertyList(); 77 if (!"AppClientModule".equals(keyPropertyList.get("j2eeType"))) { 78 throw new InvalidObjectNameException("AppClientModule object name j2eeType property must be 'AppClientModule'", objectName); 79 } 80 if (!keyPropertyList.containsKey("name")) { 81 throw new InvalidObjectNameException("AppClientModule object must contain a name property", objectName); 82 } 83 if (!keyPropertyList.containsKey("J2EEServer")) { 84 throw new InvalidObjectNameException("AppClientModule object name must contain a J2EEServer property", objectName); 85 } 86 if (!keyPropertyList.containsKey("J2EEApplication")) { 87 throw new InvalidObjectNameException("AppClientModule object name must contain a J2EEApplication property", objectName); 88 } 89 if (keyPropertyList.size() != 4) { 90 throw new InvalidObjectNameException("AppClientModule object name can only have j2eeType, name, J2EEApplication, and J2EEServer properties", objectName); 91 } 92 } 93 94 public String getDeploymentDescriptor() { 95 return deploymentDescriptor; 96 } 97 98 public String getServer() { 99 return server.getObjectName(); 100 } 101 102 public String getApplication() { 103 if (application == null) { 104 return null; 105 } 106 return application.getObjectName(); 107 } 108 109 public String [] getJavaVMs() { 110 return server.getJavaVMs(); 111 } 112 113 public ClassLoader getClassLoader() { 114 return classLoader; 115 } 116 117 public static final GBeanInfo GBEAN_INFO; 118 119 static { 120 GBeanInfoBuilder infoFactory = GBeanInfoBuilder.createStatic(J2EEAppClientModuleImpl.class, NameFactory.APP_CLIENT_MODULE); 121 infoFactory.addReference("J2EEServer", J2EEServer.class); 122 infoFactory.addReference("J2EEApplication", J2EEApplication.class); 123 124 infoFactory.addAttribute("deploymentDescriptor", String .class, true); 125 126 infoFactory.addAttribute("objectName", String .class, false); 127 infoFactory.addAttribute("server", String .class, false); 128 infoFactory.addAttribute("application", String .class, false); 129 infoFactory.addAttribute("javaVMs", String [].class, false); 130 infoFactory.addAttribute("classLoader", ClassLoader .class, false); 131 infoFactory.addInterface(AppClientModule.class); 132 133 134 infoFactory.setConstructor(new String []{ 135 "objectName", 136 "J2EEServer", 137 "J2EEApplication", 138 "deploymentDescriptor", 139 "classLoader"}); 140 141 GBEAN_INFO = infoFactory.getBeanInfo(); 142 } 143 144 public static GBeanInfo getGBeanInfo() { 145 return GBEAN_INFO; 146 } 147 } 148 | Popular Tags |