KickJava   Java API By Example, From Geeks To Geeks.

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


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 package org.apache.geronimo.j2ee.management.impl;
18
19 import java.util.Hashtable JavaDoc;
20 import java.util.Collection JavaDoc;
21 import java.util.ArrayList JavaDoc;
22 import javax.management.ObjectName JavaDoc;
23 import org.apache.geronimo.gbean.GBeanInfo;
24 import org.apache.geronimo.gbean.GBeanInfoBuilder;
25 import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
26 import org.apache.geronimo.kernel.ObjectNameUtil;
27 import org.apache.geronimo.management.AppClientModule;
28 import org.apache.geronimo.management.EJBModule;
29 import org.apache.geronimo.management.J2EEModule;
30 import org.apache.geronimo.management.J2EEResource;
31 import org.apache.geronimo.management.geronimo.J2EEApplication;
32 import org.apache.geronimo.management.geronimo.J2EEServer;
33 import org.apache.geronimo.management.geronimo.ResourceAdapterModule;
34 import org.apache.geronimo.management.geronimo.WebModule;
35
36 /**
37  * @version $Rev: 476049 $ $Date: 2006-11-16 23:35:17 -0500 (Thu, 16 Nov 2006) $
38  */

39 public class J2EEApplicationImpl implements J2EEApplication {
40     private final String JavaDoc objectName;
41     private final String JavaDoc deploymentDescriptor;
42     private final J2EEServer server;
43     private final Collection JavaDoc resources;
44     private final Collection JavaDoc appClientModules;
45     private final Collection JavaDoc ejbModules;
46     private final Collection JavaDoc resourceAdapterModules;
47     private final Collection JavaDoc webModules;
48
49     public J2EEApplicationImpl(String JavaDoc objectName,
50             String JavaDoc deploymentDescriptor,
51             J2EEServer server,
52             Collection JavaDoc resources,
53             Collection JavaDoc appClientModules,
54             Collection JavaDoc ejbModules,
55             Collection JavaDoc resourceAdapterModules,
56             Collection JavaDoc webModules) {
57
58         this.objectName = objectName;
59         ObjectName JavaDoc myObjectName = ObjectNameUtil.getObjectName(this.objectName);
60         verifyObjectName(myObjectName);
61
62         this.deploymentDescriptor = deploymentDescriptor;
63         this.server = server;
64         this.resources = resources;
65         this.appClientModules = appClientModules;
66         this.ejbModules = ejbModules;
67         this.resourceAdapterModules = resourceAdapterModules;
68         this.webModules = webModules;
69     }
70
71     public String JavaDoc getObjectName() {
72         return objectName;
73     }
74
75     public boolean isStateManageable() {
76         return true;
77     }
78
79     public boolean isStatisticsProvider() {
80         return false;
81     }
82
83     public boolean isEventProvider() {
84         return true;
85     }
86
87     /**
88      * ObjectName must match this pattern:
89      * <p/>
90      * domain:j2eeType=J2EEApplication,name=MyName,J2EEServer=MyServer
91      */

92     private void verifyObjectName(ObjectName JavaDoc objectName) {
93         if (objectName.isPattern()) {
94             throw new InvalidObjectNameException("ObjectName can not be a pattern", objectName);
95         }
96         Hashtable JavaDoc keyPropertyList = objectName.getKeyPropertyList();
97         if (!"J2EEApplication".equals(keyPropertyList.get("j2eeType"))) {
98             throw new InvalidObjectNameException("J2EEApplication object name j2eeType property must be 'J2EEApplication'", objectName);
99         }
100         if (!keyPropertyList.containsKey("name")) {
101             throw new InvalidObjectNameException("J2EEApplication object must contain a J2EEServer property", objectName);
102         }
103         if (!keyPropertyList.containsKey("J2EEServer")) {
104             throw new InvalidObjectNameException("J2EEApplication object name must contain a J2EEServer property", objectName);
105         }
106         if (keyPropertyList.size() != 3) {
107             throw new InvalidObjectNameException("J2EEApplication object name can only have j2eeType, name, and J2EEServer properties", objectName);
108         }
109     }
110
111     public String JavaDoc[] getModules() {
112         return Util.getObjectNames(getModulesInstances());
113     }
114
115     public J2EEModule[] getModulesInstances() {
116         ArrayList JavaDoc objects = new ArrayList JavaDoc();
117         if (appClientModules != null) {
118             objects.addAll(appClientModules);
119         }
120         if (ejbModules != null) {
121             objects.addAll(ejbModules);
122         }
123         if (webModules != null) {
124             objects.addAll(webModules);
125         }
126         if (resourceAdapterModules != null) {
127             objects.addAll(resourceAdapterModules);
128         }
129
130         return (J2EEModule[]) objects.toArray(new J2EEModule[objects.size()]);
131     }
132
133     public J2EEResource[] getResources() {
134         if (resources == null) return new J2EEResource[0];
135         return (J2EEResource[]) resources.toArray(new J2EEResource[resources.size()]);
136     }
137
138     public AppClientModule[] getClientModules() {
139         if (appClientModules == null) return new AppClientModule[0];
140         return (AppClientModule[]) appClientModules.toArray(new AppClientModule[appClientModules.size()]);
141     }
142
143     public EJBModule[] getEJBModules() {
144         if (ejbModules == null) return new EJBModule[0];
145         return (EJBModule[]) ejbModules.toArray(new EJBModule[ejbModules.size()]);
146     }
147
148     public ResourceAdapterModule[] getRAModules() {
149         if (resourceAdapterModules == null) return new ResourceAdapterModule[0];
150         return (ResourceAdapterModule[]) resourceAdapterModules.toArray(new ResourceAdapterModule[resourceAdapterModules.size()]);
151     }
152
153     public WebModule[] getWebModules() {
154         if (webModules == null) return new WebModule[0];
155         return (WebModule[]) webModules.toArray(new WebModule[webModules.size()]);
156     }
157
158     public String JavaDoc getDeploymentDescriptor() {
159         return deploymentDescriptor;
160     }
161
162     public String JavaDoc getServer() {
163         return server.getObjectName();
164     }
165
166     public static final GBeanInfo GBEAN_INFO;
167
168     static {
169         GBeanInfoBuilder infoFactory = GBeanInfoBuilder.createStatic(J2EEApplicationImpl.class, NameFactory.J2EE_APPLICATION);
170         infoFactory.addAttribute("deploymentDescriptor", String JavaDoc.class, true);
171         infoFactory.addReference("Server", J2EEServer.class);
172         infoFactory.addReference("Resources", J2EEResource.class);
173         infoFactory.addReference("AppClientModules", AppClientModule.class);
174         infoFactory.addReference("EJBModules", EJBModule.class);
175         infoFactory.addReference("ResourceAdapterModules", ResourceAdapterModule.class);
176         infoFactory.addReference("WebModules", WebModule.class);
177
178         infoFactory.setConstructor(new String JavaDoc[]{
179                 "objectName",
180                 "deploymentDescriptor",
181                 "Server",
182                 "Resources",
183                 "AppClientModules",
184                 "EJBModules",
185                 "ResourceAdapterModules",
186                 "WebModules",
187         });
188
189         GBEAN_INFO = infoFactory.getBeanInfo();
190     }
191
192     public static GBeanInfo getGBeanInfo() {
193         return GBEAN_INFO;
194     }
195 }
196
Popular Tags