1 /** 2 * 3 * Copyright 2003-2004 The Apache Software Foundation 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 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 /** 32 * @version $Rev: 396206 $ $Date: 2006-04-22 19:55:45 -0700 (Sat, 22 Apr 2006) $ 33 */ 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 /** 62 * ObjectName must match this pattern: 63 * <p/> 64 * domain:j2eeType=J2EEDomain,name=domain 65 */ 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 }