KickJava   Java API By Example, From Geeks To Geeks.

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


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.ArrayList JavaDoc;
21 import java.util.Collection JavaDoc;
22 import java.util.Hashtable JavaDoc;
23 import javax.management.ObjectName JavaDoc;
24
25 import org.apache.geronimo.gbean.GBeanInfo;
26 import org.apache.geronimo.gbean.GBeanInfoBuilder;
27 import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
28 import org.apache.geronimo.kernel.ObjectNameUtil;
29 import org.apache.geronimo.kernel.config.ConfigurationManager;
30 import org.apache.geronimo.kernel.repository.ListableRepository;
31 import org.apache.geronimo.kernel.repository.WritableListableRepository;
32 import org.apache.geronimo.management.AppClientModule;
33 import org.apache.geronimo.management.EJBModule;
34 import org.apache.geronimo.management.J2EEDeployedObject;
35 import org.apache.geronimo.management.J2EEResource;
36 import org.apache.geronimo.management.geronimo.EJBManager;
37 import org.apache.geronimo.management.geronimo.J2EEApplication;
38 import org.apache.geronimo.management.geronimo.J2EEServer;
39 import org.apache.geronimo.management.geronimo.JMSManager;
40 import org.apache.geronimo.management.geronimo.JVM;
41 import org.apache.geronimo.management.geronimo.KeystoreManager;
42 import org.apache.geronimo.management.geronimo.LoginService;
43 import org.apache.geronimo.management.geronimo.ResourceAdapterModule;
44 import org.apache.geronimo.management.geronimo.SecurityRealm;
45 import org.apache.geronimo.management.geronimo.WebManager;
46 import org.apache.geronimo.management.geronimo.WebModule;
47 import org.apache.geronimo.system.serverinfo.ServerInfo;
48 import org.apache.geronimo.system.threads.ThreadPool;
49 import org.apache.geronimo.system.plugin.PluginInstaller;
50 import org.apache.geronimo.system.plugin.PluginRepositoryList;
51
52 /**
53  * @version $Rev: 476049 $ $Date: 2006-11-16 23:35:17 -0500 (Thu, 16 Nov 2006) $
54  */

55 public class J2EEServerImpl implements J2EEServer {
56     private static final String JavaDoc SERVER_VENDOR = "The Apache Software Foundation";
57     private final String JavaDoc objectName;
58     private final ServerInfo serverInfo;
59     private final Collection JavaDoc jvms;
60     private final Collection JavaDoc resources;
61     private final Collection JavaDoc j2eeApplications;
62     private final Collection JavaDoc appClientModules;
63     private final Collection JavaDoc webModules;
64     private final Collection JavaDoc ejbModules;
65     private final Collection JavaDoc resourceAdapterModules;
66     private final Collection JavaDoc webManagers;
67     private final Collection JavaDoc ejbManagers;
68     private final Collection JavaDoc jmsManagers;
69     private final Collection JavaDoc threadPools;
70     private final Collection JavaDoc repositories;
71     private final Collection JavaDoc pluginRepoLists;
72     private final Collection JavaDoc writableRepos;
73     private final Collection JavaDoc securityRealms;
74     private final Collection JavaDoc loginServices;
75     private final Collection JavaDoc keystoreManagers;
76     private final PluginInstaller pluginInstaller;
77     private final ConfigurationManager configurationManager;
78
79     public J2EEServerImpl(String JavaDoc objectName,
80                           ServerInfo serverInfo,
81                           Collection JavaDoc jvms,
82                           Collection JavaDoc resources,
83                           Collection JavaDoc applications,
84                           Collection JavaDoc appClientModules,
85                           Collection JavaDoc webModules,
86                           Collection JavaDoc ejbModules,
87                           Collection JavaDoc resourceAdapterModules,
88                           Collection JavaDoc webManagers,
89                           Collection JavaDoc ejbManagers,
90                           Collection JavaDoc jmsManagers,
91                           Collection JavaDoc threadPools,
92                           Collection JavaDoc repositories,
93                           Collection JavaDoc writableRepos,
94                           Collection JavaDoc securityRealms,
95                           Collection JavaDoc loginServices,
96                           Collection JavaDoc keystoreManagers,
97                           PluginInstaller configurationInstaller,
98                           ConfigurationManager configurationManager,
99                           Collection JavaDoc pluginRepoLists) {
100
101         this.objectName = objectName;
102         ObjectName JavaDoc myObjectName = ObjectNameUtil.getObjectName(this.objectName);
103         verifyObjectName(myObjectName);
104
105         this.serverInfo = serverInfo;
106         this.jvms = jvms;
107         this.resources = resources;
108
109         this.j2eeApplications = applications;
110         this.appClientModules = appClientModules;
111         this.webModules = webModules;
112         this.ejbModules = ejbModules;
113         this.resourceAdapterModules = resourceAdapterModules;
114
115         this.webManagers = webManagers;
116         this.ejbManagers = ejbManagers;
117         this.jmsManagers = jmsManagers;
118
119         this.threadPools = threadPools;
120         this.repositories = repositories;
121         this.writableRepos = writableRepos;
122         this.securityRealms = securityRealms;
123         this.loginServices = loginServices;
124         this.keystoreManagers = keystoreManagers;
125         this.pluginInstaller = configurationInstaller;
126         this.configurationManager = configurationManager;
127         this.pluginRepoLists = pluginRepoLists;
128     }
129
130     public String JavaDoc getObjectName() {
131         return objectName;
132     }
133
134     public boolean isStateManageable() {
135         return true;
136     }
137
138     public boolean isStatisticsProvider() {
139         return false;
140     }
141
142     public boolean isEventProvider() {
143         return true;
144     }
145
146     /**
147      * ObjectName must match this pattern:
148      * <p/>
149      * domain:j2eeType=J2EEServer,name=MyName
150      */

151     private void verifyObjectName(ObjectName JavaDoc objectName) {
152         if (objectName.isPattern()) {
153             throw new InvalidObjectNameException("ObjectName can not be a pattern", objectName);
154         }
155         Hashtable JavaDoc keyPropertyList = objectName.getKeyPropertyList();
156         if (!"J2EEServer".equals(keyPropertyList.get("j2eeType"))) {
157             throw new InvalidObjectNameException("J2EEServer object name j2eeType property must be 'J2EEServer'", objectName);
158         }
159         if (!keyPropertyList.containsKey("name")) {
160             throw new InvalidObjectNameException("J2EEServer object must contain a name property", objectName);
161         }
162         if (keyPropertyList.size() != 2) {
163             throw new InvalidObjectNameException("J2EEServer object name can only have j2eeType, and name", objectName);
164         }
165     }
166
167
168     public String JavaDoc[] getDeployedObjects() {
169         return Util.getObjectNames(getDeployedObjectInstances());
170     }
171
172     public J2EEDeployedObject[] getDeployedObjectInstances() {
173         ArrayList JavaDoc objects = new ArrayList JavaDoc();
174         if (j2eeApplications != null) {
175             objects.addAll(j2eeApplications);
176         }
177         if (appClientModules != null) {
178             objects.addAll(appClientModules);
179         }
180         if (ejbModules != null) {
181             objects.addAll(ejbModules);
182         }
183         if (webModules != null) {
184             objects.addAll(webModules);
185         }
186         if (resourceAdapterModules != null) {
187             objects.addAll(resourceAdapterModules);
188         }
189
190         return (J2EEDeployedObject[]) objects.toArray(new J2EEDeployedObject[objects.size()]);
191     }
192
193     public String JavaDoc[] getResources() {
194         return Util.getObjectNames(getResourceInstances());
195     }
196
197     public J2EEResource[] getResourceInstances() {
198         if (resources == null) return new J2EEResource[0];
199         return (J2EEResource[]) resources.toArray(new J2EEResource[resources.size()]);
200     }
201
202     public String JavaDoc[] getJavaVMs() {
203         return Util.getObjectNames(getJavaVMInstances());
204     }
205
206     public JVM[] getJavaVMInstances() {
207         if (jvms == null) return new JVM[0];
208         return (JVM[]) jvms.toArray(new JVM[jvms.size()]);
209     }
210
211     public J2EEApplication[] getApplications() {
212         if (j2eeApplications == null) return new J2EEApplication[0];
213         return (J2EEApplication[]) j2eeApplications.toArray(new J2EEApplication[j2eeApplications.size()]);
214     }
215
216     public AppClientModule[] getAppClients() {
217         if (appClientModules == null) return new AppClientModule[0];
218         return (AppClientModule[]) appClientModules.toArray(new AppClientModule[appClientModules.size()]);
219     }
220
221     public WebModule[] getWebModules() {
222         if (webModules == null) return new WebModule[0];
223         return (WebModule[]) webModules.toArray(new WebModule[webModules.size()]);
224     }
225
226     public EJBModule[] getEJBModules() {
227         if (ejbModules == null) return new EJBModule[0];
228         return (EJBModule[]) ejbModules.toArray(new EJBModule[ejbModules.size()]);
229     }
230
231     public ResourceAdapterModule[] getResourceAdapterModules() {
232         if (resourceAdapterModules == null) return new ResourceAdapterModule[0];
233         return (ResourceAdapterModule[]) resourceAdapterModules.toArray(new ResourceAdapterModule[resourceAdapterModules.size()]);
234     }
235
236
237     public WebManager[] getWebManagers() {
238         if (webManagers == null) return new WebManager[0];
239         return (WebManager[]) webManagers.toArray(new WebManager[webManagers.size()]);
240     }
241
242     public EJBManager[] getEJBManagers() {
243         if (ejbManagers == null) return new EJBManager[0];
244         return (EJBManager[]) ejbManagers.toArray(new EJBManager[ejbManagers.size()]);
245     }
246
247     public JMSManager[] getJMSManagers() {
248         if (jmsManagers == null) return new JMSManager[0];
249         return (JMSManager[]) jmsManagers.toArray(new JMSManager[jmsManagers.size()]);
250     }
251
252     public ThreadPool[] getThreadPools() {
253         if (threadPools == null) return new ThreadPool[0];
254         return (ThreadPool[]) threadPools.toArray(new ThreadPool[threadPools.size()]);
255     }
256
257     public ListableRepository[] getRepositories() {
258         if (repositories == null) return new ListableRepository[0];
259         return (ListableRepository[]) repositories.toArray(new ListableRepository[repositories.size()]);
260     }
261
262     public WritableListableRepository[] getWritableRepositories() {
263         if (writableRepos == null) return new WritableListableRepository[0];
264         return (WritableListableRepository[]) writableRepos.toArray(new WritableListableRepository[writableRepos.size()]);
265     }
266
267     public SecurityRealm[] getSecurityRealms() {
268         if (securityRealms == null) return new SecurityRealm[0];
269         return (SecurityRealm[]) securityRealms.toArray(new SecurityRealm[securityRealms.size()]);
270     }
271
272     public PluginRepositoryList[] getPluginRepositoryLists() {
273         if (pluginRepoLists == null) return new PluginRepositoryList[0];
274         return (PluginRepositoryList[]) pluginRepoLists.toArray(new PluginRepositoryList[pluginRepoLists.size()]);
275     }
276
277     public ServerInfo getServerInfo() {
278         return serverInfo;
279     }
280
281     public LoginService getLoginService() {
282         if (loginServices == null) return null;
283         return (LoginService) loginServices.iterator().next();
284     }
285
286     public KeystoreManager getKeystoreManager() {
287         if (keystoreManagers == null) return null;
288         return (KeystoreManager) keystoreManagers.iterator().next();
289     }
290
291     public PluginInstaller getPluginInstaller() {
292         return pluginInstaller;
293     }
294
295     public ConfigurationManager getConfigurationManager() {
296         return configurationManager;
297     }
298
299     public String JavaDoc getServerVendor() {
300         return SERVER_VENDOR;
301     }
302
303     public String JavaDoc getServerVersion() {
304         return serverInfo.getVersion();
305     }
306
307     public static final GBeanInfo GBEAN_INFO;
308
309     static {
310         GBeanInfoBuilder infoFactory = GBeanInfoBuilder.createStatic(J2EEServerImpl.class, NameFactory.J2EE_SERVER);
311
312         infoFactory.addReference("ServerInfo", ServerInfo.class, NameFactory.GERONIMO_SERVICE);
313         infoFactory.addReference("JVMs", JVM.class, NameFactory.JVM);
314         infoFactory.addReference("Resources", J2EEResource.class); // several types match this
315
infoFactory.addReference("Applications", J2EEApplication.class, NameFactory.J2EE_APPLICATION);
316         infoFactory.addReference("AppClientModules", AppClientModule.class, NameFactory.APP_CLIENT_MODULE);
317         infoFactory.addReference("WebModules", WebModule.class, NameFactory.WEB_MODULE);
318         infoFactory.addReference("EJBModules", EJBModule.class, NameFactory.EJB_MODULE);
319         infoFactory.addReference("ResourceAdapterModules", ResourceAdapterModule.class, NameFactory.RESOURCE_ADAPTER_MODULE);
320         infoFactory.addReference("WebManagers", WebManager.class);
321         infoFactory.addReference("EJBManagers", EJBManager.class);
322         infoFactory.addReference("JMSManagers", JMSManager.class);
323         infoFactory.addReference("ThreadPools", ThreadPool.class);
324         infoFactory.addReference("Repositories", ListableRepository.class);
325         infoFactory.addReference("WritableRepos", WritableListableRepository.class);
326         infoFactory.addReference("SecurityRealms", SecurityRealm.class);
327         infoFactory.addReference("LoginServices", LoginService.class);
328         infoFactory.addReference("KeystoreManagers", KeystoreManager.class);
329         infoFactory.addReference("PluginInstaller", PluginInstaller.class);
330         infoFactory.addReference("PluginRepoLists", PluginRepositoryList.class);
331         infoFactory.addReference("ConfigurationManager", ConfigurationManager.class);
332
333         infoFactory.setConstructor(new String JavaDoc[]{
334                 "objectName",
335                 "ServerInfo",
336                 "JVMs",
337                 "Resources",
338                 "Applications",
339                 "AppClientModules",
340                 "WebModules",
341                 "EJBModules",
342                 "ResourceAdapterModules",
343                 "WebManagers",
344                 "EJBManagers",
345                 "JMSManagers",
346                 "ThreadPools",
347                 "Repositories",
348                 "WritableRepos",
349                 "SecurityRealms",
350                 "LoginServices",
351                 "KeystoreManagers",
352                 "PluginInstaller",
353                 "ConfigurationManager",
354                 "PluginRepoLists",
355         });
356
357         GBEAN_INFO = infoFactory.getBeanInfo();
358     }
359
360     public static GBeanInfo getGBeanInfo() {
361         return GBEAN_INFO;
362     }
363 }
364
Popular Tags