KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > j2ee > management > impl > J2EEDomainImpl


1 /**
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. 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 JavaDoc;
21 import java.util.Collection JavaDoc;
22 import javax.management.ObjectName JavaDoc;
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: 476049 $ $Date: 2006-11-16 23:35:17 -0500 (Thu, 16 Nov 2006) $
33  */

34 public class J2EEDomainImpl implements J2EEDomain {
35     private final String JavaDoc objectName;
36     private final Collection JavaDoc servers;
37
38     public J2EEDomainImpl(String JavaDoc objectName, Collection JavaDoc servers) {
39         this.objectName = objectName;
40         ObjectName JavaDoc myObjectName = ObjectNameUtil.getObjectName(this.objectName);
41         verifyObjectName(myObjectName);
42         this.servers = servers;
43     }
44
45     public String JavaDoc 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 JavaDoc objectName) {
67         if (objectName.isPattern()) {
68             throw new InvalidObjectNameException("ObjectName can not be a pattern", objectName);
69         }
70         Hashtable JavaDoc 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 JavaDoc name = (String JavaDoc) 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 JavaDoc[] 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 JavaDoc[]{"objectName", "Servers"});
97
98         GBEAN_INFO = infoFactory.getBeanInfo();
99     }
100
101     public static GBeanInfo getGBeanInfo() {
102         return GBEAN_INFO;
103     }
104 }
105
Popular Tags