KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > catalina > mbeans > MBeanUtils


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.catalina.mbeans;
19
20
21 import java.util.Hashtable JavaDoc;
22
23 import javax.management.DynamicMBean JavaDoc;
24 import javax.management.MBeanException JavaDoc;
25 import javax.management.MBeanServer JavaDoc;
26 import javax.management.MalformedObjectNameException JavaDoc;
27 import javax.management.ObjectName JavaDoc;
28 import javax.management.modelmbean.ModelMBean JavaDoc;
29
30 import org.apache.catalina.Contained;
31 import org.apache.catalina.Container;
32 import org.apache.catalina.Context;
33 import org.apache.catalina.Engine;
34 import org.apache.catalina.Group;
35 import org.apache.catalina.Host;
36 import org.apache.catalina.Loader;
37 import org.apache.catalina.Manager;
38 import org.apache.catalina.Realm;
39 import org.apache.catalina.Role;
40 import org.apache.catalina.Server;
41 import org.apache.catalina.Service;
42 import org.apache.catalina.User;
43 import org.apache.catalina.UserDatabase;
44 import org.apache.catalina.Valve;
45 import org.apache.catalina.connector.Connector;
46 import org.apache.catalina.deploy.ContextEnvironment;
47 import org.apache.catalina.deploy.ContextResource;
48 import org.apache.catalina.deploy.ContextResourceLink;
49 import org.apache.catalina.deploy.NamingResources;
50 import org.apache.catalina.valves.ValveBase;
51 import org.apache.commons.logging.Log;
52 import org.apache.commons.logging.LogFactory;
53 import org.apache.tomcat.util.IntrospectionUtils;
54 import org.apache.tomcat.util.modeler.ManagedBean;
55 import org.apache.tomcat.util.modeler.Registry;
56
57
58 /**
59  * Public utility methods in support of the server side MBeans implementation.
60  *
61  * @author Craig R. McClanahan
62  * @author Amy Roh
63  * @version $Revision: 467222 $ $Date: 2006-10-24 05:17:11 +0200 (mar., 24 oct. 2006) $
64  */

65
66 public class MBeanUtils {
67     private static Log log = LogFactory.getLog(MBeanUtils.class);
68
69     // ------------------------------------------------------- Static Variables
70

71
72     /**
73      * The set of exceptions to the normal rules used by
74      * <code>createManagedBean()</code>. The first element of each pair
75      * is a class name, and the second element is the managed bean name.
76      */

77     private static String JavaDoc exceptions[][] = {
78         { "org.apache.ajp.tomcat4.Ajp13Connector",
79           "Ajp13Connector" },
80         { "org.apache.coyote.tomcat4.Ajp13Connector",
81           "CoyoteConnector" },
82         { "org.apache.catalina.users.JDBCGroup",
83           "Group" },
84         { "org.apache.catalina.users.JDBCRole",
85           "Role" },
86         { "org.apache.catalina.users.JDBCUser",
87           "User" },
88         { "org.apache.catalina.users.MemoryGroup",
89           "Group" },
90         { "org.apache.catalina.users.MemoryRole",
91           "Role" },
92         { "org.apache.catalina.users.MemoryUser",
93           "User" },
94     };
95
96
97     /**
98      * The configuration information registry for our managed beans.
99      */

100     private static Registry registry = createRegistry();
101
102
103     /**
104      * The <code>MBeanServer</code> for this application.
105      */

106     private static MBeanServer JavaDoc mserver = createServer();
107
108
109     // --------------------------------------------------------- Static Methods
110

111     /**
112      * Create and return the name of the <code>ManagedBean</code> that
113      * corresponds to this Catalina component.
114      *
115      * @param component The component for which to create a name
116      */

117     static String JavaDoc createManagedName(Object JavaDoc component) {
118
119         // Deal with exceptions to the standard rule
120
String JavaDoc className = component.getClass().getName();
121         for (int i = 0; i < exceptions.length; i++) {
122             if (className.equals(exceptions[i][0])) {
123                 return (exceptions[i][1]);
124             }
125         }
126
127         // Perform the standard transformation
128
int period = className.lastIndexOf('.');
129         if (period >= 0)
130             className = className.substring(period + 1);
131         return (className);
132
133     }
134
135
136     /**
137      * Create, register, and return an MBean for this
138      * <code>Connector</code> object.
139      *
140      * @param connector The Connector to be managed
141      *
142      * @exception Exception if an MBean cannot be created or registered
143      */

144     static DynamicMBean JavaDoc createMBean(Connector connector)
145         throws Exception JavaDoc {
146
147         String JavaDoc mname = createManagedName(connector);
148         ManagedBean managed = registry.findManagedBean(mname);
149         if (managed == null) {
150             Exception JavaDoc e = new Exception JavaDoc("ManagedBean is not found with "+mname);
151             throw new MBeanException JavaDoc(e);
152         }
153         String JavaDoc domain = managed.getDomain();
154         if (domain == null)
155             domain = mserver.getDefaultDomain();
156         DynamicMBean JavaDoc mbean = managed.createMBean(connector);
157         ObjectName JavaDoc oname = createObjectName(domain, connector);
158         if( mserver.isRegistered( oname )) {
159             mserver.unregisterMBean(oname);
160         }
161         mserver.registerMBean(mbean, oname);
162         return (mbean);
163
164     }
165
166
167     /**
168      * Create, register, and return an MBean for this
169      * <code>Context</code> object.
170      *
171      * @param context The Context to be managed
172      *
173      * @exception Exception if an MBean cannot be created or registered
174      */

175     static DynamicMBean JavaDoc createMBean(Context context)
176         throws Exception JavaDoc {
177
178         String JavaDoc mname = createManagedName(context);
179         ManagedBean managed = registry.findManagedBean(mname);
180         if (managed == null) {
181             Exception JavaDoc e = new Exception JavaDoc("ManagedBean is not found with "+mname);
182             throw new MBeanException JavaDoc(e);
183         }
184         String JavaDoc domain = managed.getDomain();
185         if (domain == null)
186             domain = mserver.getDefaultDomain();
187         DynamicMBean JavaDoc mbean = managed.createMBean(context);
188         ObjectName JavaDoc oname = createObjectName(domain, context);
189         if( mserver.isRegistered(oname)) {
190             log.debug("Already registered " + oname);
191             mserver.unregisterMBean(oname);
192         }
193         mserver.registerMBean(mbean, oname);
194         return (mbean);
195
196     }
197
198     
199     /**
200      * Create, register, and return an MBean for this
201      * <code>ContextEnvironment</code> object.
202      *
203      * @param environment The ContextEnvironment to be managed
204      *
205      * @exception Exception if an MBean cannot be created or registered
206      */

207     static DynamicMBean JavaDoc createMBean(ContextEnvironment environment)
208         throws Exception JavaDoc {
209
210         String JavaDoc mname = createManagedName(environment);
211         ManagedBean managed = registry.findManagedBean(mname);
212         if (managed == null) {
213             Exception JavaDoc e = new Exception JavaDoc("ManagedBean is not found with "+mname);
214             throw new MBeanException JavaDoc(e);
215         }
216         String JavaDoc domain = managed.getDomain();
217         if (domain == null)
218             domain = mserver.getDefaultDomain();
219         DynamicMBean JavaDoc mbean = managed.createMBean(environment);
220         ObjectName JavaDoc oname = createObjectName(domain, environment);
221         if( mserver.isRegistered( oname )) {
222             mserver.unregisterMBean(oname);
223         }
224         mserver.registerMBean(mbean, oname);
225         return (mbean);
226
227     }
228
229
230     /**
231      * Create, register, and return an MBean for this
232      * <code>ContextResource</code> object.
233      *
234      * @param resource The ContextResource to be managed
235      *
236      * @exception Exception if an MBean cannot be created or registered
237      */

238     static DynamicMBean JavaDoc createMBean(ContextResource resource)
239         throws Exception JavaDoc {
240
241         String JavaDoc mname = createManagedName(resource);
242         ManagedBean managed = registry.findManagedBean(mname);
243         if (managed == null) {
244             Exception JavaDoc e = new Exception JavaDoc("ManagedBean is not found with "+mname);
245             throw new MBeanException JavaDoc(e);
246         }
247         String JavaDoc domain = managed.getDomain();
248         if (domain == null)
249             domain = mserver.getDefaultDomain();
250         DynamicMBean JavaDoc mbean = managed.createMBean(resource);
251         ObjectName JavaDoc oname = createObjectName(domain, resource);
252         if( mserver.isRegistered( oname )) {
253             mserver.unregisterMBean(oname);
254         }
255         mserver.registerMBean(mbean, oname);
256         return (mbean);
257
258     }
259
260
261     /**
262      * Create, register, and return an MBean for this
263      * <code>ContextResourceLink</code> object.
264      *
265      * @param resourceLink The ContextResourceLink to be managed
266      *
267      * @exception Exception if an MBean cannot be created or registered
268      */

269     static DynamicMBean JavaDoc createMBean(ContextResourceLink resourceLink)
270         throws Exception JavaDoc {
271
272         String JavaDoc mname = createManagedName(resourceLink);
273         ManagedBean managed = registry.findManagedBean(mname);
274         if (managed == null) {
275             Exception JavaDoc e = new Exception JavaDoc("ManagedBean is not found with "+mname);
276             throw new MBeanException JavaDoc(e);
277         }
278         String JavaDoc domain = managed.getDomain();
279         if (domain == null)
280             domain = mserver.getDefaultDomain();
281         DynamicMBean JavaDoc mbean = managed.createMBean(resourceLink);
282         ObjectName JavaDoc oname = createObjectName(domain, resourceLink);
283         if( mserver.isRegistered( oname )) {
284             mserver.unregisterMBean(oname);
285         }
286         mserver.registerMBean(mbean, oname);
287         return (mbean);
288
289     }
290  
291     /**
292      * Create, register, and return an MBean for this
293      * <code>Engine</code> object.
294      *
295      * @param engine The Engine to be managed
296      *
297      * @exception Exception if an MBean cannot be created or registered
298      */

299     static DynamicMBean JavaDoc createMBean(Engine engine)
300         throws Exception JavaDoc {
301
302         String JavaDoc mname = createManagedName(engine);
303         ManagedBean managed = registry.findManagedBean(mname);
304         if (managed == null) {
305             Exception JavaDoc e = new Exception JavaDoc("ManagedBean is not found with "+mname);
306             throw new MBeanException JavaDoc(e);
307         }
308         String JavaDoc domain = managed.getDomain();
309         if (domain == null)
310             domain = mserver.getDefaultDomain();
311         DynamicMBean JavaDoc mbean = managed.createMBean(engine);
312         ObjectName JavaDoc oname = createObjectName(domain, engine);
313         if( mserver.isRegistered( oname )) {
314             mserver.unregisterMBean(oname);
315         }
316         mserver.registerMBean(mbean, oname);
317         return (mbean);
318
319     }
320
321
322     /**
323      * Create, register, and return an MBean for this
324      * <code>Group</code> object.
325      *
326      * @param group The Group to be managed
327      *
328      * @exception Exception if an MBean cannot be created or registered
329      */

330     static DynamicMBean JavaDoc createMBean(Group group)
331         throws Exception JavaDoc {
332
333         String JavaDoc mname = createManagedName(group);
334         ManagedBean managed = registry.findManagedBean(mname);
335         if (managed == null) {
336             Exception JavaDoc e = new Exception JavaDoc("ManagedBean is not found with "+mname);
337             throw new MBeanException JavaDoc(e);
338         }
339         String JavaDoc domain = managed.getDomain();
340         if (domain == null)
341             domain = mserver.getDefaultDomain();
342         DynamicMBean JavaDoc mbean = managed.createMBean(group);
343         ObjectName JavaDoc oname = createObjectName(domain, group);
344         if( mserver.isRegistered( oname )) {
345             mserver.unregisterMBean(oname);
346         }
347         mserver.registerMBean(mbean, oname);
348         return (mbean);
349
350     }
351
352
353     /**
354      * Create, register, and return an MBean for this
355      * <code>Host</code> object.
356      *
357      * @param host The Host to be managed
358      *
359      * @exception Exception if an MBean cannot be created or registered
360      */

361     static DynamicMBean JavaDoc createMBean(Host host)
362         throws Exception JavaDoc {
363
364         String JavaDoc mname = createManagedName(host);
365         ManagedBean managed = registry.findManagedBean(mname);
366         if (managed == null) {
367             Exception JavaDoc e = new Exception JavaDoc("ManagedBean is not found with "+mname);
368             throw new MBeanException JavaDoc(e);
369         }
370         String JavaDoc domain = managed.getDomain();
371         if (domain == null)
372             domain = mserver.getDefaultDomain();
373         DynamicMBean JavaDoc mbean = managed.createMBean(host);
374         ObjectName JavaDoc oname = createObjectName(domain, host);
375         if( mserver.isRegistered( oname )) {
376             mserver.unregisterMBean(oname);
377         }
378         mserver.registerMBean(mbean, oname);
379         return (mbean);
380
381     }
382
383
384     /**
385      * Create, register, and return an MBean for this
386      * <code>Loader</code> object.
387      *
388      * @param loader The Loader to be managed
389      *
390      * @exception Exception if an MBean cannot be created or registered
391      */

392     static DynamicMBean JavaDoc createMBean(Loader loader)
393         throws Exception JavaDoc {
394
395         String JavaDoc mname = createManagedName(loader);
396         ManagedBean managed = registry.findManagedBean(mname);
397         if (managed == null) {
398             Exception JavaDoc e = new Exception JavaDoc("ManagedBean is not found with "+mname);
399             throw new MBeanException JavaDoc(e);
400         }
401         String JavaDoc domain = managed.getDomain();
402         if (domain == null)
403             domain = mserver.getDefaultDomain();
404         DynamicMBean JavaDoc mbean = managed.createMBean(loader);
405         ObjectName JavaDoc oname = createObjectName(domain, loader);
406         if( mserver.isRegistered( oname )) {
407             // side effect: stop it
408
mserver.unregisterMBean( oname );
409         }
410         mserver.registerMBean(mbean, oname);
411         return (mbean);
412
413     }
414
415     /**
416      * Create, register, and return an MBean for this
417      * <code>Manager</code> object.
418      *
419      * @param manager The Manager to be managed
420      *
421      * @exception Exception if an MBean cannot be created or registered
422      */

423     static DynamicMBean JavaDoc createMBean(Manager manager)
424         throws Exception JavaDoc {
425
426         String JavaDoc mname = createManagedName(manager);
427         ManagedBean managed = registry.findManagedBean(mname);
428         if (managed == null) {
429             Exception JavaDoc e = new Exception JavaDoc("ManagedBean is not found with "+mname);
430             throw new MBeanException JavaDoc(e);
431         }
432         String JavaDoc domain = managed.getDomain();
433         if (domain == null)
434             domain = mserver.getDefaultDomain();
435         DynamicMBean JavaDoc mbean = managed.createMBean(manager);
436         ObjectName JavaDoc oname = createObjectName(domain, manager);
437         if( mserver.isRegistered( oname )) {
438             mserver.unregisterMBean(oname);
439         }
440         mserver.registerMBean(mbean, oname);
441         return (mbean);
442
443     }
444
445
446     /**
447      * Create, register, and return an MBean for this
448      * <code>MBeanFactory</code> object.
449      *
450      * @param factory The MBeanFactory to be managed
451      *
452      * @exception Exception if an MBean cannot be created or registered
453      */

454     static DynamicMBean JavaDoc createMBean(MBeanFactory factory)
455         throws Exception JavaDoc {
456
457         String JavaDoc mname = createManagedName(factory);
458         ManagedBean managed = registry.findManagedBean(mname);
459         if (managed == null) {
460             Exception JavaDoc e = new Exception JavaDoc("ManagedBean is not found with "+mname);
461             throw new MBeanException JavaDoc(e);
462         }
463         String JavaDoc domain = managed.getDomain();
464         if (domain == null)
465             domain = mserver.getDefaultDomain();
466         DynamicMBean JavaDoc mbean = managed.createMBean(factory);
467         ObjectName JavaDoc oname = createObjectName(domain, factory);
468         if( mserver.isRegistered(oname )) {
469             mserver.unregisterMBean(oname);
470         }
471         mserver.registerMBean(mbean, oname);
472         return (mbean);
473
474     }
475
476
477     /**
478      * Create, register, and return an MBean for this
479      * <code>NamingResources</code> object.
480      *
481      * @param resource The NamingResources to be managed
482      *
483      * @exception Exception if an MBean cannot be created or registered
484      */

485     static DynamicMBean JavaDoc createMBean(NamingResources resource)
486         throws Exception JavaDoc {
487
488         String JavaDoc mname = createManagedName(resource);
489         ManagedBean managed = registry.findManagedBean(mname);
490         if (managed == null) {
491             Exception JavaDoc e = new Exception JavaDoc("ManagedBean is not found with "+mname);
492             throw new MBeanException JavaDoc(e);
493         }
494         String JavaDoc domain = managed.getDomain();
495         if (domain == null)
496             domain = mserver.getDefaultDomain();
497         DynamicMBean JavaDoc mbean = managed.createMBean(resource);
498         ObjectName JavaDoc oname = createObjectName(domain, resource);
499         if( mserver.isRegistered( oname )) {
500             mserver.unregisterMBean(oname);
501         }
502         mserver.registerMBean(mbean, oname);
503         return (mbean);
504
505     }
506
507     
508     /**
509      * Create, register, and return an MBean for this
510      * <code>Realm</code> object.
511      *
512      * @param realm The Realm to be managed
513      *
514      * @exception Exception if an MBean cannot be created or registered
515      */

516     static DynamicMBean JavaDoc createMBean(Realm realm)
517         throws Exception JavaDoc {
518
519         String JavaDoc mname = createManagedName(realm);
520         ManagedBean managed = registry.findManagedBean(mname);
521         if (managed == null) {
522             Exception JavaDoc e = new Exception JavaDoc("ManagedBean is not found with "+mname);
523             throw new MBeanException JavaDoc(e);
524         }
525         String JavaDoc domain = managed.getDomain();
526         if (domain == null)
527             domain = mserver.getDefaultDomain();
528         DynamicMBean JavaDoc mbean = managed.createMBean(realm);
529         ObjectName JavaDoc oname = createObjectName(domain, realm);
530         if( mserver.isRegistered( oname )) {
531             mserver.unregisterMBean(oname);
532         }
533         mserver.registerMBean(mbean, oname);
534         return (mbean);
535
536     }
537
538
539     /**
540      * Create, register, and return an MBean for this
541      * <code>Role</code> object.
542      *
543      * @param role The Role to be managed
544      *
545      * @exception Exception if an MBean cannot be created or registered
546      */

547     static DynamicMBean JavaDoc createMBean(Role role)
548         throws Exception JavaDoc {
549
550         String JavaDoc mname = createManagedName(role);
551         ManagedBean managed = registry.findManagedBean(mname);
552         if (managed == null) {
553             Exception JavaDoc e = new Exception JavaDoc("ManagedBean is not found with "+mname);
554             throw new MBeanException JavaDoc(e);
555         }
556         String JavaDoc domain = managed.getDomain();
557         if (domain == null)
558             domain = mserver.getDefaultDomain();
559         DynamicMBean JavaDoc mbean = managed.createMBean(role);
560         ObjectName JavaDoc oname = createObjectName(domain, role);
561         if( mserver.isRegistered( oname )) {
562             mserver.unregisterMBean(oname);
563         }
564         mserver.registerMBean(mbean, oname);
565         return (mbean);
566
567     }
568
569
570     /**
571      * Create, register, and return an MBean for this
572      * <code>Server</code> object.
573      *
574      * @param server The Server to be managed
575      *
576      * @exception Exception if an MBean cannot be created or registered
577      */

578     static DynamicMBean JavaDoc createMBean(Server JavaDoc server)
579         throws Exception JavaDoc {
580
581         String JavaDoc mname = createManagedName(server);
582         ManagedBean managed = registry.findManagedBean(mname);
583         if (managed == null) {
584             Exception JavaDoc e = new Exception JavaDoc("ManagedBean is not found with "+mname);
585             throw new MBeanException JavaDoc(e);
586         }
587         String JavaDoc domain = managed.getDomain();
588         if (domain == null)
589             domain = mserver.getDefaultDomain();
590         DynamicMBean JavaDoc mbean = managed.createMBean(server);
591         ObjectName JavaDoc oname = createObjectName(domain, server);
592         if( mserver.isRegistered( oname )) {
593             mserver.unregisterMBean(oname);
594         }
595         mserver.registerMBean(mbean, oname);
596         return (mbean);
597
598     }
599
600
601     /**
602      * Create, register, and return an MBean for this
603      * <code>Service</code> object.
604      *
605      * @param service The Service to be managed
606      *
607      * @exception Exception if an MBean cannot be created or registered
608      */

609     static DynamicMBean JavaDoc createMBean(Service service)
610         throws Exception JavaDoc {
611
612         String JavaDoc mname = createManagedName(service);
613         ManagedBean managed = registry.findManagedBean(mname);
614         if (managed == null) {
615             Exception JavaDoc e = new Exception JavaDoc("ManagedBean is not found with "+mname);
616             throw new MBeanException JavaDoc(e);
617         }
618         String JavaDoc domain = managed.getDomain();
619         if (domain == null)
620             domain = mserver.getDefaultDomain();
621         DynamicMBean JavaDoc mbean = managed.createMBean(service);
622         ObjectName JavaDoc oname = createObjectName(domain, service);
623         if( mserver.isRegistered( oname )) {
624             mserver.unregisterMBean(oname);
625         }
626         mserver.registerMBean(mbean, oname);
627         return (mbean);
628
629     }
630
631
632     /**
633      * Create, register, and return an MBean for this
634      * <code>User</code> object.
635      *
636      * @param user The User to be managed
637      *
638      * @exception Exception if an MBean cannot be created or registered
639      */

640     static DynamicMBean JavaDoc createMBean(User user)
641         throws Exception JavaDoc {
642
643         String JavaDoc mname = createManagedName(user);
644         ManagedBean managed = registry.findManagedBean(mname);
645         if (managed == null) {
646             Exception JavaDoc e = new Exception JavaDoc("ManagedBean is not found with "+mname);
647             throw new MBeanException JavaDoc(e);
648         }
649         String JavaDoc domain = managed.getDomain();
650         if (domain == null)
651             domain = mserver.getDefaultDomain();
652         DynamicMBean JavaDoc mbean = managed.createMBean(user);
653         ObjectName JavaDoc oname = createObjectName(domain, user);
654         if( mserver.isRegistered( oname )) {
655             mserver.unregisterMBean(oname);
656         }
657         mserver.registerMBean(mbean, oname);
658         return (mbean);
659
660     }
661
662
663     /**
664      * Create, register, and return an MBean for this
665      * <code>UserDatabase</code> object.
666      *
667      * @param userDatabase The UserDatabase to be managed
668      *
669      * @exception Exception if an MBean cannot be created or registered
670      */

671     static DynamicMBean JavaDoc createMBean(UserDatabase userDatabase)
672         throws Exception JavaDoc {
673
674         String JavaDoc mname = createManagedName(userDatabase);
675         ManagedBean managed = registry.findManagedBean(mname);
676         if (managed == null) {
677             Exception JavaDoc e = new Exception JavaDoc("ManagedBean is not found with "+mname);
678             throw new MBeanException JavaDoc(e);
679         }
680         String JavaDoc domain = managed.getDomain();
681         if (domain == null)
682             domain = mserver.getDefaultDomain();
683         DynamicMBean JavaDoc mbean = managed.createMBean(userDatabase);
684         ObjectName JavaDoc oname = createObjectName(domain, userDatabase);
685         if( mserver.isRegistered( oname )) {
686             mserver.unregisterMBean(oname);
687         }
688         mserver.registerMBean(mbean, oname);
689         return (mbean);
690
691     }
692
693
694     /**
695      * Create, register, and return an MBean for this
696      * <code>Valve</code> object.
697      *
698      * @param valve The Valve to be managed
699      *
700      * @exception Exception if an MBean cannot be created or registered
701      */

702     static DynamicMBean JavaDoc createMBean(Valve valve)
703         throws Exception JavaDoc {
704
705         String JavaDoc mname = createManagedName(valve);
706         ManagedBean managed = registry.findManagedBean(mname);
707         if (managed == null) {
708             Exception JavaDoc e = new Exception JavaDoc("ManagedBean is not found with "+mname);
709             throw new MBeanException JavaDoc(e);
710         }
711         String JavaDoc domain = managed.getDomain();
712         if (domain == null)
713             domain = mserver.getDefaultDomain();
714         DynamicMBean JavaDoc mbean = managed.createMBean(valve);
715         ObjectName JavaDoc oname = createObjectName(domain, valve);
716         if( mserver.isRegistered( oname )) {
717             mserver.unregisterMBean(oname);
718         }
719         mserver.registerMBean(mbean, oname);
720         return (mbean);
721
722     }
723
724     /**
725      * Create an <code>ObjectName</code> for this
726      * <code>Connector</code> object.
727      *
728      * @param domain Domain in which this name is to be created
729      * @param connector The Connector to be named
730      *
731      * @exception MalformedObjectNameException if a name cannot be created
732      */

733     static ObjectName JavaDoc createObjectName(String JavaDoc domain,
734                                         Connector connector)
735         throws MalformedObjectNameException JavaDoc {
736
737         ObjectName JavaDoc name = null;
738         if (connector.getClass().getName().indexOf("CoyoteConnector") >= 0 ) {
739             try {
740                 String JavaDoc address = (String JavaDoc)
741                     IntrospectionUtils.getProperty(connector, "address");
742                 Integer JavaDoc port = (Integer JavaDoc)
743                     IntrospectionUtils.getProperty(connector, "port");
744                 Service service = connector.getService();
745                 String JavaDoc serviceName = null;
746                 if (service != null)
747                     serviceName = service.getName();
748                 StringBuffer JavaDoc sb = new StringBuffer JavaDoc(domain);
749                 sb.append(":type=Connector");
750                 sb.append(",port=" + port);
751                 if ((address != null) && (address.length()>0)) {
752                     sb.append(",address=" + address);
753                 }
754                 name = new ObjectName JavaDoc(sb.toString());
755                 return (name);
756             } catch (Exception JavaDoc e) {
757                 throw new MalformedObjectNameException JavaDoc
758                     ("Cannot create object name for " + connector+e);
759             }
760         } else {
761             throw new MalformedObjectNameException JavaDoc
762                 ("Cannot create object name for " + connector);
763         }
764
765     }
766
767
768     /**
769      * Create an <code>ObjectName</code> for this
770      * <code>Context</code> object.
771      *
772      * @param domain Domain in which this name is to be created
773      * @param context The Context to be named
774      *
775      * @exception MalformedObjectNameException if a name cannot be created
776      */

777     static ObjectName JavaDoc createObjectName(String JavaDoc domain,
778                                               Context context)
779         throws MalformedObjectNameException JavaDoc {
780
781         ObjectName JavaDoc name = null;
782         Host host = (Host)context.getParent();
783         Service service = ((Engine)host.getParent()).getService();
784         String JavaDoc path = context.getPath();
785         if (path.length() < 1)
786             path = "/";
787         // FIXME
788
name = new ObjectName JavaDoc(domain + ":j2eeType=WebModule,name=//" +
789                               host.getName()+ path +
790                               ",J2EEApplication=none,J2EEServer=none");
791     
792         return (name);
793
794     }
795
796     
797     /**
798      * Create an <code>ObjectName</code> for this
799      * <code>Service</code> object.
800      *
801      * @param domain Domain in which this name is to be created
802      * @param environment The ContextEnvironment to be named
803      *
804      * @exception MalformedObjectNameException if a name cannot be created
805      */

806     public static ObjectName JavaDoc createObjectName(String JavaDoc domain,
807                                               ContextEnvironment environment)
808         throws MalformedObjectNameException JavaDoc {
809
810         ObjectName JavaDoc name = null;
811         Object JavaDoc container =
812                 environment.getNamingResources().getContainer();
813         if (container instanceof Server JavaDoc) {
814             name = new ObjectName JavaDoc(domain + ":type=Environment" +
815                         ",resourcetype=Global,name=" + environment.getName());
816         } else if (container instanceof Context) {
817             String JavaDoc path = ((Context)container).getPath();
818             if (path.length() < 1)
819                 path = "/";
820             Host host = (Host) ((Context)container).getParent();
821             Engine engine = (Engine) host.getParent();
822             Service service = engine.getService();
823             name = new ObjectName JavaDoc(domain + ":type=Environment" +
824                         ",resourcetype=Context,path=" + path +
825                         ",host=" + host.getName() +
826                         ",name=" + environment.getName());
827         }
828         return (name);
829
830     }
831     
832     
833     /**
834      * Create an <code>ObjectName</code> for this
835      * <code>ContextResource</code> object.
836      *
837      * @param domain Domain in which this name is to be created
838      * @param resource The ContextResource to be named
839      *
840      * @exception MalformedObjectNameException if a name cannot be created
841      */

842     public static ObjectName JavaDoc createObjectName(String JavaDoc domain,
843                                               ContextResource resource)
844         throws MalformedObjectNameException JavaDoc {
845
846         ObjectName JavaDoc name = null;
847         String JavaDoc quotedResourceName = ObjectName.quote(resource.getName());
848         Object JavaDoc container =
849                 resource.getNamingResources().getContainer();
850         if (container instanceof Server JavaDoc) {
851             name = new ObjectName JavaDoc(domain + ":type=Resource" +
852                         ",resourcetype=Global,class=" + resource.getType() +
853                         ",name=" + quotedResourceName);
854         } else if (container instanceof Context) {
855             String JavaDoc path = ((Context)container).getPath();
856             if (path.length() < 1)
857                 path = "/";
858             Host host = (Host) ((Context)container).getParent();
859             Engine engine = (Engine) host.getParent();
860             Service service = engine.getService();
861             name = new ObjectName JavaDoc(domain + ":type=Resource" +
862                         ",resourcetype=Context,path=" + path +
863                         ",host=" + host.getName() +
864                         ",class=" + resource.getType() +
865                         ",name=" + quotedResourceName);
866         }
867         
868         return (name);
869
870     }
871   
872     
873      /**
874      * Create an <code>ObjectName</code> for this
875      * <code>ContextResourceLink</code> object.
876      *
877      * @param domain Domain in which this name is to be created
878      * @param resourceLink The ContextResourceLink to be named
879      *
880      * @exception MalformedObjectNameException if a name cannot be created
881      */

882     public static ObjectName JavaDoc createObjectName(String JavaDoc domain,
883                                               ContextResourceLink resourceLink)
884         throws MalformedObjectNameException JavaDoc {
885
886         ObjectName JavaDoc name = null;
887         String JavaDoc quotedResourceLinkName
888                 = ObjectName.quote(resourceLink.getName());
889         Object JavaDoc container =
890                 resourceLink.getNamingResources().getContainer();
891         if (container instanceof Server JavaDoc) {
892             name = new ObjectName JavaDoc(domain + ":type=ResourceLink" +
893                         ",resourcetype=Global" +
894                         ",name=" + quotedResourceLinkName);
895         } else if (container instanceof Context) {
896             String JavaDoc path = ((Context)container).getPath();
897             if (path.length() < 1)
898                 path = "/";
899             Host host = (Host) ((Context)container).getParent();
900             Engine engine = (Engine) host.getParent();
901             Service service = engine.getService();
902             name = new ObjectName JavaDoc(domain + ":type=ResourceLink" +
903                         ",resourcetype=Context,path=" + path +
904                         ",host=" + host.getName() +
905                         ",name=" + quotedResourceLinkName);
906         }
907         
908         return (name);
909
910     }
911     
912     
913  
914     /**
915      * Create an <code>ObjectName</code> for this
916      * <code>Engine</code> object.
917      *
918      * @param domain Domain in which this name is to be created
919      * @param engine The Engine to be named
920      *
921      * @exception MalformedObjectNameException if a name cannot be created
922      */

923     static ObjectName JavaDoc createObjectName(String JavaDoc domain,
924                                               Engine engine)
925         throws MalformedObjectNameException JavaDoc {
926
927         ObjectName JavaDoc name = null;
928         name = new ObjectName JavaDoc(domain + ":type=Engine");
929         return (name);
930
931     }
932
933
934     /**
935      * Create an <code>ObjectName</code> for this
936      * <code>Group</code> object.
937      *
938      * @param domain Domain in which this name is to be created
939      * @param group The Group to be named
940      *
941      * @exception MalformedObjectNameException if a name cannot be created
942      */

943     static ObjectName JavaDoc createObjectName(String JavaDoc domain,
944                                               Group group)
945         throws MalformedObjectNameException JavaDoc {
946
947         ObjectName JavaDoc name = null;
948         name = new ObjectName JavaDoc(domain + ":type=Group,groupname=" +
949                               ObjectName.quote(group.getGroupname()) +
950                               ",database=" + group.getUserDatabase().getId());
951         return (name);
952
953     }
954
955
956     /**
957      * Create an <code>ObjectName</code> for this
958      * <code>Host</code> object.
959      *
960      * @param domain Domain in which this name is to be created
961      * @param host The Host to be named
962      *
963      * @exception MalformedObjectNameException if a name cannot be created
964      */

965     static ObjectName JavaDoc createObjectName(String JavaDoc domain,
966                                               Host host)
967         throws MalformedObjectNameException JavaDoc {
968
969         ObjectName JavaDoc name = null;
970         Engine engine = (Engine)host.getParent();
971         Service service = engine.getService();
972         name = new ObjectName JavaDoc(domain + ":type=Host,host=" +
973                               host.getName());
974         return (name);
975
976     }
977
978
979     /**
980      * Create an <code>ObjectName</code> for this
981      * <code>Loader</code> object.
982      *
983      * @param domain Domain in which this name is to be created
984      * @param loader The Loader to be named
985      *
986      * @exception MalformedObjectNameException if a name cannot be created
987      */

988     static ObjectName JavaDoc createObjectName(String JavaDoc domain,
989                                               Loader loader)
990         throws MalformedObjectNameException JavaDoc {
991
992         ObjectName JavaDoc name = null;
993         Container container = loader.getContainer();
994
995         if (container instanceof Engine) {
996             Service service = ((Engine)container).getService();
997             name = new ObjectName JavaDoc(domain + ":type=Loader");
998         } else if (container instanceof Host) {
999             Engine engine = (Engine) container.getParent();
1000            Service service = engine.getService();
1001            name = new ObjectName JavaDoc(domain + ":type=Loader,host=" +
1002                              container.getName());
1003        } else if (container instanceof Context) {
1004            String JavaDoc path = ((Context)container).getPath();
1005            if (path.length() < 1) {
1006                path = "/";
1007            }
1008            Host host = (Host) container.getParent();
1009            Engine engine = (Engine) host.getParent();
1010            Service service = engine.getService();
1011            name = new ObjectName JavaDoc(domain + ":type=Loader,path=" + path +
1012                              ",host=" + host.getName());
1013        }
1014
1015        return (name);
1016
1017    }
1018
1019
1020    /**
1021     * Create an <code>ObjectName</code> for this
1022     * <code>Manager</code> object.
1023     *
1024     * @param domain Domain in which this name is to be created
1025     * @param manager The Manager to be named
1026     *
1027     * @exception MalformedObjectNameException if a name cannot be created
1028     */

1029    static ObjectName JavaDoc createObjectName(String JavaDoc domain,
1030                                              Manager manager)
1031        throws MalformedObjectNameException JavaDoc {
1032
1033        ObjectName JavaDoc name = null;
1034        Container container = manager.getContainer();
1035
1036        if (container instanceof Engine) {
1037            Service service = ((Engine)container).getService();
1038            name = new ObjectName JavaDoc(domain + ":type=Manager");
1039        } else if (container instanceof Host) {
1040            Engine engine = (Engine) container.getParent();
1041            Service service = engine.getService();
1042            name = new ObjectName JavaDoc(domain + ":type=Manager,host=" +
1043                              container.getName());
1044        } else if (container instanceof Context) {
1045            String JavaDoc path = ((Context)container).getPath();
1046            if (path.length() < 1) {
1047                path = "/";
1048            }
1049            Host host = (Host) container.getParent();
1050            Engine engine = (Engine) host.getParent();
1051            Service service = engine.getService();
1052            name = new ObjectName JavaDoc(domain + ":type=Manager,path=" + path +
1053                              ",host=" + host.getName());
1054        }
1055
1056        return (name);
1057
1058    }
1059    
1060    
1061    /**
1062     * Create an <code>ObjectName</code> for this
1063     * <code>Server</code> object.
1064     *
1065     * @param domain Domain in which this name is to be created
1066     * @param resources The NamingResources to be named
1067     *
1068     * @exception MalformedObjectNameException if a name cannot be created
1069     */

1070    static ObjectName JavaDoc createObjectName(String JavaDoc domain,
1071                                              NamingResources resources)
1072        throws MalformedObjectNameException JavaDoc {
1073
1074        ObjectName JavaDoc name = null;
1075        Object JavaDoc container = resources.getContainer();
1076        if (container instanceof Server JavaDoc) {
1077            name = new ObjectName JavaDoc(domain + ":type=NamingResources" +
1078                        ",resourcetype=Global");
1079        } else if (container instanceof Context) {
1080            String JavaDoc path = ((Context)container).getPath();
1081            if (path.length() < 1)
1082                path = "/";
1083            Host host = (Host) ((Context)container).getParent();
1084            Engine engine = (Engine) host.getParent();
1085            Service service = engine.getService();
1086            name = new ObjectName JavaDoc(domain + ":type=NamingResources" +
1087                        ",resourcetype=Context,path=" + path +
1088                        ",host=" + host.getName());
1089        }
1090        
1091        return (name);
1092
1093    }
1094
1095
1096    /**
1097     * Create an <code>ObjectName</code> for this
1098     * <code>MBeanFactory</code> object.
1099     *
1100     * @param domain Domain in which this name is to be created
1101     * @param factory The MBeanFactory to be named
1102     *
1103     * @exception MalformedObjectNameException if a name cannot be created
1104     */

1105    static ObjectName JavaDoc createObjectName(String JavaDoc domain,
1106                                              MBeanFactory factory)
1107        throws MalformedObjectNameException JavaDoc {
1108
1109        ObjectName JavaDoc name = new ObjectName JavaDoc(domain + ":type=MBeanFactory");
1110
1111        return (name);
1112
1113    }
1114
1115    
1116    /**
1117     * Create an <code>ObjectName</code> for this
1118     * <code>Realm</code> object.
1119     *
1120     * @param domain Domain in which this name is to be created
1121     * @param realm The Realm to be named
1122     *
1123     * @exception MalformedObjectNameException if a name cannot be created
1124     */

1125    static ObjectName JavaDoc createObjectName(String JavaDoc domain,
1126                                              Realm realm)
1127        throws MalformedObjectNameException JavaDoc {
1128
1129        ObjectName JavaDoc name = null;
1130        Container container = realm.getContainer();
1131
1132        if (container instanceof Engine) {
1133            Service service = ((Engine)container).getService();
1134            name = new ObjectName JavaDoc(domain + ":type=Realm");
1135        } else if (container instanceof Host) {
1136            Engine engine = (Engine) container.getParent();
1137            Service service = engine.getService();
1138            name = new ObjectName JavaDoc(domain + ":type=Realm,host=" +
1139                              container.getName());
1140        } else if (container instanceof Context) {
1141            String JavaDoc path = ((Context)container).getPath();
1142            if (path.length() < 1) {
1143                path = "/";
1144            }
1145            Host host = (Host) container.getParent();
1146            Engine engine = (Engine) host.getParent();
1147            Service service = engine.getService();
1148            name = new ObjectName JavaDoc(domain + ":type=Realm,path=" + path +
1149                              ",host=" + host.getName());
1150        }
1151
1152        return (name);
1153
1154    }
1155
1156
1157    /**
1158     * Create an <code>ObjectName</code> for this
1159     * <code>Role</code> object.
1160     *
1161     * @param domain Domain in which this name is to be created
1162     * @param role The Role to be named
1163     *
1164     * @exception MalformedObjectNameException if a name cannot be created
1165     */

1166    static ObjectName JavaDoc createObjectName(String JavaDoc domain,
1167                                              Role role)
1168        throws MalformedObjectNameException JavaDoc {
1169
1170        ObjectName JavaDoc name = null;
1171        name = new ObjectName JavaDoc(domain + ":type=Role,rolename=" +
1172                              role.getRolename() + ",database=" +
1173                              role.getUserDatabase().getId());
1174        return (name);
1175
1176    }
1177
1178
1179    /**
1180     * Create an <code>ObjectName</code> for this
1181     * <code>Server</code> object.
1182     *
1183     * @param domain Domain in which this name is to be created
1184     * @param server The Server to be named
1185     *
1186     * @exception MalformedObjectNameException if a name cannot be created
1187     */

1188    static ObjectName JavaDoc createObjectName(String JavaDoc domain,
1189                                              Server JavaDoc server)
1190        throws MalformedObjectNameException JavaDoc {
1191
1192        ObjectName JavaDoc name = null;
1193        name = new ObjectName JavaDoc(domain + ":type=Server");
1194        return (name);
1195
1196    }
1197
1198
1199    /**
1200     * Create an <code>ObjectName</code> for this
1201     * <code>Service</code> object.
1202     *
1203     * @param domain Domain in which this name is to be created
1204     * @param service The Service to be named
1205     *
1206     * @exception MalformedObjectNameException if a name cannot be created
1207     */

1208    static ObjectName JavaDoc createObjectName(String JavaDoc domain,
1209                                              Service service)
1210        throws MalformedObjectNameException JavaDoc {
1211
1212        ObjectName JavaDoc name = null;
1213        name = new ObjectName JavaDoc(domain + ":type=Service,serviceName=" +
1214                            service.getName());
1215        return (name);
1216
1217    }
1218
1219
1220    /**
1221     * Create an <code>ObjectName</code> for this
1222     * <code>User</code> object.
1223     *
1224     * @param domain Domain in which this name is to be created
1225     * @param user The User to be named
1226     *
1227     * @exception MalformedObjectNameException if a name cannot be created
1228     */

1229    static ObjectName JavaDoc createObjectName(String JavaDoc domain,
1230                                              User user)
1231        throws MalformedObjectNameException JavaDoc {
1232
1233        ObjectName JavaDoc name = null;
1234        name = new ObjectName JavaDoc(domain + ":type=User,username=" +
1235                              ObjectName.quote(user.getUsername())
1236                              + ",database=" + user.getUserDatabase().getId());
1237        return (name);
1238
1239    }
1240
1241
1242    /**
1243     * Create an <code>ObjectName</code> for this
1244     * <code>UserDatabase</code> object.
1245     *
1246     * @param domain Domain in which this name is to be created
1247     * @param userDatabase The UserDatabase to be named
1248     *
1249     * @exception MalformedObjectNameException if a name cannot be created
1250     */

1251    static ObjectName JavaDoc createObjectName(String JavaDoc domain,
1252                                              UserDatabase userDatabase)
1253        throws MalformedObjectNameException JavaDoc {
1254
1255        ObjectName JavaDoc name = null;
1256        name = new ObjectName JavaDoc(domain + ":type=UserDatabase,database=" +
1257                              userDatabase.getId());
1258        return (name);
1259
1260    }
1261
1262
1263    /**
1264     * Create an <code>ObjectName</code> for this
1265     * <code>Valve</code> object.
1266     *
1267     * @param domain Domain in which this name is to be created
1268     * @param valve The Valve to be named
1269     *
1270     * @exception MalformedObjectNameException if a name cannot be created
1271     */

1272    static ObjectName JavaDoc createObjectName(String JavaDoc domain,
1273                                       Valve valve)
1274        throws MalformedObjectNameException JavaDoc {
1275        if( valve instanceof ValveBase ) {
1276            ObjectName JavaDoc name=((ValveBase)valve).getObjectName();
1277            if( name != null )
1278                return name;
1279        }
1280
1281        ObjectName JavaDoc name = null;
1282        Container container = null;
1283        String JavaDoc className=valve.getClass().getName();
1284        int period = className.lastIndexOf('.');
1285        if (period >= 0)
1286            className = className.substring(period + 1);
1287        if( valve instanceof Contained ) {
1288            container = ((Contained)valve).getContainer();
1289        }
1290        if( container == null ) {
1291            throw new MalformedObjectNameException JavaDoc(
1292                               "Cannot create mbean for non-contained valve " +
1293                               valve);
1294        }
1295        if (container instanceof Engine) {
1296            Service service = ((Engine)container).getService();
1297            String JavaDoc local="";
1298            int seq = getSeq(local);
1299            String JavaDoc ext="";
1300            if( seq > 0 ) {
1301                ext=",seq=" + seq;
1302            }
1303            name = new ObjectName JavaDoc(domain + ":type=Valve,name=" + className +
1304                                    ext + local );
1305        } else if (container instanceof Host) {
1306            Service service = ((Engine)container.getParent()).getService();
1307            String JavaDoc local=",host=" +container.getName();
1308            int seq = getSeq(local);
1309            String JavaDoc ext="";
1310            if( seq > 0 ) {
1311                ext=",seq=" + seq;
1312            }
1313            name = new ObjectName JavaDoc(domain + ":type=Valve,name=" + className +
1314                                    ext + local );
1315        } else if (container instanceof Context) {
1316            String JavaDoc path = ((Context)container).getPath();
1317            if (path.length() < 1) {
1318                path = "/";
1319            }
1320            Host host = (Host) container.getParent();
1321            Service service = ((Engine) host.getParent()).getService();
1322            String JavaDoc local=",path=" + path + ",host=" +
1323                    host.getName();
1324            int seq = getSeq(local);
1325            String JavaDoc ext="";
1326            if( seq > 0 ) {
1327                ext=",seq=" + seq;
1328            }
1329            name = new ObjectName JavaDoc(domain + ":type=Valve,name=" + className +
1330                                    ext + local );
1331        }
1332
1333        return (name);
1334
1335    }
1336
1337    static Hashtable JavaDoc seq=new Hashtable JavaDoc();
1338    static int getSeq( String JavaDoc key ) {
1339        int i[]=(int [])seq.get( key );
1340        if (i == null ) {
1341            i=new int[1];
1342            i[0]=0;
1343            seq.put( key, i);
1344        } else {
1345            i[0]++;
1346        }
1347        return i[0];
1348    }
1349
1350    /**
1351     * Create and configure (if necessary) and return the registry of
1352     * managed object descriptions.
1353     */

1354    public synchronized static Registry createRegistry() {
1355
1356        if (registry == null) {
1357            registry = Registry.getRegistry(null, null);
1358            ClassLoader JavaDoc cl=ServerLifecycleListener.class.getClassLoader();
1359
1360            registry.loadDescriptors("org.apache.catalina.mbeans", cl);
1361            registry.loadDescriptors("org.apache.catalina.authenticator", cl);
1362            registry.loadDescriptors("org.apache.catalina.core", cl);
1363            registry.loadDescriptors("org.apache.catalina", cl);
1364            registry.loadDescriptors("org.apache.catalina.deploy", cl);
1365            registry.loadDescriptors("org.apache.catalina.loader", cl);
1366            registry.loadDescriptors("org.apache.catalina.realm", cl);
1367            registry.loadDescriptors("org.apache.catalina.session", cl);
1368            registry.loadDescriptors("org.apache.catalina.startup", cl);
1369            registry.loadDescriptors("org.apache.catalina.users", cl);
1370            registry.loadDescriptors("org.apache.catalina.ha", cl);
1371            registry.loadDescriptors("org.apache.catalina.connector", cl);
1372            registry.loadDescriptors("org.apache.catalina.valves", cl);
1373        }
1374        return (registry);
1375
1376    }
1377
1378
1379    /**
1380     * Create and configure (if necessary) and return the
1381     * <code>MBeanServer</code> with which we will be
1382     * registering our <code>DynamicMBean</code> implementations.
1383     */

1384    public synchronized static MBeanServer JavaDoc createServer() {
1385
1386        if (mserver == null) {
1387            try {
1388                mserver = Registry.getRegistry(null, null).getMBeanServer();
1389            } catch (Throwable JavaDoc t) {
1390                t.printStackTrace(System.out);
1391                System.exit(1);
1392            }
1393        }
1394        return (mserver);
1395
1396    }
1397
1398
1399    /**
1400     * Deregister the MBean for this
1401     * <code>Connector</code> object.
1402     *
1403     * @param connector The Connector to be managed
1404     *
1405     * @exception Exception if an MBean cannot be deregistered
1406     */

1407    static void destroyMBean(Connector connector, Service service)
1408        throws Exception JavaDoc {
1409
1410        connector.setService(service);
1411        String JavaDoc mname = createManagedName(connector);
1412        ManagedBean managed = registry.findManagedBean(mname);
1413        if (managed == null) {
1414            return;
1415        }
1416        String JavaDoc domain = managed.getDomain();
1417        if (domain == null)
1418            domain = mserver.getDefaultDomain();
1419        ObjectName JavaDoc oname = createObjectName(domain, connector);
1420        connector.setService(null);
1421        if( mserver.isRegistered( oname )) {
1422            mserver.unregisterMBean(oname);
1423        }
1424    }
1425
1426
1427    /**
1428     * Deregister the MBean for this
1429     * <code>Context</code> object.
1430     *
1431     * @param context The Context to be managed
1432     *
1433     * @exception Exception if an MBean cannot be deregistered
1434     */

1435    static void destroyMBean(Context context)
1436        throws Exception JavaDoc {
1437
1438        String JavaDoc mname = createManagedName(context);
1439        ManagedBean managed = registry.findManagedBean(mname);
1440        if (managed == null) {
1441            return;
1442        }
1443        String JavaDoc domain = managed.getDomain();
1444        if (domain == null)
1445            domain = mserver.getDefaultDomain();
1446        ObjectName JavaDoc oname = createObjectName(domain, context);
1447        if( mserver.isRegistered(oname) )
1448            mserver.unregisterMBean(oname);
1449
1450    }
1451
1452    
1453    /**
1454     * Deregister the MBean for this
1455     * <code>ContextEnvironment</code> object.
1456     *
1457     * @param environment The ContextEnvironment to be managed
1458     *
1459     * @exception Exception if an MBean cannot be deregistered
1460     */

1461    static void destroyMBean(ContextEnvironment environment)
1462        throws Exception JavaDoc {
1463
1464        String JavaDoc mname = createManagedName(environment);
1465        ManagedBean managed = registry.findManagedBean(mname);
1466        if (managed == null) {
1467            return;
1468        }
1469        String JavaDoc domain = managed.getDomain();
1470        if (domain == null)
1471            domain = mserver.getDefaultDomain();
1472        ObjectName JavaDoc oname = createObjectName(domain, environment);
1473        if( mserver.isRegistered(oname) )
1474            mserver.unregisterMBean(oname);
1475
1476    }
1477    
1478    
1479    /**
1480     * Deregister the MBean for this
1481     * <code>ContextResource</code> object.
1482     *
1483     * @param resource The ContextResource to be managed
1484     *
1485     * @exception Exception if an MBean cannot be deregistered
1486     */

1487    static void destroyMBean(ContextResource resource)
1488        throws Exception JavaDoc {
1489
1490        String JavaDoc mname = createManagedName(resource);
1491        ManagedBean managed = registry.findManagedBean(mname);
1492        if (managed == null) {
1493            return;
1494        }
1495        String JavaDoc domain = managed.getDomain();
1496        if (domain == null)
1497            domain = mserver.getDefaultDomain();
1498        ObjectName JavaDoc oname = createObjectName(domain, resource);
1499        if( mserver.isRegistered(oname ))
1500            mserver.unregisterMBean(oname);
1501
1502    }
1503     
1504    
1505    /**
1506     * Deregister the MBean for this
1507     * <code>ContextResourceLink</code> object.
1508     *
1509     * @param resourceLink The ContextResourceLink to be managed
1510     *
1511     * @exception Exception if an MBean cannot be deregistered
1512     */

1513    static void destroyMBean(ContextResourceLink resourceLink)
1514        throws Exception JavaDoc {
1515
1516        String JavaDoc mname = createManagedName(resourceLink);
1517        ManagedBean managed = registry.findManagedBean(mname);
1518        if (managed == null) {
1519            return;
1520        }
1521        String JavaDoc domain = managed.getDomain();
1522        if (domain == null)
1523            domain = mserver.getDefaultDomain();
1524        ObjectName JavaDoc oname = createObjectName(domain, resourceLink);
1525        if( mserver.isRegistered(oname) )
1526            mserver.unregisterMBean(oname);
1527
1528    }
1529    
1530    /**
1531     * Deregister the MBean for this
1532     * <code>Engine</code> object.
1533     *
1534     * @param engine The Engine to be managed
1535     *
1536     * @exception Exception if an MBean cannot be deregistered
1537     */

1538    static void destroyMBean(Engine engine)
1539        throws Exception JavaDoc {
1540
1541        String JavaDoc mname = createManagedName(engine);
1542        ManagedBean managed = registry.findManagedBean(mname);
1543        if (managed == null) {
1544            return;
1545        }
1546        String JavaDoc domain = managed.getDomain();
1547        if (domain == null)
1548            domain = mserver.getDefaultDomain();
1549        ObjectName JavaDoc oname = createObjectName(domain, engine);
1550        if( mserver.isRegistered(oname) )
1551            mserver.unregisterMBean(oname);
1552
1553    }
1554
1555
1556    /**
1557     * Deregister the MBean for this
1558     * <code>Group</code> object.
1559     *
1560     * @param group The Group to be managed
1561     *
1562     * @exception Exception if an MBean cannot be deregistered
1563     */

1564    static void destroyMBean(Group group)
1565        throws Exception JavaDoc {
1566
1567        String JavaDoc mname = createManagedName(group);
1568        ManagedBean managed = registry.findManagedBean(mname);
1569        if (managed == null) {
1570            return;
1571        }
1572        String JavaDoc domain = managed.getDomain();
1573        if (domain == null)
1574            domain = mserver.getDefaultDomain();
1575        ObjectName JavaDoc oname = createObjectName(domain, group);
1576        if( mserver.isRegistered(oname) )
1577            mserver.unregisterMBean(oname);
1578
1579    }
1580
1581
1582    /**
1583     * Deregister the MBean for this
1584     * <code>Host</code> object.
1585     *
1586     * @param host The Host to be managed
1587     *
1588     * @exception Exception if an MBean cannot be deregistered
1589     */

1590    static void destroyMBean(Host host)
1591        throws Exception JavaDoc {
1592
1593        String JavaDoc mname = createManagedName(host);
1594        ManagedBean managed = registry.findManagedBean(mname);
1595        if (managed == null) {
1596            return;
1597        }
1598        String JavaDoc domain = managed.getDomain();
1599        if (domain == null)
1600            domain = mserver.getDefaultDomain();
1601        ObjectName JavaDoc oname = createObjectName(domain, host);
1602        if( mserver.isRegistered(oname) )
1603            mserver.unregisterMBean(oname);
1604
1605    }
1606
1607
1608    /**
1609     * Deregister the MBean for this
1610     * <code>Loader</code> object.
1611     *
1612     * @param loader The Loader to be managed
1613     *
1614     * @exception Exception if an MBean cannot be deregistered
1615     */

1616    static void destroyMBean(Loader loader)
1617        throws Exception JavaDoc {
1618
1619        String JavaDoc mname = createManagedName(loader);
1620        ManagedBean managed = registry.findManagedBean(mname);
1621        if (managed == null) {
1622            return;
1623        }
1624        String JavaDoc domain = managed.getDomain();
1625        if (domain == null)
1626            domain = mserver.getDefaultDomain();
1627        ObjectName JavaDoc oname = createObjectName(domain, loader);
1628        if( mserver.isRegistered(oname) )
1629            mserver.unregisterMBean(oname);
1630
1631    }
1632
1633
1634    /**
1635     * Deregister the MBean for this
1636     * <code>Manager</code> object.
1637     *
1638     * @param manager The Manager to be managed
1639     *
1640     * @exception Exception if an MBean cannot be deregistered
1641     */

1642    static void destroyMBean(Manager manager)
1643        throws Exception JavaDoc {
1644
1645        String JavaDoc mname = createManagedName(manager);
1646        ManagedBean managed = registry.findManagedBean(mname);
1647        if (managed == null) {
1648            return;
1649        }
1650        String JavaDoc domain = managed.getDomain();
1651        if (domain == null)
1652            domain = mserver.getDefaultDomain();
1653        ObjectName JavaDoc oname = createObjectName(domain, manager);
1654        if( mserver.isRegistered(oname) )
1655            mserver.unregisterMBean(oname);
1656
1657    }
1658    
1659    
1660   /**
1661     * Deregister the MBean for this
1662     * <code>NamingResources</code> object.
1663     *
1664     * @param resources The NamingResources to be managed
1665     *
1666     * @exception Exception if an MBean cannot be deregistered
1667     */

1668    static void destroyMBean(NamingResources resources)
1669        throws Exception JavaDoc {
1670
1671        String JavaDoc mname = createManagedName(resources);
1672        ManagedBean managed = registry.findManagedBean(mname);
1673        if (managed == null) {
1674            return;
1675        }
1676        String JavaDoc domain = managed.getDomain();
1677        if (domain == null)
1678            domain = mserver.getDefaultDomain();
1679        ObjectName JavaDoc oname = createObjectName(domain, resources);
1680       if( mserver.isRegistered(oname) )
1681            mserver.unregisterMBean(oname);
1682
1683    }
1684    
1685    
1686    /**
1687     * Deregister the MBean for this
1688     * <code>Realm</code> object.
1689     *
1690     * @param realm The Realm to be managed
1691     *
1692     * @exception Exception if an MBean cannot be deregistered
1693     */

1694    static void destroyMBean(Realm realm)
1695        throws Exception JavaDoc {
1696
1697        String JavaDoc mname = createManagedName(realm);
1698        ManagedBean managed = registry.findManagedBean(mname);
1699        if (managed == null) {
1700            return;
1701        }
1702        String JavaDoc domain = managed.getDomain();
1703        if (domain == null)
1704            domain = mserver.getDefaultDomain();
1705        ObjectName JavaDoc oname = createObjectName(domain, realm);
1706        if( mserver.isRegistered(oname) )
1707            mserver.unregisterMBean(oname);
1708
1709    }
1710
1711
1712    /**
1713     * Deregister the MBean for this
1714     * <code>Role</code> object.
1715     *
1716     * @param role The Role to be managed
1717     *
1718     * @exception Exception if an MBean cannot be deregistered
1719     */

1720    static void destroyMBean(Role role)
1721        throws Exception JavaDoc {
1722
1723        String JavaDoc mname = createManagedName(role);
1724        ManagedBean managed = registry.findManagedBean(mname);
1725        if (managed == null) {
1726            return;
1727        }
1728        String JavaDoc domain = managed.getDomain();
1729        if (domain == null)
1730            domain = mserver.getDefaultDomain();
1731        ObjectName JavaDoc oname = createObjectName(domain, role);
1732        if( mserver.isRegistered(oname) )
1733            mserver.unregisterMBean(oname);
1734
1735    }
1736
1737
1738    /**
1739     * Deregister the MBean for this
1740     * <code>Server</code> object.
1741     *
1742     * @param server The Server to be managed
1743     *
1744     * @exception Exception if an MBean cannot be deregistered
1745     */

1746    static void destroyMBean(Server JavaDoc server)
1747        throws Exception JavaDoc {
1748
1749        String JavaDoc mname = createManagedName(server);
1750        ManagedBean managed = registry.findManagedBean(mname);
1751        if (managed == null) {
1752            return;
1753        }
1754        String JavaDoc domain = managed.getDomain();
1755        if (domain == null)
1756            domain = mserver.getDefaultDomain();
1757        ObjectName JavaDoc oname = createObjectName(domain, server);
1758        if( mserver.isRegistered(oname) )
1759            mserver.unregisterMBean(oname);
1760
1761    }
1762
1763
1764    /**
1765     * Deregister the MBean for this
1766     * <code>Service</code> object.
1767     *
1768     * @param service The Service to be managed
1769     *
1770     * @exception Exception if an MBean cannot be deregistered
1771     */

1772    static void destroyMBean(Service service)
1773        throws Exception JavaDoc {
1774
1775        String JavaDoc mname = createManagedName(service);
1776        ManagedBean managed = registry.findManagedBean(mname);
1777        if (managed == null) {
1778            return;
1779        }
1780        String JavaDoc domain = managed.getDomain();
1781        if (domain == null)
1782            domain = mserver.getDefaultDomain();
1783        ObjectName JavaDoc oname = createObjectName(domain, service);
1784        if( mserver.isRegistered(oname) )
1785            mserver.unregisterMBean(oname);
1786
1787    }
1788
1789
1790    /**
1791     * Deregister the MBean for this
1792     * <code>User</code> object.
1793     *
1794     * @param user The User to be managed
1795     *
1796     * @exception Exception if an MBean cannot be deregistered
1797     */

1798    static void destroyMBean(User user)
1799        throws Exception JavaDoc {
1800
1801        String JavaDoc mname = createManagedName(user);
1802        ManagedBean managed = registry.findManagedBean(mname);
1803        if (managed == null) {
1804            return;
1805        }
1806        String JavaDoc domain = managed.getDomain();
1807        if (domain == null)
1808            domain = mserver.getDefaultDomain();
1809        ObjectName JavaDoc oname = createObjectName(domain, user);
1810        if( mserver.isRegistered(oname) )
1811            mserver.unregisterMBean(oname);
1812
1813    }
1814
1815
1816    /**
1817     * Deregister the MBean for this
1818     * <code>UserDatabase</code> object.
1819     *
1820     * @param userDatabase The UserDatabase to be managed
1821     *
1822     * @exception Exception if an MBean cannot be deregistered
1823     */

1824    static void destroyMBean(UserDatabase userDatabase)
1825        throws Exception JavaDoc {
1826
1827        String JavaDoc mname = createManagedName(userDatabase);
1828        ManagedBean managed = registry.findManagedBean(mname);
1829        if (managed == null) {
1830            return;
1831        }
1832        String JavaDoc domain = managed.getDomain();
1833        if (domain == null)
1834            domain = mserver.getDefaultDomain();
1835        ObjectName JavaDoc oname = createObjectName(domain, userDatabase);
1836        if( mserver.isRegistered(oname) )
1837            mserver.unregisterMBean(oname);
1838
1839    }
1840
1841
1842    /**
1843     * Deregister the MBean for this
1844     * <code>Valve</code> object.
1845     *
1846     * @param valve The Valve to be managed
1847     *
1848     * @exception Exception if an MBean cannot be deregistered
1849     */

1850    static void destroyMBean(Valve valve, Container container)
1851        throws Exception JavaDoc {
1852
1853        ((Contained)valve).setContainer(container);
1854        String JavaDoc mname = createManagedName(valve);
1855        ManagedBean managed = registry.findManagedBean(mname);
1856        if (managed == null) {
1857            return;
1858        }
1859        String JavaDoc domain = managed.getDomain();
1860        if (domain == null)
1861            domain = mserver.getDefaultDomain();
1862        ObjectName JavaDoc oname = createObjectName(domain, valve);
1863        try {
1864            ((Contained)valve).setContainer(null);
1865        } catch (Throwable JavaDoc t) {
1866        ;
1867        }
1868        if( mserver.isRegistered(oname) ) {
1869            mserver.unregisterMBean(oname);
1870        }
1871
1872    }
1873
1874}
1875
Popular Tags