KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > management > util > J2EEManagementObjectManager


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 package com.sun.enterprise.management.util;
25
26 import com.sun.enterprise.ManagementObjectManager;
27 import com.sun.enterprise.admin.common.MBeanServerFactory;
28 import com.sun.enterprise.admin.meta.MBeanRegistry;
29 import com.sun.enterprise.admin.meta.MBeanRegistryFactory;
30 import com.sun.enterprise.admin.server.core.AdminService;
31
32 import com.sun.enterprise.deployment.*;
33 import com.sun.enterprise.deployment.Application;
34 import com.sun.enterprise.deployment.ApplicationClientDescriptor;
35 import com.sun.enterprise.deployment.WebServiceEndpoint;
36 import com.sun.enterprise.deployment.WebServicesDescriptor;
37 import com.sun.enterprise.deployment.BundleDescriptor;
38 import com.sun.enterprise.deployment.util.ModuleDescriptor;
39 import com.sun.enterprise.deployment.ConnectorDescriptor;
40 import com.sun.enterprise.deployment.EjbBundleDescriptor;
41 import com.sun.enterprise.deployment.EjbDescriptor;
42 import com.sun.enterprise.deployment.EjbSessionDescriptor;
43 import com.sun.enterprise.deployment.WebBundleDescriptor;
44 import com.sun.enterprise.deployment.WebComponentDescriptor;
45 import com.sun.enterprise.deployment.io.AppClientDeploymentDescriptorFile;
46 import com.sun.enterprise.deployment.io.ApplicationDeploymentDescriptorFile;
47 import com.sun.enterprise.deployment.io.ConnectorDeploymentDescriptorFile;
48 import com.sun.enterprise.deployment.io.EjbDeploymentDescriptorFile;
49 import com.sun.enterprise.deployment.io.WebDeploymentDescriptorFile;
50 import com.sun.enterprise.deployment.node.J2EEDocumentBuilder;
51 import com.sun.enterprise.management.agent.MEJB;
52 import com.sun.enterprise.management.agent.MEJBUtility;
53 import com.sun.enterprise.management.model.*;
54 //import com.sun.enterprise.management.model.emma.*;
55
import com.sun.enterprise.management.util.J2EEModuleCallBack;
56 import com.sun.enterprise.server.*;
57 import com.sun.enterprise.server.ApplicationServer;
58 import com.sun.jmx.trace.Trace;
59 //import com.sun.management.j2se.MOAgents.EmmaOptions;
60
//import com.sun.management.j2se.MOAgents.MOAgentFactory;
61
import java.io.File JavaDoc;
62 import java.lang.reflect.Method JavaDoc;
63 import java.lang.reflect.Constructor JavaDoc;
64 import java.rmi.RemoteException JavaDoc;
65 import java.security.AccessController JavaDoc;
66 import java.security.PrivilegedAction JavaDoc;
67 import java.util.*;
68 import java.util.logging.*;
69 import javax.management.*;
70 import javax.management.modelmbean.ModelMBean JavaDoc;
71 import javax.naming.*;
72 import javax.rmi.PortableRemoteObject JavaDoc;
73 import com.sun.enterprise.instance.*;
74 import com.sun.enterprise.deployment.io.DescriptorConstants;
75 import java.io.*;
76 import com.sun.enterprise.config.ConfigException;
77 import com.sun.enterprise.util.io.FileUtils;
78
79 import java.util.logging.Level JavaDoc;
80 import java.util.logging.Logger JavaDoc;
81 import com.sun.enterprise.admin.common.constant.AdminConstants;
82 import com.sun.enterprise.config.ConfigContext;
83 import com.sun.enterprise.config.serverbeans.Server;
84 import com.sun.enterprise.config.serverbeans.ServerHelper;
85 import com.sun.enterprise.management.j2ee.DASJ2EEServerImpl;
86 import com.sun.enterprise.admin.mbeans.DomainStatus;
87 import com.sun.enterprise.admin.mbeans.DomainStatusHelper;
88 import com.sun.enterprise.admin.mbeans.DomainStatusMBean;
89 import com.sun.appserv.management.j2ee.StateManageable;
90
91 import com.sun.enterprise.management.support.LoaderMBean;
92 import com.sun.appserv.management.base.Util;
93 import com.sun.appserv.management.util.misc.SetUtil;
94
95 /* uncomment the following if the HtmlAdaptorServer is needed */
96 //import com.sun.jdmk.comm.HtmlAdaptorServer;
97

98 import com.sun.enterprise.config.serverbeans.Cluster;
99 import com.sun.enterprise.config.serverbeans.ClusterHelper;
100 import com.sun.appserv.management.base.AMX;
101 import com.sun.appserv.management.base.Util;
102 import com.sun.appserv.management.j2ee.J2EEDomain;
103 import com.sun.appserv.management.j2ee.J2EECluster;
104 import com.sun.appserv.management.client.ProxyFactory;
105 import com.sun.enterprise.management.support.BootUtil;
106 import com.sun.enterprise.management.support.ObjectNames;
107 import com.sun.enterprise.management.j2ee.J2EEClusterImpl;
108 import com.sun.appserv.management.util.jmx.MBeanServerConnectionSource;
109 import com.sun.appserv.management.util.jmx.JMXUtil;
110 import com.sun.enterprise.management.support.WebModuleSupport;
111
112 /**
113  * J2EEManagementObjectManager is responsible for managing
114  * all JSR77 managed objects (MBeans).
115  * It is a "glue" integration layer between the J2EE RI and
116  * JMX (Java Management Extensions) and JSR77 implementations.
117  * It includes functionality for initializing JMX,
118  * registering and unregistering managed objects, starting and stopping
119  * J2EE modules, etc.
120  * The register/unregister methods are called from J2EE RI code when the
121  * RI objects corresponding to the MBeans are created/removed.
122  * RI code uses only the com.sun.enterprise.ManagementObjectManager
123  * interface.
124  *
125  * @author Prakash Aradhya, Sanjeev Krishnan
126  */

127
128 public class J2EEManagementObjectManager implements ManagementObjectManager {
129     
130     private MEJB mejbRef = null;
131     private MEJBUtility mejbUtility = null;
132     private static MBeanServer server = null;
133     private static String JavaDoc domain = J2EEDomainMdl.DOMAINNAME;
134  // private static boolean moagentNotSet = true;
135
private static final String JavaDoc QUEUE = "javax.jms.Queue";
136     private static final String JavaDoc TOPIC = "javax.jms.Topic";
137     private static final String JavaDoc DEFAULT_VIRTUAL_SERVER = "server";
138
139     private static Logger JavaDoc _logger = Logger.getLogger(AdminConstants.kLoggerName);
140
141     /* uncomment the following if the HtmlAdaptorServer is needed */
142     //private static HtmlAdaptorServer htmlAdaptorServer = null;
143

144     /* Static initializer for mBean server */
145     static {
146         if (server == null) {
147             initMBeanServer();
148         }
149         if ((server != null)) {
150             registerHTMLAdaptor();
151         }
152     }
153     
154     public J2EEManagementObjectManager() {
155         
156     // set the default managed object agent
157
// WARNING: This must be done before any managed objects are created
158
// if (moagentNotSet) {
159
//MOAgentFactory.setAgents(
160
// "com.sun.management.j2se.MOAgents.J2EEAgentImpl",
161
// "com.sun.management.j2se.MOAgents.J2EEClientImpl");
162
// moagentNotSet = false;
163
// }
164
}
165
166     /* Initialization method for mBean server */
167     private static void initMBeanServer() {
168
169         // get or create mBean server
170
try {
171         server = MBeanServerFactory.getMBeanServer();
172         } catch (Exception JavaDoc e) {
173             e.printStackTrace();
174         }
175     }
176
177     /**
178      * Register html adaptor
179      * Used for testing only
180      */

181     private static boolean _bHtmlAdaptorServerRegistered = false;
182     private static void registerHTMLAdaptor() {
183         /* uncomment the following if the HtmlAdaptorServer is needed */
184         if(_bHtmlAdaptorServerRegistered)
185             return;
186         try {
187             String JavaDoc strPort = System.getProperty("html.adaptor.port");
188             if(strPort==null || strPort.trim().length()<1)
189                 return;
190             //final int freePort = NetUtils.getFreePort();
191
int port = (new Integer JavaDoc(strPort.trim())).intValue();
192             Class JavaDoc cl = Class.forName("com.sun.jdmk.comm.HtmlAdaptorServer");
193             Constructor JavaDoc contr = cl.getConstructor(new Class JavaDoc[]{Integer.TYPE});
194             Object JavaDoc adaptor = contr.newInstance(new Object JavaDoc[]{new Integer JavaDoc(port)});
195             Method JavaDoc method = cl.getMethod("start");
196             ObjectName htmlAdaptorObjectName = new ObjectName(
197                     "Adaptor:name=html,port="+port);
198             server.registerMBean(adaptor, htmlAdaptorObjectName);
199             method.invoke(adaptor);
200             _bHtmlAdaptorServerRegistered = true;
201         } catch (Exception JavaDoc e) {
202             e.printStackTrace();
203         }
204     
205     }
206
207     public MEJBUtility getMEJBUtility(){
208         if(this.mejbUtility == null){
209             this.mejbUtility = MEJBUtility.getMEJBUtility();
210         }
211         return this.mejbUtility;
212     }
213     
214     public void registerJ2EEDomain() {
215         instantiateAndRegisterRuntimeMBean("J2EEDomain", null);
216     registerDomainStatusMBean();
217     }
218     
219     public void registerJ2EEServer() {
220         J2EEServerMdl managedServerMdlObject = new J2EEServerMdl(
221                 ApplicationServer.getServerContext().getInstanceName(),
222                 com.sun.appserv.server.util.Version.getVersion());
223         instantiateAndRegisterRuntimeMBean("J2EEServer", managedServerMdlObject);
224     }
225     
226     public void registerJCAConnectionFactory(String JavaDoc jcaResName,
227                 String JavaDoc jcaConnFactName, String JavaDoc managedConFact)
228     {
229         Object JavaDoc managedBean = (Object JavaDoc)new JCAConnectionFactoryMdl(
230             jcaResName, ApplicationServer.getServerContext().getInstanceName(),
231             jcaConnFactName, managedConFact);
232         instantiateAndRegisterRuntimeMBean("JCAConnectionFactory", managedBean, jcaResName, jcaConnFactName);
233     }
234
235     public void registerJCAManagedConnectionFactory(String JavaDoc connFactName) {
236         Object JavaDoc managedBean = (Object JavaDoc)new JCAManagedConnectionFactoryMdl(
237             connFactName, ApplicationServer.getServerContext().getInstanceName());
238         instantiateAndRegisterRuntimeMBean("JCAManagedConnectionFactory", managedBean, connFactName);
239     }
240
241     public void registerJCAResource(String JavaDoc name, String JavaDoc raName,
242                             String JavaDoc username, String JavaDoc password,
243                             String JavaDoc[] propNames, String JavaDoc[] propValues) {
244         Object JavaDoc managedBean = (Object JavaDoc)new JCAResourceMdl(name,
245                                 ApplicationServer.getServerContext().getInstanceName(),
246                                 raName, username, password, propNames, propValues);
247         instantiateAndRegisterRuntimeMBean("JCAResource", managedBean, raName, name);
248        
249     }
250
251     public void registerAdminObjectResource(String JavaDoc name, String JavaDoc raName, String JavaDoc resType,
252                             String JavaDoc[] propNames, String JavaDoc[] propValues) {
253         //username and password for nulls in that order
254
if(QUEUE.equals(resType) || TOPIC.equals(resType)) {
255             registerJMSResource(name, resType, null, null, propNames, propValues);
256         }
257     }
258     
259     public void registerJDBCDataSource(String JavaDoc dsJndiName, String JavaDoc dsName, String JavaDoc url,
260                             String JavaDoc username,
261                             String JavaDoc password,
262                             String JavaDoc[] propNames,
263                             String JavaDoc[] propValues) {
264         Object JavaDoc managedBean = (Object JavaDoc)new JDBCDataSourceMdl(dsJndiName, dsName, url,
265                                 username,
266                                 ApplicationServer.getServerContext().getInstanceName(),
267                                 password,
268                                 propNames,
269                                 propValues);
270         instantiateAndRegisterRuntimeMBean("JDBCDataSource", managedBean, dsJndiName, dsJndiName); //FIXME: why no dsJndiName,dsName
271
}
272
273     public void registerJDBCDriver(String JavaDoc name) {
274         instantiateAndRegisterRuntimeMBean("JDBCDriver", null, name);
275     }
276
277     public void registerJDBCResource(String JavaDoc name) {
278         instantiateAndRegisterRuntimeMBean("JDBCResource", null, name);
279     }
280
281
282     public void registerJMSResource(String JavaDoc name, String JavaDoc resType,
283                                     String JavaDoc username, String JavaDoc password,
284                                     String JavaDoc[] propNames, String JavaDoc[] propValues) {
285         Object JavaDoc managedBean = (Object JavaDoc)new JMSResourceMdl(name,
286                                     ApplicationServer.getServerContext().getInstanceName(),
287                                     resType, username, password, propNames, propValues);
288         instantiateAndRegisterRuntimeMBean("JMSResource", managedBean, name);
289     }
290
291     public void registerJNDIResource(String JavaDoc name) {
292         instantiateAndRegisterRuntimeMBean("JNDIResource", null, name);
293     }
294
295     public void registerJTAResource(String JavaDoc name) {
296         instantiateAndRegisterRuntimeMBean("JTAResource", null, name);
297     }
298   
299     public void registerJVM() {
300         //instantiateAndRegisterRuntimeMBean("JVM", null,
301
// MOAgentFactory.getAgent().getJVMId());
302
instantiateAndRegisterRuntimeMBean("JVM", null,
303                 getJVMId());
304    }
305     
306     public void registerJavaMailResource(String JavaDoc name) {
307         instantiateAndRegisterRuntimeMBean("JavaMailResource", null, name);
308     }
309
310     
311     public void registerRMI_IIOPResource(String JavaDoc name) {
312         instantiateAndRegisterRuntimeMBean("RMI_IIOPResource", null, name);
313     }
314
315     MEJB getMEJB() throws Exception JavaDoc {
316         if ( mejbRef == null ) {
317             InitialContext ic = new InitialContext();
318             java.lang.Object JavaDoc objref = ic.lookup(
319                 System.getProperty("mejb.name","ejb/mgmt/MEJB"));
320         }
321         return mejbRef;
322     }
323      
324     public void unregisterStandAloneModule(String JavaDoc moduleType, String JavaDoc name) {
325         try {
326             unregisterStandAloneAndItsComponents(moduleType, name);
327         } catch ( Exception JavaDoc ex ) {
328             throw new RuntimeException JavaDoc(ex);
329         }
330     }
331
332     private void unregisterStandAloneAndItsComponents(
333         String JavaDoc moduleType, String JavaDoc moduleName)throws Exception JavaDoc {
334     }
335
336     public void unregisterJCAResource(String JavaDoc moduleName)throws Exception JavaDoc {
337     }
338
339     /**
340      * Unregisters the jms resource managed object if the type is Queue
341      * or Topic.
342      */

343     public void unregisterAdminObjectResource(
344             String JavaDoc name, String JavaDoc resourceType) throws Exception JavaDoc {
345         if(QUEUE.equals(resourceType) || TOPIC.equals(resourceType)) {
346             unregisterResource(name,"JMSResource");
347         }
348     }
349     
350     public void unregisterJMSResource(String JavaDoc name) throws Exception JavaDoc {
351         unregisterResource(name,"JMSResource");
352     }
353
354     public void unregisterJavaMailResource(String JavaDoc name) throws Exception JavaDoc {
355         unregisterResource(name,"JavaMailResource");
356     }
357     
358     public void unregisterJDBCResource(String JavaDoc name) throws Exception JavaDoc {
359         unregisterResource(name,"JDBCResource");
360     }
361
362     
363     /**
364      * Unregisters a resource mbean given the resource jndi name and
365      * the Managed Object type such as JDBCResource, JavaMailResource, etc.
366      *
367      * @param name The jndi name of the resource to be unregistered.
368      * @param type The managed object type such as JDBCResource.
369      * @throws Exception if the mbean cannot be unregistered.
370      */

371     void unregisterResource(String JavaDoc name, String JavaDoc type) throws Exception JavaDoc {
372         final MBeanRegistry registry =
373                 MBeanRegistryFactory.getRuntimeMBeanRegistry();
374         final String JavaDoc domainName =
375                 ApplicationServer.getServerContext().getDefaultDomainName();
376         final String JavaDoc serverName =
377                 ApplicationServer.getServerContext().getInstanceName();
378         final String JavaDoc[] location = new String JavaDoc[] {domainName, serverName, name};
379         final ObjectName on = registry.getMbeanObjectName(type, location);
380         if (on == null) {
381             return;
382         }
383         final MBeanServer mbs =
384                AdminService.getAdminService().getAdminContext().getMBeanServer();
385         if (mbs.isRegistered(on)) {
386             mbs.unregisterMBean(on);
387         }
388     }
389     
390     
391     public Object JavaDoc getModuleUserData(
392     String JavaDoc moduleID, int moduleType) throws Exception JavaDoc{
393         return null;
394     }
395     
396     public void setModuleUserData(
397     String JavaDoc moduleID, Object JavaDoc obj, int moduleType)throws Exception JavaDoc{
398     }
399
400     private ObjectName getManagedObjectModule(
401     String JavaDoc moduleID, int moduleType) throws Exception JavaDoc{
402         
403         return null;
404     }
405     
406        
407        
408     // Adding all the config mbeans at the end. we may move this to another file later
409
//FIXME
410
public void registerConfigJ2EEServer(String JavaDoc instance) {
411 throw new RuntimeException JavaDoc(">>>>>>>>>>>>>>>>>>>> registerConfigJ2EEServer not implemented <<<<<<<<<<<<<<<<<");
412     //new J2EEServerMdlEmmaAgent(new EmmaOptions(J2EEDomainMdl.DOMAINNAME));
413
}
414
415
416     //helper method for Runtime MBeanInstantiation
417

418     private void instantiateAndRegisterRuntimeMBean(String JavaDoc type, Object JavaDoc managed)
419     {
420         instantiateAndRegisterRuntimeMBean(type, managed, null, null, null);
421     }
422
423
424     //helper method for Runtime MBeanInstantiation
425
private void instantiateAndRegisterRuntimeMBean(
426     String JavaDoc type, Object JavaDoc managed, String JavaDoc name)
427     {
428         instantiateAndRegisterRuntimeMBean(type, managed, null, null, name);
429     }
430
431     //helper method for Runtime MBeanInstantiation
432
private void instantiateAndRegisterRuntimeMBean(
433     String JavaDoc type, Object JavaDoc managed, String JavaDoc parentName, String JavaDoc name)
434     {
435         instantiateAndRegisterRuntimeMBean(type, managed, null, parentName, name);
436     }
437
438
439     //helper method for Runtime MBeanInstantiation
440

441     private void instantiateAndRegisterRuntimeMBean(
442     String JavaDoc type, Object JavaDoc managed, String JavaDoc grandParentName,
443     String JavaDoc parentName, String JavaDoc name) {
444
445         MBeanRegistry registry = MBeanRegistryFactory.getRuntimeMBeanRegistry();
446         String JavaDoc domainName = ApplicationServer.getServerContext().getDefaultDomainName();
447         String JavaDoc serverName = ApplicationServer.getServerContext().getInstanceName();
448  
449         try {
450             if(grandParentName!=null) {
451
452                registry.instantiateMBean(
453             type,
454             new String JavaDoc[]{domainName, serverName, grandParentName,
455                      parentName, name},
456             managed, AdminService.getAdminService().getAdminContext().getAdminConfigContext(), true); //FIXME
457
} else {
458                 if(parentName!=null) {
459                    registry.instantiateMBean(
460                 type,
461                 new String JavaDoc[]{domainName, serverName,
462                              parentName, name},
463                 managed, AdminService.getAdminService().getAdminContext().getAdminConfigContext(), true); //FIXME
464
} else {
465                     if(name!=null) {
466                        registry.instantiateMBean(
467                 type, new String JavaDoc[]{domainName, serverName,name},
468                 managed, AdminService.getAdminService().getAdminContext().getAdminConfigContext(), true); //FIXME
469
} else {
470                        registry.instantiateMBean(
471                 type, new String JavaDoc[]{domainName, serverName},
472                 managed, AdminService.getAdminService().getAdminContext().getAdminConfigContext(), true); //FIXME
473
}
474         }
475         }
476         } catch (Exception JavaDoc e) {
477             System.out.println("Exception msg:"+e.getMessage());
478             e.printStackTrace();
479         }
480     }
481
482     // code for deploy objects
483

484     /* Create application mBean */
485     public void createAppMBean(Application application, String JavaDoc serverName,
486     String JavaDoc appLocation)
487         throws MBeanException {
488
489     // get the standard deployment descriptor file
490
String JavaDoc xmlDesc = null;
491
492         String JavaDoc j2eeDDLocation = application.getGeneratedXMLDirectory() +
493                                 File.separator +
494                                 DescriptorConstants.APPLICATION_DD_ENTRY;
495
496         // get the string for deployment descriptor file
497
xmlDesc = getStringForDDxml(j2eeDDLocation);
498
499         StartStopCallback sscb = new StartStopCallback();
500
501         J2EEModuleCallBackImpl module = new J2EEModuleCallBackImpl(
502                 application.getRegistrationName(),
503                 application.getRegistrationName(), serverName, xmlDesc, sscb);
504
505     J2EEApplicationMdl managedResource = new J2EEApplicationMdl(module, application);
506     instantiateAndRegisterRuntimeMBean( "J2EEApplication", managedResource,
507         application.getRegistrationName());
508
509     }
510
511     /* Delete application mBean */
512     public void deleteAppMBean(Application application, String JavaDoc serverName)
513         throws MBeanException {
514
515         try {
516         String JavaDoc namePattern =
517             (domain + ":" +
518             "j2eeType=J2EEApplication" + "," +
519             "name=" + application.getRegistrationName() + "," +
520             "J2EEServer=" + serverName + "," +
521             "*");
522
523         ObjectName objName = findObjectName(namePattern);
524
525         if (objName != null) {
526                     unregister(objName);
527         }
528         } catch (Exception JavaDoc e) {
529             throw new MBeanException(e);
530         }
531     }
532
533     /**
534      * Create application mBean modules
535      * J2EE Application may have several modules. According to JSR77
536      * spec. each module will have an mBean.
537      */

538     public void createAppMBeanModules(Application application,
539         String JavaDoc serverName, String JavaDoc appLocation) throws MBeanException {
540
541         boolean registerComponents = false;
542
543         // Register EJB modules
544
java.util.Set JavaDoc ejbBundles = application.getEjbBundleDescriptors();
545
546         for (Iterator it = ejbBundles.iterator(); it.hasNext();) {
547             EjbBundleDescriptor bundleDesc = (EjbBundleDescriptor) it.next();
548             registerEjbModuleAndItsComponents(bundleDesc, serverName,
549                 registerComponents, appLocation);
550         }
551
552     // Web module registration will be done within Tomcat container
553
// FIXME: when webcore based regn needs to be done during 8.0 SE/EE
554
// Register Web modules
555
/*
556         java.util.Set webBundles = application.getWebBundleDescriptors();
557
558         for (Iterator it = webBundles.iterator(); it.hasNext();) {
559             WebBundleDescriptor bundleDesc = (WebBundleDescriptor) it.next();
560             registerWebModuleAndItsComponents(bundleDesc, serverName,
561                 registerComponents, appLocation);
562         }
563     */

564
565         // Register RAR modules
566
java.util.Set JavaDoc rarBundles = application.getRarDescriptors();
567
568         for (Iterator it = rarBundles.iterator(); it.hasNext();) {
569             ConnectorDescriptor bundleDesc = (ConnectorDescriptor) it.next();
570             registerResourceAdapterModuleAndItsComponents(bundleDesc,
571                 serverName, registerComponents, appLocation);
572         }
573
574         // Register AppClient modules
575
java.util.Set JavaDoc appClientBundles = application.getApplicationClientDescriptors();
576
577         for (Iterator it = appClientBundles.iterator(); it.hasNext();) {
578             ApplicationClientDescriptor bundleDesc = (ApplicationClientDescriptor) it.next();
579             registerAppClient(bundleDesc, serverName, appLocation);
580         }
581     }
582
583     /**
584      * Register all the modules of the application and its' children
585      * objects.
586      */

587     public void createAppMBeans(Application application,
588         String JavaDoc serverName, String JavaDoc appLocation) throws MBeanException {
589
590         boolean registerComponents = true;
591
592         // Register EJB modules
593
java.util.Set JavaDoc ejbBundles = application.getEjbBundleDescriptors();
594
595         for (Iterator it = ejbBundles.iterator(); it.hasNext();) {
596             EjbBundleDescriptor bundleDesc = (EjbBundleDescriptor) it.next();
597             registerEjbModuleAndItsComponents(bundleDesc, serverName,
598                 registerComponents, appLocation);
599         }
600
601     // Web module registration will be done within Tomcat container
602
// FIXME: when webcore based regn needs to be done during 8.0 SE/EE
603
// Register Web modules
604
/*
605         java.util.Set webBundles = application.getWebBundleDescriptors();
606
607         for (Iterator it = webBundles.iterator(); it.hasNext();) {
608             WebBundleDescriptor bundleDesc = (WebBundleDescriptor) it.next();
609             registerWebModuleAndItsComponents(bundleDesc, serverName,
610                 registerComponents, appLocation);
611         }
612     */

613
614         // Register RAR modules
615
java.util.Set JavaDoc rarBundles = application.getRarDescriptors();
616
617         for (Iterator it = rarBundles.iterator(); it.hasNext();) {
618             ConnectorDescriptor bundleDesc = (ConnectorDescriptor) it.next();
619             registerResourceAdapterModuleAndItsComponents(bundleDesc,
620                 serverName, registerComponents, appLocation);
621         }
622
623         // Register AppClient modules
624
java.util.Set JavaDoc appClientBundles = application.getApplicationClientDescriptors();
625
626         for (Iterator it = appClientBundles.iterator(); it.hasNext();) {
627             ApplicationClientDescriptor bundleDesc = (ApplicationClientDescriptor) it.next();
628             registerAppClient(bundleDesc, serverName, appLocation);
629         }
630     }
631
632     /* Register ejb module and its' children ejbs which is part of an application */
633     public void registerEjbModuleAndItsComponents(
634         EjbBundleDescriptor ejbBundleDescriptor, String JavaDoc serverName,
635         boolean registerComponents, String JavaDoc appLocation) throws MBeanException {
636
637
638         createEJBModuleMBean(ejbBundleDescriptor, serverName, appLocation);
639
640         if (registerComponents) {
641             createEJBMBeans(ejbBundleDescriptor, serverName);
642         }
643     }
644
645     /* Register web module and its' children which is part of an application */
646     public void registerWebModuleAndItsComponents(
647         WebBundleDescriptor webBundleDescriptor, String JavaDoc serverName,
648         boolean registerComponents, String JavaDoc appLocation) throws MBeanException {
649
650     // get the string for deployment descriptor file
651
String JavaDoc xmlDesc = getStringForDDxml(
652                 getModuleLocation(webBundleDescriptor, "WebModule"));
653
654         String JavaDoc applicationName = "null";
655
656         if (webBundleDescriptor.getApplication() != null) {
657             if (!webBundleDescriptor.getModuleDescriptor().isStandalone()) {
658                 applicationName = webBundleDescriptor.getApplication()
659                                                      .getRegistrationName();
660
661                 if (applicationName == null) {
662                     applicationName = "null";
663                 }
664             }
665         }
666
667         createWebModuleMBean(webBundleDescriptor.getModuleID(),
668             applicationName, serverName, xmlDesc);
669
670         if (registerComponents) {
671             createWebMBeans(webBundleDescriptor, serverName);
672         }
673         try {
674             createWSEndpointMBeans(webBundleDescriptor, serverName);
675         } catch (MBeanException mbe) {
676             _logger.log(Level.WARNING,
677                 "admin.registerWebModuleAndItsComponents exception", mbe);
678         }
679     }
680
681     /* Register connector module and its' children which is part of an application */
682     public void registerResourceAdapterModuleAndItsComponents(
683         ConnectorDescriptor bundleDesc, String JavaDoc serverName,
684         boolean registerComponents, String JavaDoc appLocation) throws MBeanException {
685
686
687
688         createRARModuleMBean(bundleDesc, serverName, appLocation);
689
690         if (registerComponents) {
691             createRARMBeans(bundleDesc, serverName);
692         }
693     }
694
695     /* Register application client module */
696     public void registerAppClient(
697         ApplicationClientDescriptor bundleDesc, String JavaDoc serverName,
698     String JavaDoc appLocation)
699         throws MBeanException {
700
701     // get the string for deployment descriptor file
702
String JavaDoc xmlDesc = getStringForDDxml(
703                 getModuleLocation(bundleDesc, "AppClientModule"));
704
705         String JavaDoc applicationName = "null";
706
707         if (bundleDesc.getApplication() != null) {
708             if (!bundleDesc.getModuleDescriptor().isStandalone()) {
709                 applicationName = bundleDesc.getApplication()
710                                             .getRegistrationName();
711
712                 if (applicationName == null) {
713                     applicationName = "null";
714                 }
715             }
716         }
717
718         createAppClientModuleMBean(getModuleName(bundleDesc), applicationName,
719             serverName, xmlDesc);
720     }
721
722     /* Unregister application client module */
723     public void unregisterAppClient(
724         ApplicationClientDescriptor bundleDesc, String JavaDoc serverName)
725         throws MBeanException {
726
727         String JavaDoc applicationName = "null";
728
729         if (bundleDesc.getApplication() != null) {
730             if (!bundleDesc.getModuleDescriptor().isStandalone()) {
731                 applicationName = bundleDesc.getApplication()
732                                             .getRegistrationName();
733
734                 if (applicationName == null) {
735                     applicationName = "null";
736                 }
737             }
738         }
739
740         deleteAppClientModuleMBean(getModuleName(bundleDesc), applicationName,
741             serverName);
742     }
743
744
745     /* Delete all mbeans of the application including modules and its' children */
746     public void deleteAppMBeans(Application application,
747         String JavaDoc serverName) throws MBeanException {
748
749         try {
750         String JavaDoc namePattern =
751             (domain + ":" +
752             "j2eeType=J2EEApplication" + "," +
753             "name=" + application.getRegistrationName() + "," +
754             "J2EEServer=" + serverName + "," +
755             "*");
756
757         ObjectName objName = findObjectName(namePattern);
758
759         if (objName != null) {
760                 String JavaDoc[] modulesArr = (String JavaDoc[]) server.getAttribute(objName,
761                     "modules");
762                 ObjectName[] deployedModules = toObjectNameArray(modulesArr);
763
764                 for (int moduleIndex = 0; moduleIndex < deployedModules.length;
765                     moduleIndex++) {
766                     unregisterModuleAndItsComponents(deployedModules[moduleIndex]);
767                 }
768         }
769         } catch (Exception JavaDoc e) {
770             throw new MBeanException(e);
771         }
772     }
773
774     /* used by deleteAppMBeans */
775     public void unregisterModuleAndItsComponents(ObjectName objectName)
776         throws MBeanException {
777
778         // unregister its components
779
ObjectName[] comps = getComponents(objectName);
780
781         for (int compsIndex = 0; compsIndex < comps.length; compsIndex++) {
782             unregister(comps[compsIndex]);
783         }
784
785         // unregister module itself
786
unregister(objectName);
787     }
788
789     /* Get child components of a given object say module */
790     private ObjectName[] getComponents(ObjectName module)
791         throws MBeanException {
792
793         ObjectName[] components = null;
794
795         try {
796           if (module.getKeyProperty("j2eeType").equals("AppClientModule")) {
797             // There should not be any components for app client module
798
components = new ObjectName[] { };
799           } else if (module.getKeyProperty("j2eeType").equals("EJBModule")) {
800             components = toObjectNameArray((String JavaDoc[]) server.getAttribute(
801                         module, "ejbs"));
802           } else if (module.getKeyProperty("j2eeType").equals("WebModule")) {
803             components = toObjectNameArray((String JavaDoc[]) server.getAttribute(
804                         module, "servlets"));
805           } else if (module.getKeyProperty("j2eeType").equals("ResourceAdapterModule")) {
806             components = toObjectNameArray((String JavaDoc[]) server.getAttribute(
807                         module, "resourceAdapters"));
808           }
809         } catch (Exception JavaDoc e) {
810           throw new MBeanException(e);
811         }
812
813         return components;
814     }
815
816     /* Create ejb module mBean */
817     public void createEJBModuleMBean(EjbBundleDescriptor ejbBundleDescriptor,
818         String JavaDoc serverName, String JavaDoc appLocation) throws MBeanException {
819
820
821     // get the string for deployment descriptor file
822
String JavaDoc xmlDesc = getStringForDDxml(
823                 getModuleLocation(ejbBundleDescriptor, "EJBModule"));
824
825         String JavaDoc moduleName = getModuleName(ejbBundleDescriptor);
826         String JavaDoc applicationName = getApplicationName(ejbBundleDescriptor);
827
828         StartStopCallback sscb = new StartStopCallback();
829         J2EEModuleCallBackImpl module = new J2EEModuleCallBackImpl(moduleName,
830                 applicationName, serverName, xmlDesc, sscb);
831
832     EJBModuleMdl managedResource = new EJBModuleMdl(module, ejbBundleDescriptor);
833
834     instantiateAndRegisterRuntimeMBean( "EJBModule", managedResource,
835         null, applicationName, moduleName);
836         try {
837             createWSEndpointMBeans(ejbBundleDescriptor, serverName);
838         } catch (MBeanException mbe) {
839             _logger.log(Level.WARNING,
840                 "admin.registerEjbModuleAndItsComponents exception", mbe);
841         }
842     }
843
844     /* Delete ejb module mBean */
845     public void deleteEJBModuleMBean(EjbBundleDescriptor ejbBundleDescriptor,
846         String JavaDoc serverName) throws MBeanException {
847
848
849         String JavaDoc moduleName = getModuleName(ejbBundleDescriptor);
850         String JavaDoc applicationName = getApplicationName(ejbBundleDescriptor);
851
852         try {
853         String JavaDoc namePattern =
854             (domain + ":" +
855             "j2eeType=EJBModule" + "," +
856             "name=" + moduleName + "," +
857             "J2EEApplication=" + applicationName + "," +
858             "J2EEServer=" + serverName + "," +
859             "*");
860
861         ObjectName objName = findObjectName(namePattern);
862
863             if (objName != null) {
864                     unregister(objName);
865             }
866         } catch (Exception JavaDoc e) {
867             throw new MBeanException(e);
868         }
869     }
870
871     /* Create ejb mBeans within a given bundle descriptor */
872     public void createEJBMBeans(
873         EjbBundleDescriptor ejbBundleDescriptor, String JavaDoc serverName)
874         throws MBeanException {
875
876
877         //Vector beanDescriptors = application.getEjbDescriptors();
878
java.util.Set JavaDoc ejbs = ejbBundleDescriptor.getEjbs();
879
880         for (Iterator it = ejbs.iterator(); it.hasNext();) {
881             EjbDescriptor nextDescriptor = (EjbDescriptor) it.next();
882
883             createEJBMBean(nextDescriptor, serverName);
884         }
885     }
886
887     /* Delete ejb mBeans within a given bundle descriptor */
888     public void deleteEJBMBeans(
889         EjbBundleDescriptor ejbBundleDescriptor, String JavaDoc serverName)
890         throws MBeanException {
891
892
893         java.util.Set JavaDoc ejbs = ejbBundleDescriptor.getEjbs();
894
895         for (Iterator it = ejbs.iterator(); it.hasNext();) {
896
897             EjbDescriptor nextDescriptor = (EjbDescriptor) it.next();
898
899             deleteEJBMBean(nextDescriptor, serverName);
900         }
901
902     }
903
904     /**
905      * Creates all the web service endpoint runtime mbeans for the web or
906      * ejb bundle.
907      *
908      * @param bundleDescriptor descriptor of the web/ejb bundle
909      * @param serverName instance on which these mbeans are created
910      *
911      * @throws MBeanException incase of error
912      */

913     public void createWSEndpointMBeans(
914         BundleDescriptor bundleDescriptor, String JavaDoc serverName)
915         throws MBeanException {
916
917         if ( bundleDescriptor == null) {
918             return;
919         }
920
921         String JavaDoc ctxRoot = null;
922         if ( bundleDescriptor instanceof WebBundleDescriptor) {
923             ctxRoot = ((WebBundleDescriptor) bundleDescriptor).getContextRoot();
924         }
925
926         WebServicesDescriptor wss = bundleDescriptor.getWebServices();
927         if ( wss != null) {
928             java.util.Collection JavaDoc wsEps = wss.getEndpoints();
929
930             for (Iterator it = wsEps.iterator(); it.hasNext();) {
931                 WebServiceEndpoint nextDescriptor =
932                         (WebServiceEndpoint) it.next();
933
934                 createWSEndpointMBean(ctxRoot, nextDescriptor, serverName);
935             }
936         }
937     }
938
939     /**
940      * Deletes all the web service endpoint runtime mbeans for the web or
941      * ejb bundle.
942      *
943      * @param bundleDescriptor descriptor of the web/ejb bundle
944      * @param serverName instance on which these mbeans are deleted
945      *
946      * @throws MBeanException incase of error
947      */

948     public void deleteWSEndpointMBeans(
949         BundleDescriptor bundleDescriptor, String JavaDoc serverName)
950         throws MBeanException {
951
952         if ( bundleDescriptor == null) {
953             return;
954         }
955
956         String JavaDoc ctxRoot = null;
957         if ( bundleDescriptor instanceof WebBundleDescriptor) {
958             ctxRoot = ((WebBundleDescriptor) bundleDescriptor).getContextRoot();
959         }
960
961         WebServicesDescriptor wsd = bundleDescriptor.getWebServices();
962         if ( wsd == null) {
963             return;
964         }
965
966         java.util.Collection JavaDoc wsEps = wsd.getEndpoints();
967
968         for (Iterator it = wsEps.iterator(); it.hasNext();) {
969             WebServiceEndpoint nextDescriptor = (WebServiceEndpoint) it.next();
970
971             try {
972                 deleteWSEndpointMBean(ctxRoot, nextDescriptor, serverName);
973             } catch (MBeanException mbe) {
974                 _logger.log(Level.WARNING,
975                     "admin.deleteEJBMBeans exception", mbe);
976             }
977         }
978
979
980     }
981
982     /* Create mBean for a given ejb and register it with mBean server*/
983     public void createEJBMBean(EjbDescriptor ejbDescriptor, String JavaDoc serverName)
984         throws MBeanException {
985
986
987         String JavaDoc ejbName = ejbDescriptor.getName();
988         String JavaDoc ejbType = ejbDescriptor.getType();
989         String JavaDoc ejbSessionType = null;
990         if (ejbType.equals("Session")) {
991             ejbSessionType = ((EjbSessionDescriptor) ejbDescriptor).getSessionType();
992     }
993
994         String JavaDoc moduleName = getModuleName(ejbDescriptor.getEjbBundleDescriptor());
995         String JavaDoc appName = getApplicationName(ejbDescriptor.getEjbBundleDescriptor());
996
997         Object JavaDoc ejbMB = null;
998         String JavaDoc j2eeType = null;
999
1000        if (ejbType.equals("Entity")) {
1001            j2eeType = "EntityBean";
1002        } else if (ejbType.equals("Message-driven")) {
1003            j2eeType = "MessageDrivenBean";
1004        } else if (ejbType.equals("Session")) {
1005            if (ejbSessionType.equals("Stateless")) {
1006                j2eeType = "StatelessSessionBean";
1007            } else if (ejbSessionType.equals("Stateful")) {
1008                j2eeType = "StatefulSessionBean";
1009            }
1010        }
1011
1012        if (ejbType.equals("Entity")) {
1013        EntityBeanMdl managedResource =
1014        new EntityBeanMdl(ejbName, moduleName, appName, serverName);
1015        instantiateAndRegisterRuntimeMBean("EntityBean", managedResource,
1016        appName, moduleName, ejbName);
1017        } else if (ejbType.equals("Message-driven")) {
1018        MessageDrivenBeanMdl managedResource =
1019        new MessageDrivenBeanMdl(
1020        ejbName, moduleName, appName, serverName);
1021        instantiateAndRegisterRuntimeMBean("MessageDrivenBean", managedResource,
1022        appName, moduleName, ejbName);
1023        } else if (ejbType.equals("Session")) {
1024            if (ejbSessionType.equals("Stateless")) {
1025            StatelessSessionBeanMdl managedResource =
1026            new StatelessSessionBeanMdl(
1027            ejbName, moduleName, appName, serverName);
1028            instantiateAndRegisterRuntimeMBean("StatelessSessionBean", managedResource,
1029            appName, moduleName, ejbName);
1030            } else if (ejbSessionType.equals("Stateful")) {
1031            StatefulSessionBeanMdl managedResource =
1032            new StatefulSessionBeanMdl(
1033            ejbName, moduleName, appName, serverName);
1034            instantiateAndRegisterRuntimeMBean("StatefulSessionBean", managedResource,
1035            appName, moduleName, ejbName);
1036            }
1037        }
1038
1039    }
1040
1041    /* Delete the mBean for a given ejb and unregister it from mBean server */
1042    public void deleteEJBMBean(EjbDescriptor ejbDescriptor, String JavaDoc serverName)
1043        throws MBeanException {
1044
1045
1046        String JavaDoc ejbName = ejbDescriptor.getName();
1047        String JavaDoc ejbType = ejbDescriptor.getType();
1048        String JavaDoc ejbSessionType = null;
1049        if (ejbType.equals("Session")) {
1050            ejbSessionType = ((EjbSessionDescriptor) ejbDescriptor).getSessionType();
1051    }
1052
1053        String JavaDoc moduleName = getModuleName(ejbDescriptor.getEjbBundleDescriptor());
1054        String JavaDoc appName = getApplicationName(ejbDescriptor.getEjbBundleDescriptor());
1055
1056        String JavaDoc j2eeType = null;
1057
1058        if (ejbType.equals("Entity")) {
1059            j2eeType = "EntityBean";
1060        } else if (ejbType.equals("Message-driven")) {
1061            j2eeType = "MessageDrivenBean";
1062        } else if (ejbType.equals("Session")) {
1063            if (ejbSessionType.equals("Stateless")) {
1064                j2eeType = "StatelessSessionBean";
1065            } else if (ejbSessionType.equals("Stateful")) {
1066                j2eeType = "StatefulSessionBean";
1067            }
1068        }
1069
1070        try {
1071        String JavaDoc namePattern =
1072            (domain + ":" +
1073            "j2eeType=" + j2eeType + "," +
1074            "name=" + ejbName + "," +
1075            "EJBModule=" + moduleName + "," +
1076            "J2EEApplication=" + appName + "," +
1077            "J2EEServer=" + serverName + "," +
1078            "*");
1079
1080        ObjectName objName = findObjectName(namePattern);
1081
1082            if (objName != null) {
1083                    unregister(objName);
1084            }
1085        } catch (Exception JavaDoc e) {
1086            throw new MBeanException(e);
1087        }
1088    }
1089
1090    /**
1091     * Creates the specified web service endpoint runtime mbean
1092     *
1093     * @param ctxRoot context root for this web service endpoint
1094     * @param descriptor descriptor of the web service endpoint
1095     * @param serverName instance on which these mbean is created
1096     *
1097     * @throws MBeanException incase of error
1098     */

1099    public void createWSEndpointMBean(String JavaDoc ctxRoot,
1100     WebServiceEndpoint wsDescriptor,
1101        String JavaDoc serverName) throws MBeanException {
1102
1103
1104        BundleDescriptor bd = wsDescriptor.getBundleDescriptor();
1105        boolean isEjb = false;
1106
1107        if ( bd instanceof EjbBundleDescriptor) {
1108            isEjb = true;
1109        }
1110
1111        String JavaDoc epName = wsDescriptor.getEndpointName();
1112        String JavaDoc appName = getApplicationName(bd);
1113        String JavaDoc regName = bd.getApplication().getRegistrationName();
1114        String JavaDoc moduleName = getModuleName(bd);
1115
1116        if (ctxRoot != null ) {
1117            ServletWebServiceEndpointMdl managedResource =
1118                new ServletWebServiceEndpointMdl(epName, moduleName, regName,
1119                    serverName, bd.getApplication().isVirtual(), isEjb);
1120            String JavaDoc cRoot = null;
1121            if (( ctxRoot.length() > 0) && (ctxRoot.charAt(0) != '/')){
1122                cRoot = "/" + ctxRoot;
1123            } else {
1124                cRoot = ctxRoot;
1125            }
1126            instantiateAndRegisterRuntimeMBean(managedResource.getMBeanName(),
1127             managedResource, appName, WebModuleSupport.VIRTUAL_SERVER_PREFIX
1128             + DEFAULT_VIRTUAL_SERVER + cRoot, epName);
1129        } else {
1130            EJBWebServiceEndpointMdl managedResource =
1131            new EJBWebServiceEndpointMdl(epName, moduleName,regName, serverName,
1132             bd.getApplication().isVirtual(),isEjb);
1133            instantiateAndRegisterRuntimeMBean(managedResource.getMBeanName(),
1134            managedResource, appName, moduleName, epName);
1135        }
1136    }
1137
1138    /**
1139     * Deletes the specified web service endpoint runtime mbean
1140     *
1141     * @param descriptor descriptor of the web service endpoint
1142     * @param serverName instance on which these mbean is deleted
1143     *
1144     * @throws MBeanException incase of error
1145     */

1146    public void deleteWSEndpointMBean(String JavaDoc ctxRoot,
1147        WebServiceEndpoint wsDescriptor, String JavaDoc serverName)
1148        throws MBeanException {
1149
1150        String JavaDoc epName = wsDescriptor.getEndpointName();
1151        BundleDescriptor bd = wsDescriptor.getBundleDescriptor();
1152
1153        String JavaDoc moduleName = getModuleName(bd);
1154        String JavaDoc appName = getApplicationName(bd);
1155
1156        try {
1157        String JavaDoc namePattern = null;
1158
1159        if ( bd instanceof EjbBundleDescriptor) {
1160            namePattern = (domain + ":" +
1161            "j2eeType=WebServiceEndpoint," +
1162            "name=" + epName + "," +
1163            "EJBModule=" + moduleName + "," +
1164            "J2EEApplication=" + appName + "," +
1165            "J2EEServer=" + serverName + "," +
1166            "*");
1167        } else if ( bd instanceof WebBundleDescriptor) {
1168            namePattern = (domain + ":" +
1169            "j2eeType=WebServiceEndpoint," +
1170            "name=" + epName + "," +
1171            "WebModule=" + WebModuleSupport.VIRTUAL_SERVER_PREFIX
1172             + DEFAULT_VIRTUAL_SERVER + ctxRoot + "," +
1173            "J2EEApplication=" + appName + "," +
1174            "J2EEServer=" + serverName + "," +
1175            "*");
1176        }
1177
1178        ObjectName objName = findObjectName(namePattern);
1179
1180            if (objName != null) {
1181                    unregister(objName);
1182            }
1183        } catch (Exception JavaDoc e) {
1184            throw new MBeanException(e);
1185        }
1186    }
1187
1188    /* Create mBean for the given web module and register it with mBean server */
1189    /*
1190    public WebModuleMBean getWebModuleMBean(String appName, String parentName,
1191        String serverName, String deploymentDescriptor) {
1192
1193        StartStopCallback sscb = new StartStopCallback();
1194        J2EEModuleCallBackImpl module = new J2EEModuleCallBackImpl(appName,
1195                parentName, serverName, deploymentDescriptor, sscb);
1196        WebModuleMBean webModMB = new WebModuleMBean(module);
1197
1198        return webModMB;
1199    }
1200    */

1201
1202
1203    /* Create mBean for the given web module and register it with mBean server */
1204    public void createWebModuleMBean(String JavaDoc appName, String JavaDoc parentName,
1205        String JavaDoc serverName, String JavaDoc deploymentDescriptor)
1206        throws MBeanException {
1207
1208        StartStopCallback sscb = new StartStopCallback();
1209        J2EEModuleCallBackImpl module = new J2EEModuleCallBackImpl(appName,
1210                parentName, serverName, deploymentDescriptor, sscb);
1211
1212        WebModuleMdl managedResource = new WebModuleMdl(module);
1213
1214        instantiateAndRegisterRuntimeMBean( "WebModule", managedResource,
1215        null, parentName, appName);
1216    }
1217
1218    /* Delete mBean for the given web module by unregistering it from mBean server */
1219    public void deleteWebModuleMBean(String JavaDoc appName, String JavaDoc parentName,
1220        String JavaDoc serverName) throws MBeanException {
1221
1222        try {
1223        String JavaDoc namePattern =
1224            (domain + ":" +
1225            "j2eeType=WebModule" + "," +
1226            "name=" + appName + "," +
1227            "J2EEApplication=" + parentName + "," +
1228            "J2EEServer=" + serverName + "," +
1229            "*");
1230
1231        ObjectName objName = findObjectName(namePattern);
1232
1233            if (objName != null) {
1234                    unregister(objName);
1235            }
1236        } catch (Exception JavaDoc e) {
1237            throw new MBeanException(e);
1238        }
1239    }
1240
1241    /* Create all web mBeans within the given webBundleDescriptor */
1242    public void createWebMBeans(
1243        WebBundleDescriptor webBundleDescriptor, String JavaDoc serverName)
1244        throws MBeanException {
1245
1246        Set set = webBundleDescriptor.getWebComponentDescriptorsSet();
1247
1248        String JavaDoc applicationName = webBundleDescriptor.getApplication()
1249                                                    .getRegistrationName();
1250
1251        if (applicationName == null) {
1252            applicationName = "null";
1253        }
1254
1255        for (Iterator it = set.iterator(); it.hasNext();) {
1256            WebComponentDescriptor nextDescriptor = (WebComponentDescriptor) it.next();
1257            createWebMBean(nextDescriptor.getCanonicalName(),
1258                webBundleDescriptor.getModuleID(), applicationName, serverName);
1259        }
1260    }
1261
1262    /* Delete all web mBeans within the given webBundleDescriptor */
1263    public void deleteWebMBeans(
1264        WebBundleDescriptor webBundleDescriptor, String JavaDoc serverName)
1265        throws MBeanException {
1266
1267        Set set = webBundleDescriptor.getWebComponentDescriptorsSet();
1268
1269        String JavaDoc applicationName = webBundleDescriptor.getApplication()
1270                                                    .getRegistrationName();
1271
1272        if (applicationName == null) {
1273            applicationName = "null";
1274        }
1275
1276        for (Iterator it = set.iterator(); it.hasNext();) {
1277            WebComponentDescriptor nextDescriptor = (WebComponentDescriptor) it.next();
1278            deleteWebMBean(nextDescriptor.getCanonicalName(),
1279                webBundleDescriptor.getModuleID(), applicationName, serverName);
1280        }
1281    }
1282
1283    /* Create mBean for the given servlet */
1284    public void createWebMBean(String JavaDoc servletName, String JavaDoc moduleName,
1285        String JavaDoc appName, String JavaDoc serverName) throws MBeanException {
1286
1287    ServletMdl managedResource = new ServletMdl(servletName, moduleName,
1288        appName, serverName);
1289
1290        instantiateAndRegisterRuntimeMBean( "Servlet", managedResource,
1291            appName, moduleName, servletName);
1292
1293    }
1294
1295    /* Delete mBean for the given servlet */
1296    public void deleteWebMBean(String JavaDoc servletName, String JavaDoc moduleName,
1297        String JavaDoc appName, String JavaDoc serverName) throws MBeanException {
1298
1299        if (server == null) {
1300            initMBeanServer();
1301        }
1302
1303        try {
1304        String JavaDoc namePattern =
1305            (domain + ":" +
1306            "j2eeType=Servlet" + "," +
1307            "name=" + servletName + "," +
1308            "WebModule=" + moduleName + "," +
1309            "J2EEApplication=" + appName + "," +
1310            "J2EEServer=" + serverName + "," +
1311            "*");
1312        ObjectName objName = findObjectName(namePattern);
1313
1314            if (objName != null) {
1315                    unregister(objName);
1316            }
1317        } catch (Exception JavaDoc e) {
1318            throw new MBeanException(e);
1319        }
1320    }
1321
1322    /* Create mBean for the given connector module */
1323    public void createRARModuleMBean(ConnectorDescriptor bundleDesc,
1324        String JavaDoc serverName, String JavaDoc appLocation) throws MBeanException {
1325
1326    // get the string for deployment descriptor file
1327

1328    // fix for CTS bug# 6411637
1329
// if resource adapter module name is one of connector system apps
1330
// then set the location of deployment descriptor to the original
1331
// location and not the generated directory. These system apps are
1332
// directly loaded without generating descriptors
1333

1334        String JavaDoc modLocation = "";
1335    if (bundleDesc.getModuleDescriptor().isStandalone()) {
1336            modLocation = appLocation + File.separator +
1337                DescriptorConstants.RAR_DD_ENTRY;
1338        } else {
1339        String JavaDoc moduleName = FileUtils.makeFriendlyFileName(
1340             bundleDesc.getModuleDescriptor().getArchiveUri());
1341        modLocation = appLocation + File.separator + moduleName + File.separator +
1342              DescriptorConstants.RAR_DD_ENTRY;
1343        }
1344
1345        String JavaDoc xmlDesc = getStringForDDxml(modLocation);
1346
1347        String JavaDoc applicationName = getApplicationName(bundleDesc);
1348
1349        String JavaDoc resAdName = getModuleName(bundleDesc);
1350
1351        StartStopCallback sscb = new StartStopCallback();
1352        J2EEModuleCallBackImpl module = new J2EEModuleCallBackImpl(resAdName,
1353                applicationName, serverName, xmlDesc, sscb);
1354
1355    ResourceAdapterModuleMdl managedResource =
1356        new ResourceAdapterModuleMdl(module, resAdName);
1357
1358    instantiateAndRegisterRuntimeMBean( "ResourceAdapterModule", managedResource,
1359        null, applicationName, resAdName);
1360
1361    }
1362
1363    /* Delete mBean for the given connector module */
1364    public void deleteRARModuleMBean(ConnectorDescriptor cd,
1365        String JavaDoc serverName) throws MBeanException {
1366
1367
1368        String JavaDoc moduleName = getModuleName(cd);
1369        String JavaDoc applicationName = getApplicationName(cd);
1370
1371        try {
1372        String JavaDoc namePattern =
1373            (domain + ":" +
1374            "j2eeType=ResourceAdapterModule" + "," +
1375            "name=" + moduleName + "," +
1376            "J2EEApplication=" + applicationName + "," +
1377            "J2EEServer=" + serverName + "," +
1378            "*");
1379
1380        ObjectName objName = findObjectName(namePattern);
1381
1382            if (objName != null) {
1383                    unregister(objName);
1384            }
1385        } catch (Exception JavaDoc e) {
1386            throw new MBeanException(e);
1387        }
1388    }
1389
1390    /* Create all mBeans for the given connector descriptor */
1391    public void createRARMBeans(ConnectorDescriptor cd,
1392        String JavaDoc serverName) throws MBeanException {
1393
1394        createRARMBean(cd, serverName);
1395    }
1396
1397    /* Delete all mBeans for the given connector descriptor */
1398    public void deleteRARMBeans(ConnectorDescriptor cd,
1399        String JavaDoc serverName) throws MBeanException {
1400
1401
1402        deleteRARMBean(cd, serverName);
1403    }
1404
1405    /* Create mBean for the given connector */
1406    public void createRARMBean(ConnectorDescriptor cd,
1407        String JavaDoc serverName) throws MBeanException {
1408
1409
1410        String JavaDoc rarName = cd.getName();
1411        String JavaDoc moduleName = getModuleName(cd);
1412        String JavaDoc appName = getApplicationName(cd);
1413
1414    ResourceAdapterMdl managedResource =
1415        new ResourceAdapterMdl(rarName, moduleName, appName, serverName);
1416
1417    instantiateAndRegisterRuntimeMBean( "ResourceAdapter", managedResource,
1418        appName, moduleName, rarName);
1419
1420    }
1421
1422    /* Delete mBean for the given connector */
1423    public void deleteRARMBean(ConnectorDescriptor cd,
1424        String JavaDoc serverName) throws MBeanException {
1425
1426
1427        String JavaDoc rarName = cd.getName();
1428        String JavaDoc moduleName = getModuleName(cd);
1429        String JavaDoc appName = getApplicationName(cd);
1430
1431        try {
1432        String JavaDoc namePattern =
1433            (domain + ":" +
1434            "j2eeType=ResourceAdapter" + "," +
1435            "name=" + rarName + "," +
1436            "ResourceAdapterModule=" + moduleName + "," +
1437            "J2EEApplication=" + appName + "," +
1438            "J2EEServer=" + serverName + "," +
1439            "*");
1440        ObjectName objName = findObjectName(namePattern);
1441
1442            if (objName != null) {
1443                    unregister(objName);
1444            }
1445        } catch (Exception JavaDoc e) {
1446            throw new MBeanException(e);
1447        }
1448    }
1449
1450    /* Create mBean for the given application client module */
1451    public void createAppClientModuleMBean(String JavaDoc appName,
1452        String JavaDoc parentName, String JavaDoc serverName, String JavaDoc deploymentDescriptor)
1453        throws MBeanException {
1454
1455        StartStopCallback sscb = new StartStopCallback();
1456        J2EEModuleCallBackImpl module = new J2EEModuleCallBackImpl(appName,
1457                parentName, serverName, deploymentDescriptor, sscb);
1458
1459    AppClientModuleMdl managedResource = new AppClientModuleMdl(module);
1460    instantiateAndRegisterRuntimeMBean( "AppClientModule", managedResource,
1461        null, parentName, appName);
1462    }
1463
1464    /* Delete mBean for the given application client module */
1465    public void deleteAppClientModuleMBean(String JavaDoc applicationName,
1466        String JavaDoc parentName, String JavaDoc serverName) throws MBeanException {
1467
1468        try {
1469        String JavaDoc namePattern =
1470            (domain + ":" +
1471            "j2eeType=AppClientModule" + "," +
1472            "name=" + applicationName + "," +
1473            "J2EEApplication=" + parentName + "," +
1474            "J2EEServer=" + serverName + "," +
1475            "*");
1476        ObjectName objName = findObjectName(namePattern);
1477            if (objName != null) {
1478                    unregister(objName);
1479            }
1480        } catch (Exception JavaDoc e) {
1481            throw new MBeanException(e);
1482        }
1483    }
1484
1485    /* Set state for the given application */
1486    public void setApplicationState(int state, Application application,
1487        String JavaDoc serverName) throws MBeanException {
1488
1489        String JavaDoc applicationName = application.getRegistrationName();
1490    String JavaDoc namePattern =
1491        (domain + ":" +
1492         "j2eeType=J2EEApplication" + "," +
1493         "name=" + applicationName + "," +
1494         "J2EEServer=" + serverName + "," +
1495         "*");
1496    ObjectName objName = findObjectName(namePattern);
1497    if (objName != null) {
1498        setState(objName, state);
1499    }
1500    }
1501
1502    /* Set state for the connector module */
1503    public void setRARModuleState(int state, ConnectorDescriptor connectorDescriptor,
1504        String JavaDoc serverName) throws MBeanException {
1505
1506        String JavaDoc moduleName = getModuleName(connectorDescriptor);
1507        String JavaDoc applicationName = getApplicationName(connectorDescriptor);
1508    String JavaDoc namePattern =
1509        (domain + ":" +
1510         "j2eeType=ResourceAdapterModule" + "," +
1511         "name=" + moduleName + "," +
1512         "J2EEApplication=" + applicationName + "," +
1513         "J2EEServer=" + serverName + "," +
1514         "*");
1515    ObjectName objName = findObjectName(namePattern);
1516    if (objName != null) {
1517        setState(objName, state);
1518    }
1519    }
1520
1521
1522    /* Set state for the ejb module */
1523    public void setEJBModuleState(int state, EjbBundleDescriptor ejbBundleDescriptor,
1524        String JavaDoc serverName) throws MBeanException {
1525
1526        String JavaDoc moduleName = getModuleName(ejbBundleDescriptor);
1527        String JavaDoc applicationName = getApplicationName(ejbBundleDescriptor);
1528    String JavaDoc namePattern =
1529        (domain + ":" +
1530         "j2eeType=EJBModule" + "," +
1531         "name=" + moduleName + "," +
1532         "J2EEApplication=" + applicationName + "," +
1533         "J2EEServer=" + serverName + "," +
1534         "*");
1535    ObjectName objName = findObjectName(namePattern);
1536    if (objName != null) {
1537        setState(objName, state);
1538    }
1539    }
1540
1541    /**
1542     * Set state for the given object name array
1543     * corresponding to a module or application
1544     */

1545
1546    private void setState(ObjectName objName, int state) throws MBeanException {
1547        try {
1548            if (server.isRegistered(objName)) {
1549                Integer JavaDoc stateValueObj = new Integer JavaDoc(state);
1550                server.setAttribute(objName,
1551                    (new javax.management.Attribute JavaDoc("state", stateValueObj)));
1552            }
1553        } catch (javax.management.InstanceNotFoundException JavaDoc infe) {
1554        } catch (Exception JavaDoc e) {
1555            throw new MBeanException(e);
1556        }
1557    }
1558
1559
1560    /* Get state for the given name pattern */
1561    public Integer JavaDoc getState(String JavaDoc namePattern) throws MBeanException {
1562    ObjectName objName = findObjectName(namePattern);
1563    if (objName != null) {
1564            try {
1565        Integer JavaDoc intObj = (Integer JavaDoc) server.getAttribute(objName, "state");
1566        return intObj;
1567        } catch (javax.management.InstanceNotFoundException JavaDoc infe) {
1568            } catch (Exception JavaDoc e) {
1569                throw new MBeanException(e);
1570        }
1571    }
1572    return null;
1573    }
1574
1575
1576    /* Register a given object name with the mBean server */
1577    private void register(Object JavaDoc object, ObjectName objectName)
1578        throws MBeanException {
1579        if (server == null) {
1580            initMBeanServer();
1581        }
1582
1583        try {
1584            if (!server.isRegistered(objectName)) {
1585                server.registerMBean(object, objectName);
1586            }
1587        } catch (Exception JavaDoc e) {
1588            throw new MBeanException(e);
1589        }
1590    }
1591
1592    /* Unregister a given object name from the mBean server */
1593    public void unregister(ObjectName objectName)
1594        throws MBeanException {
1595
1596        try {
1597            if (server.isRegistered(objectName)) {
1598                server.unregisterMBean(objectName);
1599            }
1600        } catch (javax.management.InstanceNotFoundException JavaDoc infe) {
1601        } catch (Exception JavaDoc e) {
1602            throw new MBeanException(e);
1603        }
1604    }
1605
1606    /**
1607     * Returns array of javax.management.ObjectName corresponding to the
1608     * given string array of object names
1609     */

1610    public ObjectName[] toObjectNameArray(String JavaDoc[] strings)
1611        throws MBeanException {
1612        // It could be possible that strings are null
1613
if (strings != null) {
1614            ObjectName[] objectNames = new ObjectName[strings.length];
1615
1616            for (int i = 0; i < strings.length; i++) {
1617                try {
1618                    objectNames[i] = new ObjectName(strings[i]);
1619                } catch (MalformedObjectNameException mne) {
1620                    throw new MBeanException(mne);
1621                }
1622            }
1623
1624            return objectNames;
1625        }
1626
1627        // return an empty array
1628
return new ObjectName[] { };
1629    }
1630
1631    /* get module name for connector module */
1632    public String JavaDoc getModuleName(BundleDescriptor bd)
1633        throws MBeanException {
1634
1635    String JavaDoc moduleName = null;
1636
1637    if (bd.getModuleDescriptor().isStandalone()) {
1638        moduleName = bd.getApplication().getRegistrationName();
1639    } else {
1640        moduleName = bd.getModuleDescriptor().getArchiveUri();
1641    }
1642
1643    return moduleName;
1644
1645    }
1646
1647
1648    /* get module location */
1649    private String JavaDoc getModuleLocation(BundleDescriptor bd, String JavaDoc j2eeType)
1650        throws MBeanException {
1651
1652    String JavaDoc moduleName = null;
1653    String JavaDoc modLocation = null;
1654    String JavaDoc ddRoot = bd.getApplication().getGeneratedXMLDirectory();
1655
1656    if (bd.getModuleDescriptor().isStandalone()) {
1657
1658        moduleName = bd.getApplication().getRegistrationName();
1659
1660            if (j2eeType.equals("AppClientModule")) {
1661                modLocation = ddRoot + File.separator +
1662                DescriptorConstants.APP_CLIENT_DD_ENTRY;
1663            } else if (j2eeType.equals("EJBModule")) {
1664                modLocation = ddRoot + File.separator +
1665                DescriptorConstants.EJB_DD_ENTRY;
1666            } else if (j2eeType.equals("WebModule")) {
1667                modLocation = ddRoot + File.separator +
1668                DescriptorConstants.WEB_DD_ENTRY;
1669            } else if (j2eeType.equals("ResourceAdapterModule")) {
1670                modLocation = ddRoot + File.separator +
1671                DescriptorConstants.RAR_DD_ENTRY;
1672            }
1673
1674    } else {
1675
1676        moduleName = FileUtils.makeFriendlyFileName(
1677             bd.getModuleDescriptor().getArchiveUri());
1678
1679            if (j2eeType.equals("AppClientModule")) {
1680                modLocation = ddRoot + File.separator + moduleName + File.separator +
1681                DescriptorConstants.APP_CLIENT_DD_ENTRY;
1682            } else if (j2eeType.equals("EJBModule")) {
1683                modLocation = ddRoot + File.separator + moduleName + File.separator +
1684                DescriptorConstants.EJB_DD_ENTRY;
1685            } else if (j2eeType.equals("WebModule")) {
1686                modLocation = ddRoot + File.separator + moduleName + File.separator +
1687                DescriptorConstants.WEB_DD_ENTRY;
1688            } else if (j2eeType.equals("ResourceAdapterModule")) {
1689                modLocation = ddRoot + File.separator + moduleName + File.separator +
1690                DescriptorConstants.RAR_DD_ENTRY;
1691            }
1692    }
1693
1694    return modLocation;
1695    }
1696
1697
1698    /* get application name for connector module */
1699    public String JavaDoc getApplicationName(BundleDescriptor bd) {
1700
1701        String JavaDoc applicationName = "null";
1702
1703        if (bd.getModuleDescriptor().isStandalone()) {
1704                return applicationName;
1705        } else {
1706            if (bd.getApplication() != null) {
1707                applicationName = bd.getApplication().getRegistrationName();
1708
1709                if (applicationName == null) {
1710                    applicationName = "null";
1711                }
1712            }
1713        }
1714        return applicationName;
1715    }
1716
1717    // Methods for retrieving object names
1718

1719    // Method to retrieve single object name
1720

1721    public ObjectName findObjectName(String JavaDoc namePattern)
1722            throws MBeanException {
1723
1724    ObjectName [] objNameArr = findObjectNames(namePattern);
1725
1726    if ((objNameArr != null) && (objNameArr.length > 0)) {
1727        if (objNameArr.length > 1) {
1728                throw new MBeanException(new Exception JavaDoc(
1729            "Found more than one mBean matchin the given object name pattern"));
1730        }
1731        return objNameArr[0];
1732    }
1733
1734    return null;
1735    }
1736
1737
1738    // Method to retrieve array of object names
1739

1740    private ObjectName[] findObjectNames(String JavaDoc namePattern)
1741            throws MBeanException {
1742
1743    ObjectName [] objNameArr = null;
1744    ObjectName objNamePattern = null;
1745
1746    //String pattern = J2EEDomainMdl.DOMAINNAME + ":" + keys + ",*";
1747

1748    try {
1749        objNamePattern = new ObjectName(namePattern);
1750    } catch (javax.management.MalformedObjectNameException JavaDoc mfone) {
1751        throw new MBeanException(mfone);
1752    }
1753
1754    Set s = new HashSet();
1755    s = server.queryNames(objNamePattern, null);
1756    if (s != null) {
1757        objNameArr = (ObjectName[]) s.toArray( new ObjectName[s.size()]);
1758        return objNameArr;
1759    }
1760
1761    return objNameArr;
1762    }
1763
1764    // Method to read deployment descriptor xml
1765
// and return it as String
1766

1767    private String JavaDoc getStringForDDxml(String JavaDoc fileName)
1768            throws MBeanException {
1769    FileReader fr = null;
1770        try {
1771
1772            if (!(new File(fileName)).exists()) {
1773                _logger.log(Level.FINE, "Descriptor does not exist " + fileName);
1774                return null;
1775            }
1776
1777        fr = new FileReader(fileName);
1778        StringWriter sr = new StringWriter();
1779
1780        char[] buf = new char[1024];
1781        int len = 0;
1782        while (len != -1) {
1783            try {
1784                len = fr.read(buf, 0, buf.length);
1785            } catch (EOFException eof) {
1786                break;
1787            }
1788            if (len != -1) {
1789                sr.write(buf, 0, len);
1790            }
1791        }
1792
1793        fr.close();
1794        sr.close();
1795
1796        return sr.toString();
1797
1798    } catch (FileNotFoundException fnfe) {
1799            //System.out.println("FileNotFoundException ...");
1800
throw new MBeanException(fnfe);
1801    } catch (IOException ioe) {
1802            //System.out.println("IOException ...");
1803
throw new MBeanException(ioe);
1804    } finally {
1805        if (fr != null) {
1806            try {
1807                fr.close();
1808            } catch (IOException ioe) {
1809            }
1810        }
1811    }
1812    }
1813
1814
1815    /* Return j2ee tpe for a given ejb */
1816    public String JavaDoc getJ2eeTypeForEjb(EjbDescriptor ejbDescriptor)
1817        throws MBeanException {
1818
1819
1820        String JavaDoc ejbType = ejbDescriptor.getType();
1821        String JavaDoc ejbSessionType = null;
1822        if (ejbType.equals("Session")) {
1823            ejbSessionType = ((EjbSessionDescriptor) ejbDescriptor).getSessionType();
1824    }
1825
1826        String JavaDoc j2eeType = null;
1827
1828        if (ejbType.equals("Entity")) {
1829            j2eeType = "EntityBean";
1830        } else if (ejbType.equals("Message-driven")) {
1831            j2eeType = "MessageDrivenBean";
1832        } else if (ejbType.equals("Session")) {
1833            if (ejbSessionType.equals("Stateless")) {
1834                j2eeType = "StatelessSessionBean";
1835            } else if (ejbSessionType.equals("Stateful")) {
1836                j2eeType = "StatefulSessionBean";
1837            }
1838        }
1839
1840    return j2eeType;
1841    }
1842
1843
1844    // register domain status mBean
1845
private void registerDomainStatusMBean() {
1846    try {
1847        ObjectName on = DomainStatusHelper.getDomainStatusObjectName();
1848
1849        server.registerMBean(new DomainStatus(), on);
1850
1851        // set this server state to RUNNING
1852
Object JavaDoc[] params = new Object JavaDoc[2];
1853        params[0] = (Object JavaDoc) ApplicationServer.getServerContext().getInstanceName();
1854        params[1] = (Object JavaDoc) new Integer JavaDoc(StateManageable.STATE_RUNNING);
1855        String JavaDoc[] signature = {"java.lang.String", "java.lang.Integer"};
1856        server.invoke(on, "setstate", params, signature);
1857
1858    } catch (MalformedObjectNameException mne) {
1859        throw new RuntimeException JavaDoc(mne);
1860    } catch (InstanceNotFoundException infe) {
1861        throw new RuntimeException JavaDoc(infe);
1862    } catch (InstanceAlreadyExistsException iae) {
1863        throw new RuntimeException JavaDoc(iae);
1864    } catch (MBeanRegistrationException mre) {
1865        throw new RuntimeException JavaDoc(mre);
1866    } catch (NotCompliantMBeanException ncmbe) {
1867        throw new RuntimeException JavaDoc(ncmbe);
1868    } catch (MBeanException mbe) {
1869        throw new RuntimeException JavaDoc(mbe);
1870    } catch (ReflectionException rfe) {
1871        throw new RuntimeException JavaDoc(rfe);
1872    }
1873    }
1874
1875    // register das j2ee servers
1876
public void registerDasJ2EEServers() {
1877    // get the list of servers
1878
String JavaDoc [] allServers = getAllServerNamesInDomain();
1879    if ((allServers == null) || (allServers.length == 0)) return;
1880    // register for each server
1881
for (int i=0; i<allServers.length; i++) {
1882                registerDasJ2EEServer(allServers[i]);
1883        }
1884    }
1885
1886
1887    // get the list of all server names within this domain
1888
private String JavaDoc[] getAllServerNamesInDomain() {
1889        // get the list of all instances for this domain
1890
ConfigContext configContext =
1891                AdminService.getAdminService().getAdminContext().getAdminConfigContext();
1892        Server [] serverArr = null;
1893        try {
1894            serverArr = ServerHelper.getServersInDomain(configContext);
1895        } catch (ConfigException ce) {
1896            ce.printStackTrace();
1897            _logger.log(Level.WARNING, "admin.get_servers_in_domain_error", ce);
1898        }
1899        if ((serverArr == null) || (serverArr.length == 0)) {
1900                return null;
1901        }
1902
1903        String JavaDoc [] strServerArr = new String JavaDoc[serverArr.length];
1904
1905        for (int i=0; i<serverArr.length; i++) {
1906                strServerArr[i] = serverArr[i].getName();
1907        }
1908
1909        return strServerArr;
1910    }
1911
1912    // register DasJ2EE Server
1913
public void registerDasJ2EEServer(String JavaDoc serverName) {
1914
1915    // vars
1916
DomainStatusHelper dsh = new DomainStatusHelper();
1917
1918    try {
1919        // check if the DomainStatusMBean is registered or not
1920
if (! server.isRegistered(dsh.getDomainStatusObjectName())) {
1921        registerDomainStatusMBean();
1922        }
1923
1924        // set this server state to STARTING if not already set
1925
try {
1926        dsh.getstate(serverName);
1927            } catch (Exception JavaDoc e) {
1928            Object JavaDoc[] params = new Object JavaDoc[2];
1929            params[0] = (Object JavaDoc) serverName;
1930            params[1] = (Object JavaDoc) new Integer JavaDoc(StateManageable.STATE_STARTING);
1931            String JavaDoc[] signature = {"java.lang.String", "java.lang.Integer"};
1932            server.invoke(dsh.getDomainStatusObjectName(), "setstate", params, signature);
1933        }
1934
1935        // object name for j2ee server
1936
/*
1937        String strON = (
1938                ApplicationServer.getServerContext().getDefaultDomainName() + ":" +
1939        "j2eeType=J2EEServer," +
1940        "name=" + serverName +
1941        ",category=dasJ2EE"
1942        );
1943        ObjectName on = new ObjectName(strON);
1944        */

1945        ObjectName on = new ObjectName(getServerBaseON(true, serverName));
1946
1947        DASJ2EEServerImpl ds = new DASJ2EEServerImpl();
1948        ObjectInstance oi = server.registerMBean(ds, on);
1949
1950        // register the notification listener
1951
server.addNotificationListener(
1952        dsh.getDomainStatusObjectName(),
1953        oi.getObjectName(),
1954        null, null);
1955    } catch(MalformedObjectNameException e) {
1956            e.printStackTrace();
1957            _logger.log(Level.WARNING, "admin.registerDasJ2EEServer exception", e);
1958    } catch(javax.management.InstanceAlreadyExistsException JavaDoc iae) {
1959    } catch(javax.management.InstanceNotFoundException JavaDoc infe) {
1960            infe.printStackTrace();
1961            _logger.log(Level.WARNING, "admin.registerDasJ2EEServer exception", infe);
1962    } catch(javax.management.MBeanRegistrationException JavaDoc mre) {
1963            mre.printStackTrace();
1964            _logger.log(Level.WARNING, "admin.registerDasJ2EEServer exception", mre);
1965    } catch(javax.management.NotCompliantMBeanException JavaDoc ncmbe) {
1966        ncmbe.printStackTrace();
1967            _logger.log(Level.WARNING, "admin.registerDasJ2EEServer exception", ncmbe);
1968    } catch(javax.management.MBeanException JavaDoc mbe) {
1969        mbe.printStackTrace();
1970            _logger.log(Level.WARNING, "admin.registerDasJ2EEServer exception", mbe);
1971    } catch(javax.management.ReflectionException JavaDoc rfe) {
1972        rfe.printStackTrace();
1973            _logger.log(Level.WARNING, "admin.registerDasJ2EEServer exception", rfe);
1974    }
1975    }
1976    
1977
1978    // unregister das j2ee server
1979
public void unregisterDasJ2EEServer(String JavaDoc serverName) {
1980    try {
1981        /*
1982        ObjectName onPattern = new ObjectName(
1983                ApplicationServer.getServerContext().getDefaultDomainName() + ":" +
1984        "j2eeType=J2EEServer," +
1985        "name=" + serverName +
1986        ",group=jsr77" +
1987        ",*"
1988        );
1989        */

1990        ObjectName onPattern = new ObjectName(
1991        getServerBaseON(true, serverName) +
1992        ",*"
1993        );
1994        // query mBean server
1995
Set s = new HashSet();
1996        s = server.queryNames(onPattern, null);
1997        if ((s != null) && (s.size() > 0)) {
1998        ObjectName [] objNameArr =
1999            (ObjectName[]) s.toArray( new ObjectName[s.size()]);
2000            server.unregisterMBean(objNameArr[0]);
2001        }
2002    } catch(MalformedObjectNameException e) {
2003            e.printStackTrace();
2004            _logger.log(Level.WARNING, "admin.unregisterDASJ2EEServer exception", e);
2005    } catch (javax.management.InstanceNotFoundException JavaDoc infe) {
2006            _logger.log(Level.FINE, "admin.unregisterDASJ2EEServer exception", infe);
2007    } catch (MBeanException mbe) {
2008            _logger.log(Level.FINE, "admin.unregisterDASJ2EEServer exception", mbe);
2009    } catch (Exception JavaDoc ex) {
2010        ex.printStackTrace();
2011            _logger.log(Level.FINE, "admin.unregisterDASJ2EEServer exception", ex);
2012    }
2013    }
2014
2015    /*
2016    public ObjectName getServerON(boolean amx, String serverName) {
2017    ObjectName serverON = null;
2018    try {
2019        String strON = getServerBaseON(amx, serverName);
2020        serverON = findObjectName(strON + ",*");
2021    } catch (Exception e) {
2022        e.printStackTrace();
2023            _logger.log(Level.WARNING, "admin.getServerON exception", e);
2024    }
2025    return serverON;
2026    }
2027    */

2028
2029    public String JavaDoc getServerBaseON(boolean amx, String JavaDoc serverName) {
2030
2031            String JavaDoc domainName = null;
2032    
2033            // get domain name
2034
if (amx) {
2035        try {
2036                    ObjectName pattern = Util.newObjectNamePattern(
2037                        "*", LoaderMBean.LOADER_NAME_PROPS );
2038                    Set names = server.queryNames(pattern, null);
2039                    assert( names.size() == 1 );
2040                    ObjectName loaderON = (ObjectName) SetUtil.getSingleton(names);
2041                    domainName =
2042                        (String JavaDoc) server.getAttribute(loaderON, "AdministrativeDomainName");
2043        } catch (Exception JavaDoc e) {
2044            throw new RuntimeException JavaDoc(e);
2045        }
2046        //domainName = "amx";
2047
} else {
2048        /*
2049                ObjectName pattern = Util.newObjectNamePattern(
2050                    "*", "j2eeType=J2EEDomain,category=runtime");
2051                Set names = server.queryNames(pattern, null);
2052                assert( names.size() == 1 );
2053                ObjectName domainON = (ObjectName) SetUtil.getSingleton(names);
2054                domainName = (String) server.getAttribute(domainON, "name");
2055        */

2056                domainName =
2057        ApplicationServer.getServerContext().getDefaultDomainName();
2058            }
2059            
2060            return getServerBaseON(domainName, serverName);
2061    
2062    }
2063
2064  
2065    public void registerTransactionService() {
2066    TransactionServiceMdl ts = new TransactionServiceMdl();
2067        instantiateAndRegisterRuntimeMBean("TransactionService", ts);
2068   }
2069
2070    private String JavaDoc getServerBaseON(String JavaDoc domainName, String JavaDoc serverName) {
2071            return( domainName + ":" + "j2eeType=J2EEServer,name=" + serverName);
2072    }
2073
2074    public void registerAllJ2EEClusters() {
2075        try {
2076            final Cluster[] clusters = ClusterHelper.getClustersInDomain(
2077                getAdminConfigContext());
2078            if ((null == clusters) || (clusters.length == 0)) {
2079                return;
2080            }
2081            final ArrayList al = new ArrayList(clusters.length);
2082            for (int i = 0; i < clusters.length; i++) {
2083                al.add(clusters[i].getName());
2084            }
2085            final String JavaDoc[] sa = (String JavaDoc[])al.toArray(new String JavaDoc[0]);
2086            _registerJ2EEClusters(sa);
2087        } catch (ConfigException ce) {
2088            throw new RuntimeException JavaDoc(ce.getMessage());
2089        }
2090    }
2091
2092    public void registerJ2EECluster(String JavaDoc clusterName) {
2093        try {
2094            if (!ClusterHelper.isACluster(getAdminConfigContext(), clusterName)) {
2095                throw new RuntimeException JavaDoc(clusterName + " is not a valid cluster.");
2096            }
2097        } catch (ConfigException ce) {
2098            throw new RuntimeException JavaDoc(ce.getMessage());
2099        }
2100        _registerJ2EEClusters(new String JavaDoc[] {clusterName});
2101    }
2102
2103    public void unregisterJ2EECluster(String JavaDoc clusterName) {
2104        if ((null == clusterName) || "".equals(clusterName)) {
2105            throw new IllegalArgumentException JavaDoc();
2106        }
2107        ObjectName on = null;
2108        final MBeanServer mbs = getAdminMBeanServer();
2109        final ProxyFactory proxyFactory = ProxyFactory.getInstance(
2110            new MBeanServerConnectionSource(mbs));
2111        final Set proxies = proxyFactory.getDomainRoot().getQueryMgr().
2112            queryJ2EETypeSet(J2EECluster.J2EE_TYPE);
2113        final Iterator it = proxies.iterator();
2114        while (it.hasNext()) {
2115            J2EECluster cluster = (J2EECluster)it.next();
2116            if (cluster.getName().equals(clusterName)) {
2117                on = Util.getObjectName(cluster);
2118                break;
2119            }
2120        }
2121        try {
2122            mbs.unregisterMBean(on);
2123        } catch (Exception JavaDoc e) {
2124            throw new RuntimeException JavaDoc(e.getMessage());
2125        }
2126    }
2127
2128    private void _registerJ2EEClusters(String JavaDoc[] clusters) {
2129        final ConfigContext ctx = getAdminConfigContext();
2130        final MBeanServer mbs = getAdminMBeanServer();
2131        final String JavaDoc amxJMXDomain = BootUtil.getInstance().getAMXJMXDomainName();
2132        final String JavaDoc j2eeTypeProp = AMX.J2EE_TYPE_KEY + '=' + J2EECluster.J2EE_TYPE;
2133        for (int i = 0; i < clusters.length; i++) {
2134            final String JavaDoc nameProp = AMX.NAME_KEY + '=' + clusters[i];
2135            final String JavaDoc props = Util.concatenateProps(j2eeTypeProp, nameProp);
2136            final ObjectName on = JMXUtil.newObjectName(amxJMXDomain, props);
2137            try {
2138                mbs.registerMBean(new J2EEClusterImpl(null), on);
2139                _logger.info(on + " is registered.");
2140            } catch (Exception JavaDoc e) {
2141                throw new RuntimeException JavaDoc(e.getMessage());
2142            }
2143        }
2144    }
2145
2146    private ConfigContext getAdminConfigContext() {
2147        return AdminService.getAdminService().getAdminContext().
2148            getAdminConfigContext();
2149    }
2150
2151    private MBeanServer getAdminMBeanServer() {
2152        return AdminService.getAdminService().getAdminContext().
2153            getMBeanServer();
2154    }
2155
2156    private String JavaDoc getJVMId() {
2157        final String JavaDoc serverName =
2158                ApplicationServer.getServerContext().getInstanceName();
2159        return serverName + System.currentTimeMillis();
2160    }
2161
2162}
2163
Popular Tags