1 17 18 package org.apache.geronimo.j2ee.management.impl; 19 20 import java.util.Hashtable ; 21 import java.util.Collection ; 22 import javax.management.ObjectName ; 23 24 import org.apache.geronimo.gbean.GBeanInfo; 25 import org.apache.geronimo.gbean.GBeanInfoBuilder; 26 import org.apache.geronimo.kernel.ObjectNameUtil; 27 import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory; 28 import org.apache.geronimo.management.geronimo.J2EEDomain; 29 import org.apache.geronimo.management.geronimo.J2EEServer; 30 31 34 public class J2EEDomainImpl implements J2EEDomain { 35 private final String objectName; 36 private final Collection servers; 37 38 public J2EEDomainImpl(String objectName, Collection servers) { 39 this.objectName = objectName; 40 ObjectName myObjectName = ObjectNameUtil.getObjectName(this.objectName); 41 verifyObjectName(myObjectName); 42 this.servers = servers; 43 } 44 45 public String getObjectName() { 46 return objectName; 47 } 48 49 public boolean isStateManageable() { 50 return true; 51 } 52 53 public boolean isStatisticsProvider() { 54 return false; 55 } 56 57 public boolean isEventProvider() { 58 return true; 59 } 60 61 66 private void verifyObjectName(ObjectName objectName) { 67 if (objectName.isPattern()) { 68 throw new InvalidObjectNameException("ObjectName can not be a pattern", objectName); 69 } 70 Hashtable keyPropertyList = objectName.getKeyPropertyList(); 71 if (!"J2EEDomain".equals(keyPropertyList.get("j2eeType"))) { 72 throw new InvalidObjectNameException("J2EEDomain object name j2eeType property must be 'J2EEDomain'", objectName); 73 } 74 String name = (String ) keyPropertyList.get("name"); 75 if (!objectName.getDomain().equals(name)) { 76 throw new InvalidObjectNameException("Domain part of J2EEDomain object name must match name propert", objectName); 77 } 78 } 79 80 81 public String [] getServers() { 82 return Util.getObjectNames(getServerInstances()); 83 } 84 85 public J2EEServer[] getServerInstances() { 86 if (servers == null) return new J2EEServer[0]; 87 return (J2EEServer[]) servers.toArray(new J2EEServer[servers.size()]); 88 } 89 90 public static final GBeanInfo GBEAN_INFO; 91 92 static { 93 GBeanInfoBuilder infoFactory = GBeanInfoBuilder.createStatic(J2EEDomainImpl.class, NameFactory.J2EE_DOMAIN); 94 95 infoFactory.addReference("Servers", J2EEServer.class, NameFactory.J2EE_SERVER); 96 infoFactory.setConstructor(new String []{"objectName", "Servers"}); 97 98 GBEAN_INFO = infoFactory.getBeanInfo(); 99 } 100 101 public static GBeanInfo getGBeanInfo() { 102 return GBEAN_INFO; 103 } 104 } 105 | Popular Tags |