1 17 package org.apache.geronimo.connector.deployment; 18 19 import java.util.Hashtable ; 20 import javax.management.MalformedObjectNameException ; 21 import javax.management.ObjectName ; 22 23 import org.apache.geronimo.gbean.GBeanInfo; 24 import org.apache.geronimo.gbean.GBeanInfoBuilder; 25 import org.apache.geronimo.j2ee.management.J2EEApplication; 26 import org.apache.geronimo.j2ee.management.J2EEServer; 27 import org.apache.geronimo.j2ee.management.impl.InvalidObjectNameException; 28 import org.apache.geronimo.j2ee.management.impl.Util; 29 import org.apache.geronimo.kernel.Kernel; 30 import org.apache.geronimo.kernel.jmx.JMXUtil; 31 32 35 public class ResourceAdapterModuleImpl { 36 private final Kernel kernel; 37 private final String baseName; 38 private final J2EEServer server; 39 private final J2EEApplication application; 40 private final String deploymentDescriptor; 41 42 public ResourceAdapterModuleImpl(Kernel kernel, String objectName, J2EEServer server, J2EEApplication application, String deploymentDescriptor) { 43 ObjectName myObjectName = JMXUtil.getObjectName(objectName); 44 verifyObjectName(myObjectName); 45 46 Hashtable keyPropertyList = myObjectName.getKeyPropertyList(); 48 String name = (String ) keyPropertyList.get("name"); 49 String j2eeServerName = (String ) keyPropertyList.get("J2EEServer"); 50 String j2eeApplicationName = (String ) keyPropertyList.get("J2EEApplication"); 51 baseName = myObjectName.getDomain() + ":J2EEServer=" + j2eeServerName + ",J2EEApplication=" + j2eeApplicationName + ",ResouceAdapterModule=" + name + ","; 52 53 this.kernel = kernel; 54 this.server = server; 55 this.application = application; 56 this.deploymentDescriptor = deploymentDescriptor; 57 } 58 59 public String getDeploymentDescriptor() { 60 return deploymentDescriptor; 61 } 62 63 public String getServer() { 64 return server.getObjectName(); 65 } 66 67 public String getApplication() { 68 if (application == null) { 69 return null; 70 } 71 return application.getObjectName(); 72 } 73 74 public String [] getJavaVMs() { 75 return server.getJavaVMs(); 76 } 77 78 public String [] getResourceAdapters() throws MalformedObjectNameException { 79 return Util.getObjectNames(kernel, baseName, new String []{"ResourceAdapter"}); 80 } 81 82 87 private void verifyObjectName(ObjectName objectName) { 88 if (objectName.isPattern()) { 89 throw new InvalidObjectNameException("ObjectName can not be a pattern", objectName); 90 } 91 Hashtable keyPropertyList = objectName.getKeyPropertyList(); 92 if (!"ResourceAdapterModule".equals(keyPropertyList.get("j2eeType"))) { 93 throw new InvalidObjectNameException("ResourceAdapterModule object name j2eeType property must be 'ResourceAdapterModule'", objectName); 94 } 95 if (!keyPropertyList.containsKey("name")) { 96 throw new InvalidObjectNameException("ResourceAdapterModule object must contain a name property", objectName); 97 } 98 if (!keyPropertyList.containsKey("J2EEServer")) { 99 throw new InvalidObjectNameException("ResourceAdapterModule object name must contain a J2EEServer property", objectName); 100 } 101 if (!keyPropertyList.containsKey("J2EEApplication")) { 102 throw new InvalidObjectNameException("ResourceAdapterModule object name must contain a J2EEApplication property", objectName); 103 } 104 if (keyPropertyList.size() != 4) { 105 throw new InvalidObjectNameException("ResourceAdapterModule object name can only have j2eeType, name, J2EEApplication, and J2EEServer properties", objectName); 106 } 107 } 108 109 public static final GBeanInfo GBEAN_INFO; 110 111 static { 112 GBeanInfoBuilder infoFactory = new GBeanInfoBuilder(ResourceAdapterModuleImpl.class); 113 infoFactory.addReference("J2EEServer", J2EEServer.class); 114 infoFactory.addReference("J2EEApplication", J2EEApplication.class); 115 116 infoFactory.addAttribute("deploymentDescriptor", String .class, true); 117 118 infoFactory.addAttribute("kernel", Kernel.class, false); 119 infoFactory.addAttribute("objectName", String .class, false); 120 infoFactory.addAttribute("server", String .class, false); 121 infoFactory.addAttribute("application", String .class, false); 122 infoFactory.addAttribute("javaVMs", String [].class, false); 123 infoFactory.addAttribute("resourceAdapters", String [].class, false); 124 125 infoFactory.setConstructor(new String []{ 126 "kernel", 127 "objectName", 128 "J2EEServer", 129 "J2EEApplication", 130 "deploymentDescriptor"}); 131 132 GBEAN_INFO = infoFactory.getBeanInfo(); 133 } 134 135 public static GBeanInfo getGBeanInfo() { 136 return GBEAN_INFO; 137 } 138 } 139 | Popular Tags |