Source Code Cross Referenced for MBeanUtils.java in  » Web-Server » Rimfaxe-Web-Server » org » apache » catalina » mbeans » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Web Server » Rimfaxe Web Server » org.apache.catalina.mbeans 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /*
0002:         * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/mbeans/MBeanUtils.java,v 1.42 2002/06/14 13:29:48 amyroh Exp $
0003:         * $Revision: 1.42 $
0004:         * $Date: 2002/06/14 13:29:48 $
0005:         *
0006:         * ====================================================================
0007:         *
0008:         * The Apache Software License, Version 1.1
0009:         *
0010:         * Copyright (c) 1999 The Apache Software Foundation.  All rights
0011:         * reserved.
0012:         *
0013:         * Redistribution and use in source and binary forms, with or without
0014:         * modification, are permitted provided that the following conditions
0015:         * are met:
0016:         *
0017:         * 1. Redistributions of source code must retain the above copyright
0018:         *    notice, this list of conditions and the following disclaimer.
0019:         *
0020:         * 2. Redistributions in binary form must reproduce the above copyright
0021:         *    notice, this list of conditions and the following disclaimer in
0022:         *    the documentation and/or other materials provided with the
0023:         *    distribution.
0024:         *
0025:         * 3. The end-user documentation included with the redistribution, if
0026:         *    any, must include the following acknowlegement:
0027:         *       "This product includes software developed by the
0028:         *        Apache Software Foundation (http://www.apache.org/)."
0029:         *    Alternately, this acknowlegement may appear in the software itself,
0030:         *    if and wherever such third-party acknowlegements normally appear.
0031:         *
0032:         * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
0033:         *    Foundation" must not be used to endorse or promote products derived
0034:         *    from this software without prior written permission. For written
0035:         *    permission, please contact apache@apache.org.
0036:         *
0037:         * 5. Products derived from this software may not be called "Apache"
0038:         *    nor may "Apache" appear in their names without prior written
0039:         *    permission of the Apache Group.
0040:         *
0041:         * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
0042:         * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
0043:         * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
0044:         * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
0045:         * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
0046:         * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
0047:         * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
0048:         * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
0049:         * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
0050:         * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
0051:         * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
0052:         * SUCH DAMAGE.
0053:         * ====================================================================
0054:         *
0055:         * This software consists of voluntary contributions made by many
0056:         * individuals on behalf of the Apache Software Foundation.  For more
0057:         * information on the Apache Software Foundation, please see
0058:         * <http://www.apache.org/>.
0059:         *
0060:         * [Additional notices, if required by prior licensing conditions]
0061:         *
0062:         */
0063:
0064:        package org.apache.catalina.mbeans;
0065:
0066:        import java.io.InputStream;
0067:        import java.net.URL;
0068:        import java.net.URLEncoder;
0069:        import javax.management.InstanceAlreadyExistsException;
0070:        import javax.management.MalformedObjectNameException;
0071:        import javax.management.MBeanException;
0072:        import javax.management.MBeanServer;
0073:        import javax.management.MBeanServerFactory;
0074:        import javax.management.NotCompliantMBeanException;
0075:        import javax.management.ObjectName;
0076:        import javax.management.OperationsException;
0077:        import javax.management.modelmbean.InvalidTargetObjectTypeException;
0078:        import javax.management.modelmbean.ModelMBean;
0079:        import org.apache.catalina.Connector;
0080:        import org.apache.catalina.Contained;
0081:        import org.apache.catalina.Container;
0082:        import org.apache.catalina.Context;
0083:        import org.apache.catalina.DefaultContext;
0084:        import org.apache.catalina.Engine;
0085:        import org.apache.catalina.Group;
0086:        import org.apache.catalina.Host;
0087:        import org.apache.catalina.LifecycleEvent;
0088:        import org.apache.catalina.LifecycleListener;
0089:        import org.apache.catalina.Loader;
0090:        import org.apache.catalina.Logger;
0091:        import org.apache.catalina.Manager;
0092:        import org.apache.catalina.Realm;
0093:        import org.apache.catalina.Role;
0094:        import org.apache.catalina.Server;
0095:        import org.apache.catalina.ServerFactory;
0096:        import org.apache.catalina.Service;
0097:        import org.apache.catalina.User;
0098:        import org.apache.catalina.UserDatabase;
0099:        import org.apache.catalina.Valve;
0100:        import org.apache.catalina.connector.http.HttpConnector;
0101:        import org.apache.catalina.core.StandardService;
0102:        import org.apache.catalina.deploy.ContextEnvironment;
0103:        import org.apache.catalina.deploy.ContextResource;
0104:        import org.apache.catalina.deploy.ContextResourceLink;
0105:        import org.apache.catalina.deploy.NamingResources;
0106:        import org.apache.catalina.deploy.ResourceParams;
0107:        import org.apache.catalina.valves.ValveBase;
0108:        import org.apache.commons.beanutils.PropertyUtils;
0109:        import org.apache.commons.modeler.ManagedBean;
0110:        import org.apache.commons.modeler.Registry;
0111:
0112:        /**
0113:         * Public utility methods in support of the server side MBeans implementation.
0114:         *
0115:         * @author Craig R. McClanahan
0116:         * @author Amy Roh
0117:         * @version $Revision: 1.42 $ $Date: 2002/06/14 13:29:48 $
0118:         */
0119:
0120:        public class MBeanUtils {
0121:
0122:            // ------------------------------------------------------- Static Variables
0123:
0124:            /**
0125:             * The set of exceptions to the normal rules used by
0126:             * <code>createManagedBean()</code>.  The first element of each pair
0127:             * is a class name, and the second element is the managed bean name.
0128:             */
0129:            private static String exceptions[][] = {
0130:                    { "org.apache.ajp.tomcat4.Ajp13Connector", "Ajp13Connector" },
0131:                    { "org.apache.coyote.tomcat4.Ajp13Connector",
0132:                            "CoyoteConnector" },
0133:                    { "org.apache.catalina.core.StandardDefaultContext",
0134:                            "DefaultContext" },
0135:                    { "org.apache.catalina.connector.http10.HttpConnector",
0136:                            "Http10Connector" },
0137:                    { "org.apache.catalina.connector.http.HttpConnector",
0138:                            "Http11Connector" },
0139:                    { "org.apache.catalina.users.JDBCGroup", "Group" },
0140:                    { "org.apache.catalina.users.JDBCRole", "Role" },
0141:                    { "org.apache.catalina.users.JDBCUser", "User" },
0142:                    { "org.apache.catalina.users.MemoryGroup", "Group" },
0143:                    { "org.apache.catalina.users.MemoryRole", "Role" },
0144:                    { "org.apache.catalina.users.MemoryUser", "User" }, };
0145:
0146:            /**
0147:             * The configuration information registry for our managed beans.
0148:             */
0149:            private static Registry registry = createRegistry();
0150:
0151:            /**
0152:             * The <code>MBeanServer</code> for this application.
0153:             */
0154:            private static MBeanServer mserver = createServer();
0155:
0156:            // --------------------------------------------------------- Static Methods
0157:
0158:            /**
0159:             * Translates a string into x-www-form-urlencoded format
0160:             *
0161:             * @param t string to be encoded
0162:             * @return encoded string
0163:             */
0164:            private static final String encodeStr(String t) {
0165:
0166:                return URLEncoder.encode(t);
0167:
0168:            }
0169:
0170:            /**
0171:             * Create and return the name of the <code>ManagedBean</code> that
0172:             * corresponds to this Catalina component.
0173:             *
0174:             * @param component The component for which to create a name
0175:             */
0176:            public static String createManagedName(Object component) {
0177:
0178:                // Deal with exceptions to the standard rule
0179:                String className = component.getClass().getName();
0180:                for (int i = 0; i < exceptions.length; i++) {
0181:                    if (className.equals(exceptions[i][0])) {
0182:                        return (exceptions[i][1]);
0183:                    }
0184:                }
0185:
0186:                // Perform the standard transformation
0187:                int period = className.lastIndexOf('.');
0188:                if (period >= 0)
0189:                    className = className.substring(period + 1);
0190:                return (className);
0191:
0192:            }
0193:
0194:            /**
0195:             * Create, register, and return an MBean for this
0196:             * <code>Connector</code> object.
0197:             *
0198:             * @param connector The Connector to be managed
0199:             *
0200:             * @exception Exception if an MBean cannot be created or registered
0201:             */
0202:            public static ModelMBean createMBean(Connector connector)
0203:                    throws Exception {
0204:
0205:                String mname = createManagedName(connector);
0206:                ManagedBean managed = registry.findManagedBean(mname);
0207:                if (managed == null) {
0208:                    Exception e = new Exception(
0209:                            "ManagedBean is not found with " + mname);
0210:                    throw new MBeanException(e);
0211:                }
0212:                String domain = managed.getDomain();
0213:                if (domain == null)
0214:                    domain = mserver.getDefaultDomain();
0215:                ModelMBean mbean = managed.createMBean(connector);
0216:                ObjectName oname = createObjectName(domain, connector);
0217:                mserver.registerMBean(mbean, oname);
0218:                return (mbean);
0219:
0220:            }
0221:
0222:            /**
0223:             * Create, register, and return an MBean for this
0224:             * <code>Context</code> object.
0225:             *
0226:             * @param context The Context to be managed
0227:             *
0228:             * @exception Exception if an MBean cannot be created or registered
0229:             */
0230:            public static ModelMBean createMBean(Context context)
0231:                    throws Exception {
0232:
0233:                String mname = createManagedName(context);
0234:                ManagedBean managed = registry.findManagedBean(mname);
0235:                if (managed == null) {
0236:                    Exception e = new Exception(
0237:                            "ManagedBean is not found with " + mname);
0238:                    throw new MBeanException(e);
0239:                }
0240:                String domain = managed.getDomain();
0241:                if (domain == null)
0242:                    domain = mserver.getDefaultDomain();
0243:                ModelMBean mbean = managed.createMBean(context);
0244:                ObjectName oname = createObjectName(domain, context);
0245:                mserver.registerMBean(mbean, oname);
0246:                return (mbean);
0247:
0248:            }
0249:
0250:            /**
0251:             * Create, register, and return an MBean for this
0252:             * <code>ContextEnvironment</code> object.
0253:             *
0254:             * @param environment The ContextEnvironment to be managed
0255:             *
0256:             * @exception Exception if an MBean cannot be created or registered
0257:             */
0258:            public static ModelMBean createMBean(ContextEnvironment environment)
0259:                    throws Exception {
0260:
0261:                String mname = createManagedName(environment);
0262:                ManagedBean managed = registry.findManagedBean(mname);
0263:                if (managed == null) {
0264:                    Exception e = new Exception(
0265:                            "ManagedBean is not found with " + mname);
0266:                    throw new MBeanException(e);
0267:                }
0268:                String domain = managed.getDomain();
0269:                if (domain == null)
0270:                    domain = mserver.getDefaultDomain();
0271:                ModelMBean mbean = managed.createMBean(environment);
0272:                ObjectName oname = createObjectName(domain, environment);
0273:                mserver.registerMBean(mbean, oname);
0274:                return (mbean);
0275:
0276:            }
0277:
0278:            /**
0279:             * Create, register, and return an MBean for this
0280:             * <code>ContextResource</code> object.
0281:             *
0282:             * @param resource The ContextResource to be managed
0283:             *
0284:             * @exception Exception if an MBean cannot be created or registered
0285:             */
0286:            public static ModelMBean createMBean(ContextResource resource)
0287:                    throws Exception {
0288:
0289:                String mname = createManagedName(resource);
0290:                ManagedBean managed = registry.findManagedBean(mname);
0291:                if (managed == null) {
0292:                    Exception e = new Exception(
0293:                            "ManagedBean is not found with " + mname);
0294:                    throw new MBeanException(e);
0295:                }
0296:                String domain = managed.getDomain();
0297:                if (domain == null)
0298:                    domain = mserver.getDefaultDomain();
0299:                ModelMBean mbean = managed.createMBean(resource);
0300:                ObjectName oname = createObjectName(domain, resource);
0301:                mserver.registerMBean(mbean, oname);
0302:                return (mbean);
0303:
0304:            }
0305:
0306:            /**
0307:             * Create, register, and return an MBean for this
0308:             * <code>ContextResourceLink</code> object.
0309:             *
0310:             * @param resourceLink The ContextResourceLink to be managed
0311:             *
0312:             * @exception Exception if an MBean cannot be created or registered
0313:             */
0314:            public static ModelMBean createMBean(
0315:                    ContextResourceLink resourceLink) throws Exception {
0316:
0317:                String mname = createManagedName(resourceLink);
0318:                ManagedBean managed = registry.findManagedBean(mname);
0319:                if (managed == null) {
0320:                    Exception e = new Exception(
0321:                            "ManagedBean is not found with " + mname);
0322:                    throw new MBeanException(e);
0323:                }
0324:                String domain = managed.getDomain();
0325:                if (domain == null)
0326:                    domain = mserver.getDefaultDomain();
0327:                ModelMBean mbean = managed.createMBean(resourceLink);
0328:                ObjectName oname = createObjectName(domain, resourceLink);
0329:                mserver.registerMBean(mbean, oname);
0330:                return (mbean);
0331:
0332:            }
0333:
0334:            /**
0335:             * Create, register, and return an MBean for this
0336:             * <code>DefaultContext</code> object.
0337:             *
0338:             * @param context The DefaultContext to be managed
0339:             *
0340:             * @exception Exception if an MBean cannot be created or registered
0341:             */
0342:            public static ModelMBean createMBean(DefaultContext context)
0343:                    throws Exception {
0344:
0345:                String mname = createManagedName(context);
0346:                ManagedBean managed = registry.findManagedBean(mname);
0347:                if (managed == null) {
0348:                    Exception e = new Exception(
0349:                            "ManagedBean is not found with " + mname);
0350:                    throw new MBeanException(e);
0351:                }
0352:                String domain = managed.getDomain();
0353:                if (domain == null)
0354:                    domain = mserver.getDefaultDomain();
0355:                ModelMBean mbean = managed.createMBean(context);
0356:                ObjectName oname = createObjectName(domain, context);
0357:                mserver.registerMBean(mbean, oname);
0358:                return (mbean);
0359:
0360:            }
0361:
0362:            /**
0363:             * Create, register, and return an MBean for this
0364:             * <code>Engine</code> object.
0365:             *
0366:             * @param engine The Engine to be managed
0367:             *
0368:             * @exception Exception if an MBean cannot be created or registered
0369:             */
0370:            public static ModelMBean createMBean(Engine engine)
0371:                    throws Exception {
0372:
0373:                String mname = createManagedName(engine);
0374:                ManagedBean managed = registry.findManagedBean(mname);
0375:                if (managed == null) {
0376:                    Exception e = new Exception(
0377:                            "ManagedBean is not found with " + mname);
0378:                    throw new MBeanException(e);
0379:                }
0380:                String domain = managed.getDomain();
0381:                if (domain == null)
0382:                    domain = mserver.getDefaultDomain();
0383:                ModelMBean mbean = managed.createMBean(engine);
0384:                ObjectName oname = createObjectName(domain, engine);
0385:                mserver.registerMBean(mbean, oname);
0386:                return (mbean);
0387:
0388:            }
0389:
0390:            /**
0391:             * Create, register, and return an MBean for this
0392:             * <code>Group</code> object.
0393:             *
0394:             * @param group The Group to be managed
0395:             *
0396:             * @exception Exception if an MBean cannot be created or registered
0397:             */
0398:            public static ModelMBean createMBean(Group group) throws Exception {
0399:
0400:                String mname = createManagedName(group);
0401:                ManagedBean managed = registry.findManagedBean(mname);
0402:                if (managed == null) {
0403:                    Exception e = new Exception(
0404:                            "ManagedBean is not found with " + mname);
0405:                    throw new MBeanException(e);
0406:                }
0407:                String domain = managed.getDomain();
0408:                if (domain == null)
0409:                    domain = mserver.getDefaultDomain();
0410:                ModelMBean mbean = managed.createMBean(group);
0411:                ObjectName oname = createObjectName(domain, group);
0412:                mserver.registerMBean(mbean, oname);
0413:                return (mbean);
0414:
0415:            }
0416:
0417:            /**
0418:             * Create, register, and return an MBean for this
0419:             * <code>Host</code> object.
0420:             *
0421:             * @param host The Host to be managed
0422:             *
0423:             * @exception Exception if an MBean cannot be created or registered
0424:             */
0425:            public static ModelMBean createMBean(Host host) throws Exception {
0426:
0427:                String mname = createManagedName(host);
0428:                ManagedBean managed = registry.findManagedBean(mname);
0429:                if (managed == null) {
0430:                    Exception e = new Exception(
0431:                            "ManagedBean is not found with " + mname);
0432:                    throw new MBeanException(e);
0433:                }
0434:                String domain = managed.getDomain();
0435:                if (domain == null)
0436:                    domain = mserver.getDefaultDomain();
0437:                ModelMBean mbean = managed.createMBean(host);
0438:                ObjectName oname = createObjectName(domain, host);
0439:                mserver.registerMBean(mbean, oname);
0440:                return (mbean);
0441:
0442:            }
0443:
0444:            /**
0445:             * Create, register, and return an MBean for this
0446:             * <code>Loader</code> object.
0447:             *
0448:             * @param loader The Loader to be managed
0449:             *
0450:             * @exception Exception if an MBean cannot be created or registered
0451:             */
0452:            public static ModelMBean createMBean(Loader loader)
0453:                    throws Exception {
0454:
0455:                String mname = createManagedName(loader);
0456:                ManagedBean managed = registry.findManagedBean(mname);
0457:                if (managed == null) {
0458:                    Exception e = new Exception(
0459:                            "ManagedBean is not found with " + mname);
0460:                    throw new MBeanException(e);
0461:                }
0462:                String domain = managed.getDomain();
0463:                if (domain == null)
0464:                    domain = mserver.getDefaultDomain();
0465:                ModelMBean mbean = managed.createMBean(loader);
0466:                ObjectName oname = createObjectName(domain, loader);
0467:                mserver.registerMBean(mbean, oname);
0468:                return (mbean);
0469:
0470:            }
0471:
0472:            /**
0473:             * Create, register, and return an MBean for this
0474:             * <code>Logger</code> object.
0475:             *
0476:             * @param logger The Logger to be managed
0477:             *
0478:             * @exception Exception if an MBean cannot be created or registered
0479:             */
0480:            public static ModelMBean createMBean(Logger logger)
0481:                    throws Exception {
0482:
0483:                String mname = createManagedName(logger);
0484:                ManagedBean managed = registry.findManagedBean(mname);
0485:                if (managed == null) {
0486:                    Exception e = new Exception(
0487:                            "ManagedBean is not found with " + mname);
0488:                    throw new MBeanException(e);
0489:                }
0490:                String domain = managed.getDomain();
0491:                if (domain == null)
0492:                    domain = mserver.getDefaultDomain();
0493:                ModelMBean mbean = managed.createMBean(logger);
0494:                ObjectName oname = createObjectName(domain, logger);
0495:                mserver.registerMBean(mbean, oname);
0496:                return (mbean);
0497:
0498:            }
0499:
0500:            /**
0501:             * Create, register, and return an MBean for this
0502:             * <code>Manager</code> object.
0503:             *
0504:             * @param manager The Manager to be managed
0505:             *
0506:             * @exception Exception if an MBean cannot be created or registered
0507:             */
0508:            public static ModelMBean createMBean(Manager manager)
0509:                    throws Exception {
0510:
0511:                String mname = createManagedName(manager);
0512:                ManagedBean managed = registry.findManagedBean(mname);
0513:                if (managed == null) {
0514:                    Exception e = new Exception(
0515:                            "ManagedBean is not found with " + mname);
0516:                    throw new MBeanException(e);
0517:                }
0518:                String domain = managed.getDomain();
0519:                if (domain == null)
0520:                    domain = mserver.getDefaultDomain();
0521:                ModelMBean mbean = managed.createMBean(manager);
0522:                ObjectName oname = createObjectName(domain, manager);
0523:                mserver.registerMBean(mbean, oname);
0524:                return (mbean);
0525:
0526:            }
0527:
0528:            /**
0529:             * Create, register, and return an MBean for this
0530:             * <code>MBeanFactory</code> object.
0531:             *
0532:             * @param factory The MBeanFactory to be managed
0533:             *
0534:             * @exception Exception if an MBean cannot be created or registered
0535:             */
0536:            public static ModelMBean createMBean(MBeanFactory factory)
0537:                    throws Exception {
0538:
0539:                String mname = createManagedName(factory);
0540:                ManagedBean managed = registry.findManagedBean(mname);
0541:                if (managed == null) {
0542:                    Exception e = new Exception(
0543:                            "ManagedBean is not found with " + mname);
0544:                    throw new MBeanException(e);
0545:                }
0546:                String domain = managed.getDomain();
0547:                if (domain == null)
0548:                    domain = mserver.getDefaultDomain();
0549:                ModelMBean mbean = managed.createMBean(factory);
0550:                ObjectName oname = createObjectName(domain, factory);
0551:                mserver.registerMBean(mbean, oname);
0552:                return (mbean);
0553:
0554:            }
0555:
0556:            /**
0557:             * Create, register, and return an MBean for this
0558:             * <code>NamingResources</code> object.
0559:             *
0560:             * @param resource The NamingResources to be managed
0561:             *
0562:             * @exception Exception if an MBean cannot be created or registered
0563:             */
0564:            public static ModelMBean createMBean(NamingResources resource)
0565:                    throws Exception {
0566:
0567:                String mname = createManagedName(resource);
0568:                ManagedBean managed = registry.findManagedBean(mname);
0569:                if (managed == null) {
0570:                    Exception e = new Exception(
0571:                            "ManagedBean is not found with " + mname);
0572:                    throw new MBeanException(e);
0573:                }
0574:                String domain = managed.getDomain();
0575:                if (domain == null)
0576:                    domain = mserver.getDefaultDomain();
0577:                ModelMBean mbean = managed.createMBean(resource);
0578:                ObjectName oname = createObjectName(domain, resource);
0579:                mserver.registerMBean(mbean, oname);
0580:                return (mbean);
0581:
0582:            }
0583:
0584:            /**
0585:             * Create, register, and return an MBean for this
0586:             * <code>Realm</code> object.
0587:             *
0588:             * @param realm The Realm to be managed
0589:             *
0590:             * @exception Exception if an MBean cannot be created or registered
0591:             */
0592:            public static ModelMBean createMBean(Realm realm) throws Exception {
0593:
0594:                String mname = createManagedName(realm);
0595:                ManagedBean managed = registry.findManagedBean(mname);
0596:                if (managed == null) {
0597:                    Exception e = new Exception(
0598:                            "ManagedBean is not found with " + mname);
0599:                    throw new MBeanException(e);
0600:                }
0601:                String domain = managed.getDomain();
0602:                if (domain == null)
0603:                    domain = mserver.getDefaultDomain();
0604:                ModelMBean mbean = managed.createMBean(realm);
0605:                ObjectName oname = createObjectName(domain, realm);
0606:                mserver.registerMBean(mbean, oname);
0607:                return (mbean);
0608:
0609:            }
0610:
0611:            /**
0612:             * Create, register, and return an MBean for this
0613:             * <code>Role</code> object.
0614:             *
0615:             * @param role The Role to be managed
0616:             *
0617:             * @exception Exception if an MBean cannot be created or registered
0618:             */
0619:            public static ModelMBean createMBean(Role role) throws Exception {
0620:
0621:                String mname = createManagedName(role);
0622:                ManagedBean managed = registry.findManagedBean(mname);
0623:                if (managed == null) {
0624:                    Exception e = new Exception(
0625:                            "ManagedBean is not found with " + mname);
0626:                    throw new MBeanException(e);
0627:                }
0628:                String domain = managed.getDomain();
0629:                if (domain == null)
0630:                    domain = mserver.getDefaultDomain();
0631:                ModelMBean mbean = managed.createMBean(role);
0632:                ObjectName oname = createObjectName(domain, role);
0633:                mserver.registerMBean(mbean, oname);
0634:                return (mbean);
0635:
0636:            }
0637:
0638:            /**
0639:             * Create, register, and return an MBean for this
0640:             * <code>Server</code> object.
0641:             *
0642:             * @param server The Server to be managed
0643:             *
0644:             * @exception Exception if an MBean cannot be created or registered
0645:             */
0646:            public static ModelMBean createMBean(Server server)
0647:                    throws Exception {
0648:
0649:                String mname = createManagedName(server);
0650:                ManagedBean managed = registry.findManagedBean(mname);
0651:                if (managed == null) {
0652:                    Exception e = new Exception(
0653:                            "ManagedBean is not found with " + mname);
0654:                    throw new MBeanException(e);
0655:                }
0656:                String domain = managed.getDomain();
0657:                if (domain == null)
0658:                    domain = mserver.getDefaultDomain();
0659:                ModelMBean mbean = managed.createMBean(server);
0660:                ObjectName oname = createObjectName(domain, server);
0661:                mserver.registerMBean(mbean, oname);
0662:                return (mbean);
0663:
0664:            }
0665:
0666:            /**
0667:             * Create, register, and return an MBean for this
0668:             * <code>Service</code> object.
0669:             *
0670:             * @param service The Service to be managed
0671:             *
0672:             * @exception Exception if an MBean cannot be created or registered
0673:             */
0674:            public static ModelMBean createMBean(Service service)
0675:                    throws Exception {
0676:
0677:                String mname = createManagedName(service);
0678:                ManagedBean managed = registry.findManagedBean(mname);
0679:                if (managed == null) {
0680:                    Exception e = new Exception(
0681:                            "ManagedBean is not found with " + mname);
0682:                    throw new MBeanException(e);
0683:                }
0684:                String domain = managed.getDomain();
0685:                if (domain == null)
0686:                    domain = mserver.getDefaultDomain();
0687:                ModelMBean mbean = managed.createMBean(service);
0688:                ObjectName oname = createObjectName(domain, service);
0689:                mserver.registerMBean(mbean, oname);
0690:                return (mbean);
0691:
0692:            }
0693:
0694:            /**
0695:             * Create, register, and return an MBean for this
0696:             * <code>User</code> object.
0697:             *
0698:             * @param user The User to be managed
0699:             *
0700:             * @exception Exception if an MBean cannot be created or registered
0701:             */
0702:            public static ModelMBean createMBean(User user) throws Exception {
0703:
0704:                String mname = createManagedName(user);
0705:                ManagedBean managed = registry.findManagedBean(mname);
0706:                if (managed == null) {
0707:                    Exception e = new Exception(
0708:                            "ManagedBean is not found with " + mname);
0709:                    throw new MBeanException(e);
0710:                }
0711:                String domain = managed.getDomain();
0712:                if (domain == null)
0713:                    domain = mserver.getDefaultDomain();
0714:                ModelMBean mbean = managed.createMBean(user);
0715:                ObjectName oname = createObjectName(domain, user);
0716:                mserver.registerMBean(mbean, oname);
0717:                return (mbean);
0718:
0719:            }
0720:
0721:            /**
0722:             * Create, register, and return an MBean for this
0723:             * <code>UserDatabase</code> object.
0724:             *
0725:             * @param userDatabase The UserDatabase to be managed
0726:             *
0727:             * @exception Exception if an MBean cannot be created or registered
0728:             */
0729:            public static ModelMBean createMBean(UserDatabase userDatabase)
0730:                    throws Exception {
0731:
0732:                String mname = createManagedName(userDatabase);
0733:                ManagedBean managed = registry.findManagedBean(mname);
0734:                if (managed == null) {
0735:                    Exception e = new Exception(
0736:                            "ManagedBean is not found with " + mname);
0737:                    throw new MBeanException(e);
0738:                }
0739:                String domain = managed.getDomain();
0740:                if (domain == null)
0741:                    domain = mserver.getDefaultDomain();
0742:                ModelMBean mbean = managed.createMBean(userDatabase);
0743:                ObjectName oname = createObjectName(domain, userDatabase);
0744:                mserver.registerMBean(mbean, oname);
0745:                return (mbean);
0746:
0747:            }
0748:
0749:            /**
0750:             * Create, register, and return an MBean for this
0751:             * <code>Valve</code> object.
0752:             *
0753:             * @param valve The Valve to be managed
0754:             *
0755:             * @exception Exception if an MBean cannot be created or registered
0756:             */
0757:            public static ModelMBean createMBean(Valve valve) throws Exception {
0758:
0759:                String mname = createManagedName(valve);
0760:                ManagedBean managed = registry.findManagedBean(mname);
0761:                if (managed == null) {
0762:                    Exception e = new Exception(
0763:                            "ManagedBean is not found with " + mname);
0764:                    throw new MBeanException(e);
0765:                }
0766:                String domain = managed.getDomain();
0767:                if (domain == null)
0768:                    domain = mserver.getDefaultDomain();
0769:                ModelMBean mbean = managed.createMBean(valve);
0770:                ObjectName oname = createObjectName(domain, valve);
0771:                mserver.registerMBean(mbean, oname);
0772:                return (mbean);
0773:
0774:            }
0775:
0776:            /**
0777:             * Create an <code>ObjectName</code> for this
0778:             * <code>Connector</code> object.
0779:             *
0780:             * @param domain Domain in which this name is to be created
0781:             * @param connector The Connector to be named
0782:             *
0783:             * @exception MalformedObjectNameException if a name cannot be created
0784:             */
0785:            public static ObjectName createObjectName(String domain,
0786:                    Connector connector) throws MalformedObjectNameException {
0787:
0788:                ObjectName name = null;
0789:                if (connector instanceof  HttpConnector) {
0790:                    HttpConnector httpConnector = (HttpConnector) connector;
0791:                    Service service = httpConnector.getService();
0792:                    String serviceName = null;
0793:                    if (service != null)
0794:                        serviceName = service.getName();
0795:                    name = new ObjectName(domain + ":type=Connector"
0796:                            + ",service=" + serviceName + ",port="
0797:                            + httpConnector.getPort() + ",address="
0798:                            + httpConnector.getAddress());
0799:                    return (name);
0800:                } else if (connector instanceof  org.apache.catalina.connector.http10.HttpConnector) {
0801:                    org.apache.catalina.connector.http10.HttpConnector httpConnector = (org.apache.catalina.connector.http10.HttpConnector) connector;
0802:                    Service service = httpConnector.getService();
0803:                    String serviceName = null;
0804:                    if (service != null)
0805:                        serviceName = service.getName();
0806:                    name = new ObjectName(domain + ":type=Connector"
0807:                            + ",service=" + serviceName + ",port="
0808:                            + httpConnector.getPort() + ",address="
0809:                            + httpConnector.getAddress());
0810:                    return (name);
0811:                } else if ("org.apache.ajp.tomcat4.Ajp13Connector"
0812:                        .equals(connector.getClass().getName())) {
0813:                    try {
0814:                        String address = (String) PropertyUtils
0815:                                .getSimpleProperty(connector, "address");
0816:                        Integer port = (Integer) PropertyUtils
0817:                                .getSimpleProperty(connector, "port");
0818:                        Service service = connector.getService();
0819:                        String serviceName = null;
0820:                        if (service != null)
0821:                            serviceName = service.getName();
0822:                        name = new ObjectName(domain + ":type=Connector"
0823:                                + ",service=" + serviceName + ",port=" + port
0824:                                + ",address=" + address);
0825:                        return (name);
0826:                    } catch (Exception e) {
0827:                        throw new MalformedObjectNameException(
0828:                                "Cannot create object name for " + connector
0829:                                        + e);
0830:                    }
0831:                } else if ("org.apache.coyote.tomcat4.CoyoteConnector"
0832:                        .equals(connector.getClass().getName())) {
0833:                    try {
0834:                        String address = (String) PropertyUtils
0835:                                .getSimpleProperty(connector, "address");
0836:                        Integer port = (Integer) PropertyUtils
0837:                                .getSimpleProperty(connector, "port");
0838:                        Service service = connector.getService();
0839:                        String serviceName = null;
0840:                        if (service != null)
0841:                            serviceName = service.getName();
0842:                        name = new ObjectName(domain + ":type=Connector"
0843:                                + ",service=" + serviceName + ",port=" + port
0844:                                + ",address=" + address);
0845:                        return (name);
0846:                    } catch (Exception e) {
0847:                        throw new MalformedObjectNameException(
0848:                                "Cannot create object name for " + connector
0849:                                        + e);
0850:                    }
0851:                } else {
0852:                    throw new MalformedObjectNameException(
0853:                            "Cannot create object name for " + connector);
0854:                }
0855:
0856:            }
0857:
0858:            /**
0859:             * Create an <code>ObjectName</code> for this
0860:             * <code>Context</code> object.
0861:             *
0862:             * @param domain Domain in which this name is to be created
0863:             * @param context The Context to be named
0864:             *
0865:             * @exception MalformedObjectNameException if a name cannot be created
0866:             */
0867:            public static ObjectName createObjectName(String domain,
0868:                    Context context) throws MalformedObjectNameException {
0869:
0870:                ObjectName name = null;
0871:                Host host = (Host) context.getParent();
0872:                Service service = ((Engine) host.getParent()).getService();
0873:                String path = context.getPath();
0874:                if (path.length() < 1)
0875:                    path = "/";
0876:                name = new ObjectName(domain + ":type=Context,path=" + path
0877:                        + ",host=" + host.getName() + ",service="
0878:                        + service.getName());
0879:                return (name);
0880:
0881:            }
0882:
0883:            /**
0884:             * Create an <code>ObjectName</code> for this
0885:             * <code>Service</code> object.
0886:             *
0887:             * @param domain Domain in which this name is to be created
0888:             * @param context The ContextEnvironment to be named
0889:             *
0890:             * @exception MalformedObjectNameException if a name cannot be created
0891:             */
0892:            public static ObjectName createObjectName(String domain,
0893:                    ContextEnvironment environment)
0894:                    throws MalformedObjectNameException {
0895:
0896:                ObjectName name = null;
0897:                Object container = environment.getNamingResources()
0898:                        .getContainer();
0899:                if (container instanceof  Server) {
0900:                    name = new ObjectName(domain + ":type=Environment"
0901:                            + ",resourcetype=Global,name="
0902:                            + environment.getName());
0903:                } else if (container instanceof  Context) {
0904:                    String path = ((Context) container).getPath();
0905:                    if (path.length() < 1)
0906:                        path = "/";
0907:                    Host host = (Host) ((Context) container).getParent();
0908:                    Engine engine = (Engine) host.getParent();
0909:                    Service service = engine.getService();
0910:                    name = new ObjectName(domain + ":type=Environment"
0911:                            + ",resourcetype=Context,path=" + path + ",host="
0912:                            + host.getName() + ",service=" + service.getName()
0913:                            + ",name=" + environment.getName());
0914:                } else if (container instanceof  DefaultContext) {
0915:                    container = ((DefaultContext) container).getParent();
0916:                    if (container instanceof  Host) {
0917:                        Host host = (Host) container;
0918:                        Service service = ((Engine) host.getParent())
0919:                                .getService();
0920:                        name = new ObjectName(domain + ":type=Environment"
0921:                                + ",resourcetype=DefaultContext,host="
0922:                                + host.getName() + ",service="
0923:                                + service.getName() + ",name="
0924:                                + environment.getName());
0925:                    } else if (container instanceof  Engine) {
0926:                        Engine engine = (Engine) container;
0927:                        Service service = engine.getService();
0928:                        name = new ObjectName(domain + ":type=Environment"
0929:                                + ",resourcetype=DefaultContext,service="
0930:                                + service.getName() + ",name="
0931:                                + environment.getName());
0932:                    }
0933:                }
0934:
0935:                return (name);
0936:
0937:            }
0938:
0939:            /**
0940:             * Create an <code>ObjectName</code> for this
0941:             * <code>ContextResource</code> object.
0942:             *
0943:             * @param domain Domain in which this name is to be created
0944:             * @param resource The ContextResource to be named
0945:             *
0946:             * @exception MalformedObjectNameException if a name cannot be created
0947:             */
0948:            public static ObjectName createObjectName(String domain,
0949:                    ContextResource resource)
0950:                    throws MalformedObjectNameException {
0951:
0952:                ObjectName name = null;
0953:                String encodedResourceName = encodeStr(resource.getName());
0954:                Object container = resource.getNamingResources().getContainer();
0955:                if (container instanceof  Server) {
0956:                    name = new ObjectName(domain + ":type=Resource"
0957:                            + ",resourcetype=Global,class="
0958:                            + resource.getType() + ",name="
0959:                            + encodedResourceName);
0960:                } else if (container instanceof  Context) {
0961:                    String path = ((Context) container).getPath();
0962:                    if (path.length() < 1)
0963:                        path = "/";
0964:                    Host host = (Host) ((Context) container).getParent();
0965:                    Engine engine = (Engine) host.getParent();
0966:                    Service service = engine.getService();
0967:                    name = new ObjectName(domain + ":type=Resource"
0968:                            + ",resourcetype=Context,path=" + path + ",host="
0969:                            + host.getName() + ",service=" + service.getName()
0970:                            + ",class=" + resource.getType() + ",name="
0971:                            + encodedResourceName);
0972:                } else if (container instanceof  DefaultContext) {
0973:                    container = ((DefaultContext) container).getParent();
0974:                    if (container instanceof  Host) {
0975:                        Host host = (Host) container;
0976:                        Service service = ((Engine) host.getParent())
0977:                                .getService();
0978:                        name = new ObjectName(domain + ":type=Resource"
0979:                                + ",resourcetype=DefaultContext,host="
0980:                                + host.getName() + ",service="
0981:                                + service.getName() + ",class="
0982:                                + resource.getType() + ",name="
0983:                                + encodedResourceName);
0984:                    } else if (container instanceof  Engine) {
0985:                        Engine engine = (Engine) container;
0986:                        Service service = engine.getService();
0987:                        name = new ObjectName(domain + ":type=Resource"
0988:                                + ",resourcetype=DefaultContext,service="
0989:                                + service.getName() + ",class="
0990:                                + resource.getType() + ",name="
0991:                                + encodedResourceName);
0992:                    }
0993:                }
0994:
0995:                return (name);
0996:
0997:            }
0998:
0999:            /**
1000:             * Create an <code>ObjectName</code> for this
1001:             * <code>ContextResourceLink</code> object.
1002:             *
1003:             * @param domain Domain in which this name is to be created
1004:             * @param resourceLink The ContextResourceLink to be named
1005:             *
1006:             * @exception MalformedObjectNameException if a name cannot be created
1007:             */
1008:            public static ObjectName createObjectName(String domain,
1009:                    ContextResourceLink resourceLink)
1010:                    throws MalformedObjectNameException {
1011:
1012:                ObjectName name = null;
1013:                String encodedResourceLinkName = encodeStr(resourceLink
1014:                        .getName());
1015:                Object container = resourceLink.getNamingResources()
1016:                        .getContainer();
1017:                if (container instanceof  Server) {
1018:                    name = new ObjectName(domain + ":type=ResourceLink"
1019:                            + ",resourcetype=Global,class="
1020:                            + resourceLink.getType() + ",name="
1021:                            + encodedResourceLinkName);
1022:                } else if (container instanceof  Context) {
1023:                    String path = ((Context) container).getPath();
1024:                    if (path.length() < 1)
1025:                        path = "/";
1026:                    Host host = (Host) ((Context) container).getParent();
1027:                    Engine engine = (Engine) host.getParent();
1028:                    Service service = engine.getService();
1029:                    name = new ObjectName(domain + ":type=ResourceLink"
1030:                            + ",resourcetype=Context,path=" + path + ",host="
1031:                            + host.getName() + ",service=" + service.getName()
1032:                            + ",class=" + resourceLink.getType() + ",name="
1033:                            + encodedResourceLinkName);
1034:                } else if (container instanceof  DefaultContext) {
1035:                    container = ((DefaultContext) container).getParent();
1036:                    if (container instanceof  Host) {
1037:                        Host host = (Host) container;
1038:                        Service service = ((Engine) host.getParent())
1039:                                .getService();
1040:                        name = new ObjectName(domain + ":type=ResourceLink"
1041:                                + ",resourcetype=DefaultContext,host="
1042:                                + host.getName() + ",service="
1043:                                + service.getName() + ",class="
1044:                                + resourceLink.getType() + ",name="
1045:                                + encodedResourceLinkName);
1046:                    } else if (container instanceof  Engine) {
1047:                        Engine engine = (Engine) container;
1048:                        Service service = engine.getService();
1049:                        name = new ObjectName(domain + ":type=ResourceLink"
1050:                                + ",resourcetype=DefaultContext,service="
1051:                                + service.getName() + ",class="
1052:                                + resourceLink.getType() + ",name="
1053:                                + encodedResourceLinkName);
1054:                    }
1055:                }
1056:
1057:                return (name);
1058:
1059:            }
1060:
1061:            /**
1062:             * Create an <code>ObjectName</code> for this
1063:             * <code>DefaultContext</code> object.
1064:             *
1065:             * @param domain Domain in which this name is to be created
1066:             * @param context The DefaultContext to be named
1067:             *
1068:             * @exception MalformedObjectNameException if a name cannot be created
1069:             */
1070:            public static ObjectName createObjectName(String domain,
1071:                    DefaultContext context) throws MalformedObjectNameException {
1072:
1073:                ObjectName name = null;
1074:                Container container = context.getParent();
1075:                if (container instanceof  Host) {
1076:                    Host host = (Host) container;
1077:                    Service service = ((Engine) host.getParent()).getService();
1078:                    name = new ObjectName(domain + ":type=DefaultContext,host="
1079:                            + host.getName() + ",service=" + service.getName());
1080:                } else if (container instanceof  Engine) {
1081:                    Engine engine = (Engine) container;
1082:                    Service service = engine.getService();
1083:                    name = new ObjectName(domain
1084:                            + ":type=DefaultContext,,service="
1085:                            + service.getName());
1086:                }
1087:
1088:                return (name);
1089:
1090:            }
1091:
1092:            /**
1093:             * Create an <code>ObjectName</code> for this
1094:             * <code>Engine</code> object.
1095:             *
1096:             * @param domain Domain in which this name is to be created
1097:             * @param engine The Engine to be named
1098:             *
1099:             * @exception MalformedObjectNameException if a name cannot be created
1100:             */
1101:            public static ObjectName createObjectName(String domain,
1102:                    Engine engine) throws MalformedObjectNameException {
1103:
1104:                ObjectName name = null;
1105:                name = new ObjectName(domain + ":type=Engine,service="
1106:                        + engine.getService().getName());
1107:                return (name);
1108:
1109:            }
1110:
1111:            /**
1112:             * Create an <code>ObjectName</code> for this
1113:             * <code>Group</code> object.
1114:             *
1115:             * @param domain Domain in which this name is to be created
1116:             * @param group The Group to be named
1117:             *
1118:             * @exception MalformedObjectNameException if a name cannot be created
1119:             */
1120:            public static ObjectName createObjectName(String domain, Group group)
1121:                    throws MalformedObjectNameException {
1122:
1123:                ObjectName name = null;
1124:                name = new ObjectName(domain + ":type=Group,groupname="
1125:                        + group.getGroupname() + ",database="
1126:                        + group.getUserDatabase().getId());
1127:                return (name);
1128:
1129:            }
1130:
1131:            /**
1132:             * Create an <code>ObjectName</code> for this
1133:             * <code>Host</code> object.
1134:             *
1135:             * @param domain Domain in which this name is to be created
1136:             * @param host The Host to be named
1137:             *
1138:             * @exception MalformedObjectNameException if a name cannot be created
1139:             */
1140:            public static ObjectName createObjectName(String domain, Host host)
1141:                    throws MalformedObjectNameException {
1142:
1143:                ObjectName name = null;
1144:                Engine engine = (Engine) host.getParent();
1145:                Service service = engine.getService();
1146:                name = new ObjectName(domain + ":type=Host,host="
1147:                        + host.getName() + ",service=" + service.getName());
1148:                return (name);
1149:
1150:            }
1151:
1152:            /**
1153:             * Create an <code>ObjectName</code> for this
1154:             * <code>Loader</code> object.
1155:             *
1156:             * @param domain Domain in which this name is to be created
1157:             * @param loader The Loader to be named
1158:             *
1159:             * @exception MalformedObjectNameException if a name cannot be created
1160:             */
1161:            public static ObjectName createObjectName(String domain,
1162:                    Loader loader) throws MalformedObjectNameException {
1163:
1164:                ObjectName name = null;
1165:                Container container = loader.getContainer();
1166:
1167:                if (container instanceof  Engine) {
1168:                    Service service = ((Engine) container).getService();
1169:                    name = new ObjectName(domain + ":type=Loader,service="
1170:                            + service.getName());
1171:                } else if (container instanceof  Host) {
1172:                    Engine engine = (Engine) container.getParent();
1173:                    Service service = engine.getService();
1174:                    name = new ObjectName(domain + ":type=Loader,host="
1175:                            + container.getName() + ",service="
1176:                            + service.getName());
1177:                } else if (container instanceof  Context) {
1178:                    String path = ((Context) container).getPath();
1179:                    if (path.length() < 1) {
1180:                        path = "/";
1181:                    }
1182:                    Host host = (Host) container.getParent();
1183:                    Engine engine = (Engine) host.getParent();
1184:                    Service service = engine.getService();
1185:                    name = new ObjectName(domain + ":type=Loader,path=" + path
1186:                            + ",host=" + host.getName() + ",service="
1187:                            + service.getName());
1188:                }
1189:
1190:                return (name);
1191:
1192:            }
1193:
1194:            /**
1195:             * Create an <code>ObjectName</code> for this
1196:             * <code>Logger</code> object.
1197:             *
1198:             * @param domain Domain in which this name is to be created
1199:             * @param logger The Logger to be named
1200:             *
1201:             * @exception MalformedObjectNameException if a name cannot be created
1202:             */
1203:            public static ObjectName createObjectName(String domain,
1204:                    Logger logger) throws MalformedObjectNameException {
1205:
1206:                ObjectName name = null;
1207:                Container container = logger.getContainer();
1208:
1209:                if (container instanceof  Engine) {
1210:                    Service service = ((Engine) container).getService();
1211:                    name = new ObjectName(domain + ":type=Logger,service="
1212:                            + service.getName());
1213:                } else if (container instanceof  Host) {
1214:                    Engine engine = (Engine) container.getParent();
1215:                    Service service = engine.getService();
1216:                    name = new ObjectName(domain + ":type=Logger,host="
1217:                            + container.getName() + ",service="
1218:                            + service.getName());
1219:                } else if (container instanceof  Context) {
1220:                    String path = ((Context) container).getPath();
1221:                    if (path.length() < 1) {
1222:                        path = "/";
1223:                    }
1224:                    Host host = (Host) container.getParent();
1225:                    Engine engine = (Engine) host.getParent();
1226:                    Service service = engine.getService();
1227:                    name = new ObjectName(domain + ":type=Logger,path=" + path
1228:                            + ",host=" + host.getName() + ",service="
1229:                            + service.getName());
1230:                }
1231:
1232:                return (name);
1233:
1234:            }
1235:
1236:            /**
1237:             * Create an <code>ObjectName</code> for this
1238:             * <code>Manager</code> object.
1239:             *
1240:             * @param domain Domain in which this name is to be created
1241:             * @param manager The Manager to be named
1242:             *
1243:             * @exception MalformedObjectNameException if a name cannot be created
1244:             */
1245:            public static ObjectName createObjectName(String domain,
1246:                    Manager manager) throws MalformedObjectNameException {
1247:
1248:                ObjectName name = null;
1249:                Container container = manager.getContainer();
1250:
1251:                if (container instanceof  Engine) {
1252:                    Service service = ((Engine) container).getService();
1253:                    name = new ObjectName(domain + ":type=Manager,service="
1254:                            + service.getName());
1255:                } else if (container instanceof  Host) {
1256:                    Engine engine = (Engine) container.getParent();
1257:                    Service service = engine.getService();
1258:                    name = new ObjectName(domain + ":type=Manager,host="
1259:                            + container.getName() + ",service="
1260:                            + service.getName());
1261:                } else if (container instanceof  Context) {
1262:                    String path = ((Context) container).getPath();
1263:                    if (path.length() < 1) {
1264:                        path = "/";
1265:                    }
1266:                    Host host = (Host) container.getParent();
1267:                    Engine engine = (Engine) host.getParent();
1268:                    Service service = engine.getService();
1269:                    name = new ObjectName(domain + ":type=Manager,path=" + path
1270:                            + ",host=" + host.getName() + ",service="
1271:                            + service.getName());
1272:                }
1273:
1274:                return (name);
1275:
1276:            }
1277:
1278:            /**
1279:             * Create an <code>ObjectName</code> for this
1280:             * <code>Server</code> object.
1281:             *
1282:             * @param domain Domain in which this name is to be created
1283:             * @param resources The NamingResources to be named
1284:             *
1285:             * @exception MalformedObjectNameException if a name cannot be created
1286:             */
1287:            public static ObjectName createObjectName(String domain,
1288:                    NamingResources resources)
1289:                    throws MalformedObjectNameException {
1290:
1291:                ObjectName name = null;
1292:                Object container = resources.getContainer();
1293:                if (container instanceof  Server) {
1294:                    name = new ObjectName(domain + ":type=NamingResources"
1295:                            + ",resourcetype=Global");
1296:                } else if (container instanceof  Context) {
1297:                    String path = ((Context) container).getPath();
1298:                    if (path.length() < 1)
1299:                        path = "/";
1300:                    Host host = (Host) ((Context) container).getParent();
1301:                    Engine engine = (Engine) host.getParent();
1302:                    Service service = engine.getService();
1303:                    name = new ObjectName(domain + ":type=NamingResources"
1304:                            + ",resourcetype=Context,path=" + path + ",host="
1305:                            + host.getName() + ",service=" + service.getName());
1306:                } else if (container instanceof  DefaultContext) {
1307:                    container = ((DefaultContext) container).getParent();
1308:                    if (container instanceof  Host) {
1309:                        Host host = (Host) container;
1310:                        Service service = ((Engine) host.getParent())
1311:                                .getService();
1312:                        name = new ObjectName(domain + ":type=NamingResources"
1313:                                + ",resourcetype=DefaultContext,host="
1314:                                + host.getName() + ",service="
1315:                                + service.getName());
1316:                    } else if (container instanceof  Engine) {
1317:                        Engine engine = (Engine) container;
1318:                        Service service = engine.getService();
1319:                        name = new ObjectName(domain + ":type=NamingResources"
1320:                                + ",resourcetype=DefaultContext" + ",service="
1321:                                + service.getName());
1322:                    }
1323:                }
1324:
1325:                return (name);
1326:
1327:            }
1328:
1329:            /**
1330:             * Create an <code>ObjectName</code> for this
1331:             * <code>MBeanFactory</code> object.
1332:             *
1333:             * @param domain Domain in which this name is to be created
1334:             * @param factory The MBeanFactory to be named
1335:             *
1336:             * @exception MalformedObjectNameException if a name cannot be created
1337:             */
1338:            public static ObjectName createObjectName(String domain,
1339:                    MBeanFactory factory) throws MalformedObjectNameException {
1340:
1341:                ObjectName name = new ObjectName(domain + ":type=MBeanFactory");
1342:
1343:                return (name);
1344:
1345:            }
1346:
1347:            /**
1348:             * Create an <code>ObjectName</code> for this
1349:             * <code>Realm</code> object.
1350:             *
1351:             * @param domain Domain in which this name is to be created
1352:             * @param realm The Realm to be named
1353:             *
1354:             * @exception MalformedObjectNameException if a name cannot be created
1355:             */
1356:            public static ObjectName createObjectName(String domain, Realm realm)
1357:                    throws MalformedObjectNameException {
1358:
1359:                ObjectName name = null;
1360:                Container container = realm.getContainer();
1361:
1362:                if (container instanceof  Engine) {
1363:                    Service service = ((Engine) container).getService();
1364:                    name = new ObjectName(domain + ":type=Realm,service="
1365:                            + service.getName());
1366:                } else if (container instanceof  Host) {
1367:                    Engine engine = (Engine) container.getParent();
1368:                    Service service = engine.getService();
1369:                    name = new ObjectName(domain + ":type=Realm,host="
1370:                            + container.getName() + ",service="
1371:                            + service.getName());
1372:                } else if (container instanceof  Context) {
1373:                    String path = ((Context) container).getPath();
1374:                    if (path.length() < 1) {
1375:                        path = "/";
1376:                    }
1377:                    Host host = (Host) container.getParent();
1378:                    Engine engine = (Engine) host.getParent();
1379:                    Service service = engine.getService();
1380:                    name = new ObjectName(domain + ":type=Realm,path=" + path
1381:                            + ",host=" + host.getName() + ",service="
1382:                            + service.getName());
1383:                }
1384:
1385:                return (name);
1386:
1387:            }
1388:
1389:            /**
1390:             * Create an <code>ObjectName</code> for this
1391:             * <code>Role</code> object.
1392:             *
1393:             * @param domain Domain in which this name is to be created
1394:             * @param role The Role to be named
1395:             *
1396:             * @exception MalformedObjectNameException if a name cannot be created
1397:             */
1398:            public static ObjectName createObjectName(String domain, Role role)
1399:                    throws MalformedObjectNameException {
1400:
1401:                ObjectName name = null;
1402:                name = new ObjectName(domain + ":type=Role,rolename="
1403:                        + role.getRolename() + ",database="
1404:                        + role.getUserDatabase().getId());
1405:                return (name);
1406:
1407:            }
1408:
1409:            /**
1410:             * Create an <code>ObjectName</code> for this
1411:             * <code>Server</code> object.
1412:             *
1413:             * @param domain Domain in which this name is to be created
1414:             * @param server The Server to be named
1415:             *
1416:             * @exception MalformedObjectNameException if a name cannot be created
1417:             */
1418:            public static ObjectName createObjectName(String domain,
1419:                    Server server) throws MalformedObjectNameException {
1420:
1421:                ObjectName name = null;
1422:                name = new ObjectName(domain + ":type=Server");
1423:                return (name);
1424:
1425:            }
1426:
1427:            /**
1428:             * Create an <code>ObjectName</code> for this
1429:             * <code>Service</code> object.
1430:             *
1431:             * @param domain Domain in which this name is to be created
1432:             * @param service The Service to be named
1433:             *
1434:             * @exception MalformedObjectNameException if a name cannot be created
1435:             */
1436:            public static ObjectName createObjectName(String domain,
1437:                    Service service) throws MalformedObjectNameException {
1438:
1439:                ObjectName name = null;
1440:                name = new ObjectName(domain + ":type=Service,name="
1441:                        + service.getName());
1442:                return (name);
1443:
1444:            }
1445:
1446:            /**
1447:             * Create an <code>ObjectName</code> for this
1448:             * <code>User</code> object.
1449:             *
1450:             * @param domain Domain in which this name is to be created
1451:             * @param user The User to be named
1452:             *
1453:             * @exception MalformedObjectNameException if a name cannot be created
1454:             */
1455:            public static ObjectName createObjectName(String domain, User user)
1456:                    throws MalformedObjectNameException {
1457:
1458:                ObjectName name = null;
1459:                name = new ObjectName(domain + ":type=User,username="
1460:                        + user.getUsername() + ",database="
1461:                        + user.getUserDatabase().getId());
1462:                return (name);
1463:
1464:            }
1465:
1466:            /**
1467:             * Create an <code>ObjectName</code> for this
1468:             * <code>UserDatabase</code> object.
1469:             *
1470:             * @param domain Domain in which this name is to be created
1471:             * @param userDatabase The UserDatabase to be named
1472:             *
1473:             * @exception MalformedObjectNameException if a name cannot be created
1474:             */
1475:            public static ObjectName createObjectName(String domain,
1476:                    UserDatabase userDatabase)
1477:                    throws MalformedObjectNameException {
1478:
1479:                ObjectName name = null;
1480:                name = new ObjectName(domain + ":type=UserDatabase,database="
1481:                        + userDatabase.getId());
1482:                return (name);
1483:
1484:            }
1485:
1486:            /**
1487:             * Create an <code>ObjectName</code> for this
1488:             * <code>Valve</code> object.
1489:             *
1490:             * @param domain Domain in which this name is to be created
1491:             * @param valve The Valve to be named
1492:             *
1493:             * @exception MalformedObjectNameException if a name cannot be created
1494:             */
1495:            public static ObjectName createObjectName(String domain, Valve valve)
1496:                    throws MalformedObjectNameException {
1497:
1498:                ObjectName name = null;
1499:                Container container = ((ValveBase) valve).getContainer();
1500:
1501:                if (container instanceof  Engine) {
1502:                    Service service = ((Engine) container).getService();
1503:                    name = new ObjectName(domain + ":type=Valve,sequence="
1504:                            + valve.hashCode() + ",service="
1505:                            + service.getName());
1506:                } else if (container instanceof  Host) {
1507:                    Service service = ((Engine) container.getParent())
1508:                            .getService();
1509:                    name = new ObjectName(domain + ":type=Valve,sequence="
1510:                            + valve.hashCode() + ",host=" + container.getName()
1511:                            + ",service=" + service.getName());
1512:                } else if (container instanceof  Context) {
1513:                    String path = ((Context) container).getPath();
1514:                    if (path.length() < 1) {
1515:                        path = "/";
1516:                    }
1517:                    Host host = (Host) container.getParent();
1518:                    Service service = ((Engine) host.getParent()).getService();
1519:                    name = new ObjectName(domain + ":type=Valve,sequence="
1520:                            + valve.hashCode() + ",path=" + path + ",host="
1521:                            + host.getName() + ",service=" + service.getName());
1522:                }
1523:
1524:                return (name);
1525:
1526:            }
1527:
1528:            /**
1529:             * Create and configure (if necessary) and return the registry of
1530:             * managed object descriptions.
1531:             */
1532:            public synchronized static Registry createRegistry() {
1533:
1534:                if (registry == null) {
1535:                    try {
1536:                        URL url = ServerLifecycleListener.class
1537:                                .getResource("/org/apache/catalina/mbeans/mbeans-descriptors.xml");
1538:                        InputStream stream = url.openStream();
1539:                        //                Registry.setDebug(1);
1540:                        Registry.loadRegistry(stream);
1541:                        stream.close();
1542:                        registry = Registry.getRegistry();
1543:                    } catch (Throwable t) {
1544:                        t.printStackTrace(System.out);
1545:                        System.exit(1);
1546:                    }
1547:                }
1548:                return (registry);
1549:
1550:            }
1551:
1552:            /**
1553:             * Load an MBean descriptor resource.
1554:             */
1555:            public synchronized static void loadMBeanDescriptors(String resource) {
1556:
1557:                try {
1558:                    URL url = ServerLifecycleListener.class
1559:                            .getResource(resource);
1560:                    if (url != null) {
1561:                        InputStream stream = url.openStream();
1562:                        Registry.loadRegistry(stream);
1563:                        stream.close();
1564:                    } else {
1565:                        // XXX: i18n
1566:                        System.out.println("MBean descriptors not found:"
1567:                                + resource);
1568:                    }
1569:                } catch (Throwable t) {
1570:                    t.printStackTrace(System.out);
1571:                }
1572:
1573:            }
1574:
1575:            /**
1576:             * Create and configure (if necessary) and return the
1577:             * <code>MBeanServer</code> with which we will be
1578:             * registering our <code>ModelMBean</code> implementations.
1579:             */
1580:            public synchronized static MBeanServer createServer() {
1581:
1582:                if (mserver == null) {
1583:                    try {
1584:                        //Trace.parseTraceProperties();
1585:                        //mserver = MBeanServerFactory.createMBeanServer();
1586:                        mserver = Registry.getServer();
1587:                    } catch (Throwable t) {
1588:                        t.printStackTrace(System.out);
1589:                        System.exit(1);
1590:                    }
1591:                }
1592:                return (mserver);
1593:
1594:            }
1595:
1596:            /**
1597:             * Deregister the MBean for this
1598:             * <code>Connector</code> object.
1599:             *
1600:             * @param connector The Connector to be managed
1601:             *
1602:             * @exception Exception if an MBean cannot be deregistered
1603:             */
1604:            public static void destroyMBean(Connector connector, Service service)
1605:                    throws Exception {
1606:
1607:                connector.setService(service);
1608:                String mname = createManagedName(connector);
1609:                ManagedBean managed = registry.findManagedBean(mname);
1610:                if (managed == null) {
1611:                    return;
1612:                }
1613:                String domain = managed.getDomain();
1614:                if (domain == null)
1615:                    domain = mserver.getDefaultDomain();
1616:                ObjectName oname = createObjectName(domain, connector);
1617:                connector.setService(null);
1618:                mserver.unregisterMBean(oname);
1619:
1620:            }
1621:
1622:            /**
1623:             * Deregister the MBean for this
1624:             * <code>Context</code> object.
1625:             *
1626:             * @param context The Context to be managed
1627:             *
1628:             * @exception Exception if an MBean cannot be deregistered
1629:             */
1630:            public static void destroyMBean(Context context) throws Exception {
1631:
1632:                String mname = createManagedName(context);
1633:                ManagedBean managed = registry.findManagedBean(mname);
1634:                if (managed == null) {
1635:                    return;
1636:                }
1637:                String domain = managed.getDomain();
1638:                if (domain == null)
1639:                    domain = mserver.getDefaultDomain();
1640:                ObjectName oname = createObjectName(domain, context);
1641:                mserver.unregisterMBean(oname);
1642:
1643:            }
1644:
1645:            /**
1646:             * Deregister the MBean for this
1647:             * <code>ContextEnvironment</code> object.
1648:             *
1649:             * @param environment The ContextEnvironment to be managed
1650:             *
1651:             * @exception Exception if an MBean cannot be deregistered
1652:             */
1653:            public static void destroyMBean(ContextEnvironment environment)
1654:                    throws Exception {
1655:
1656:                String mname = createManagedName(environment);
1657:                ManagedBean managed = registry.findManagedBean(mname);
1658:                if (managed == null) {
1659:                    return;
1660:                }
1661:                String domain = managed.getDomain();
1662:                if (domain == null)
1663:                    domain = mserver.getDefaultDomain();
1664:                ObjectName oname = createObjectName(domain, environment);
1665:                mserver.unregisterMBean(oname);
1666:
1667:            }
1668:
1669:            /**
1670:             * Deregister the MBean for this
1671:             * <code>ContextResource</code> object.
1672:             *
1673:             * @param resource The ContextResource to be managed
1674:             *
1675:             * @exception Exception if an MBean cannot be deregistered
1676:             */
1677:            public static void destroyMBean(ContextResource resource)
1678:                    throws Exception {
1679:
1680:                String mname = createManagedName(resource);
1681:                ManagedBean managed = registry.findManagedBean(mname);
1682:                if (managed == null) {
1683:                    return;
1684:                }
1685:                String domain = managed.getDomain();
1686:                if (domain == null)
1687:                    domain = mserver.getDefaultDomain();
1688:                ObjectName oname = createObjectName(domain, resource);
1689:                mserver.unregisterMBean(oname);
1690:
1691:            }
1692:
1693:            /**
1694:             * Deregister the MBean for this
1695:             * <code>ContextResourceLink</code> object.
1696:             *
1697:             * @param resourceLink The ContextResourceLink to be managed
1698:             *
1699:             * @exception Exception if an MBean cannot be deregistered
1700:             */
1701:            public static void destroyMBean(ContextResourceLink resourceLink)
1702:                    throws Exception {
1703:
1704:                String mname = createManagedName(resourceLink);
1705:                ManagedBean managed = registry.findManagedBean(mname);
1706:                if (managed == null) {
1707:                    return;
1708:                }
1709:                String domain = managed.getDomain();
1710:                if (domain == null)
1711:                    domain = mserver.getDefaultDomain();
1712:                ObjectName oname = createObjectName(domain, resourceLink);
1713:                mserver.unregisterMBean(oname);
1714:
1715:            }
1716:
1717:            /**
1718:             * Deregister the MBean for this
1719:             * <code>DefaultContext</code> object.
1720:             *
1721:             * @param context The DefaultContext to be managed
1722:             *
1723:             * @exception Exception if an MBean cannot be deregistered
1724:             */
1725:            public static void destroyMBean(DefaultContext context)
1726:                    throws Exception {
1727:
1728:                String mname = createManagedName(context);
1729:                ManagedBean managed = registry.findManagedBean(mname);
1730:                if (managed == null) {
1731:                    return;
1732:                }
1733:                String domain = managed.getDomain();
1734:                if (domain == null)
1735:                    domain = mserver.getDefaultDomain();
1736:                ObjectName oname = createObjectName(domain, context);
1737:                mserver.unregisterMBean(oname);
1738:
1739:            }
1740:
1741:            /**
1742:             * Deregister the MBean for this
1743:             * <code>Engine</code> object.
1744:             *
1745:             * @param engine The Engine to be managed
1746:             *
1747:             * @exception Exception if an MBean cannot be deregistered
1748:             */
1749:            public static void destroyMBean(Engine engine) throws Exception {
1750:
1751:                String mname = createManagedName(engine);
1752:                ManagedBean managed = registry.findManagedBean(mname);
1753:                if (managed == null) {
1754:                    return;
1755:                }
1756:                String domain = managed.getDomain();
1757:                if (domain == null)
1758:                    domain = mserver.getDefaultDomain();
1759:                ObjectName oname = createObjectName(domain, engine);
1760:                mserver.unregisterMBean(oname);
1761:
1762:            }
1763:
1764:            /**
1765:             * Deregister the MBean for this
1766:             * <code>Group</code> object.
1767:             *
1768:             * @param group The Group to be managed
1769:             *
1770:             * @exception Exception if an MBean cannot be deregistered
1771:             */
1772:            public static void destroyMBean(Group group) throws Exception {
1773:
1774:                String mname = createManagedName(group);
1775:                ManagedBean managed = registry.findManagedBean(mname);
1776:                if (managed == null) {
1777:                    return;
1778:                }
1779:                String domain = managed.getDomain();
1780:                if (domain == null)
1781:                    domain = mserver.getDefaultDomain();
1782:                ObjectName oname = createObjectName(domain, group);
1783:                mserver.unregisterMBean(oname);
1784:
1785:            }
1786:
1787:            /**
1788:             * Deregister the MBean for this
1789:             * <code>Host</code> object.
1790:             *
1791:             * @param host The Host to be managed
1792:             *
1793:             * @exception Exception if an MBean cannot be deregistered
1794:             */
1795:            public static void destroyMBean(Host host) throws Exception {
1796:
1797:                String mname = createManagedName(host);
1798:                ManagedBean managed = registry.findManagedBean(mname);
1799:                if (managed == null) {
1800:                    return;
1801:                }
1802:                String domain = managed.getDomain();
1803:                if (domain == null)
1804:                    domain = mserver.getDefaultDomain();
1805:                ObjectName oname = createObjectName(domain, host);
1806:                mserver.unregisterMBean(oname);
1807:
1808:            }
1809:
1810:            /**
1811:             * Deregister the MBean for this
1812:             * <code>Loader</code> object.
1813:             *
1814:             * @param loader The Loader to be managed
1815:             *
1816:             * @exception Exception if an MBean cannot be deregistered
1817:             */
1818:            public static void destroyMBean(Loader loader) throws Exception {
1819:
1820:                String mname = createManagedName(loader);
1821:                ManagedBean managed = registry.findManagedBean(mname);
1822:                if (managed == null) {
1823:                    return;
1824:                }
1825:                String domain = managed.getDomain();
1826:                if (domain == null)
1827:                    domain = mserver.getDefaultDomain();
1828:                ObjectName oname = createObjectName(domain, loader);
1829:                mserver.unregisterMBean(oname);
1830:
1831:            }
1832:
1833:            /**
1834:             * Deregister the MBean for this
1835:             * <code>Logger</code> object.
1836:             *
1837:             * @param logger The Logger to be managed
1838:             *
1839:             * @exception Exception if an MBean cannot be deregistered
1840:             */
1841:            public static void destroyMBean(Logger logger) throws Exception {
1842:
1843:                String mname = createManagedName(logger);
1844:                ManagedBean managed = registry.findManagedBean(mname);
1845:                if (managed == null) {
1846:                    return;
1847:                }
1848:                String domain = managed.getDomain();
1849:                if (domain == null)
1850:                    domain = mserver.getDefaultDomain();
1851:                ObjectName oname = createObjectName(domain, logger);
1852:                mserver.unregisterMBean(oname);
1853:
1854:            }
1855:
1856:            /**
1857:             * Deregister the MBean for this
1858:             * <code>Manager</code> object.
1859:             *
1860:             * @param manager The Manager to be managed
1861:             *
1862:             * @exception Exception if an MBean cannot be deregistered
1863:             */
1864:            public static void destroyMBean(Manager manager) throws Exception {
1865:
1866:                String mname = createManagedName(manager);
1867:                ManagedBean managed = registry.findManagedBean(mname);
1868:                if (managed == null) {
1869:                    return;
1870:                }
1871:                String domain = managed.getDomain();
1872:                if (domain == null)
1873:                    domain = mserver.getDefaultDomain();
1874:                ObjectName oname = createObjectName(domain, manager);
1875:                mserver.unregisterMBean(oname);
1876:
1877:            }
1878:
1879:            /**
1880:             * Deregister the MBean for this
1881:             * <code>NamingResources</code> object.
1882:             *
1883:             * @param resources The NamingResources to be managed
1884:             *
1885:             * @exception Exception if an MBean cannot be deregistered
1886:             */
1887:            public static void destroyMBean(NamingResources resources)
1888:                    throws Exception {
1889:
1890:                String mname = createManagedName(resources);
1891:                ManagedBean managed = registry.findManagedBean(mname);
1892:                if (managed == null) {
1893:                    return;
1894:                }
1895:                String domain = managed.getDomain();
1896:                if (domain == null)
1897:                    domain = mserver.getDefaultDomain();
1898:                ObjectName oname = createObjectName(domain, resources);
1899:                mserver.unregisterMBean(oname);
1900:
1901:            }
1902:
1903:            /**
1904:             * Deregister the MBean for this
1905:             * <code>Realm</code> object.
1906:             *
1907:             * @param realm The Realm to be managed
1908:             *
1909:             * @exception Exception if an MBean cannot be deregistered
1910:             */
1911:            public static void destroyMBean(Realm realm) throws Exception {
1912:
1913:                String mname = createManagedName(realm);
1914:                ManagedBean managed = registry.findManagedBean(mname);
1915:                if (managed == null) {
1916:                    return;
1917:                }
1918:                String domain = managed.getDomain();
1919:                if (domain == null)
1920:                    domain = mserver.getDefaultDomain();
1921:                ObjectName oname = createObjectName(domain, realm);
1922:                mserver.unregisterMBean(oname);
1923:
1924:            }
1925:
1926:            /**
1927:             * Deregister the MBean for this
1928:             * <code>Role</code> object.
1929:             *
1930:             * @param role The Role to be managed
1931:             *
1932:             * @exception Exception if an MBean cannot be deregistered
1933:             */
1934:            public static void destroyMBean(Role role) throws Exception {
1935:
1936:                String mname = createManagedName(role);
1937:                ManagedBean managed = registry.findManagedBean(mname);
1938:                if (managed == null) {
1939:                    return;
1940:                }
1941:                String domain = managed.getDomain();
1942:                if (domain == null)
1943:                    domain = mserver.getDefaultDomain();
1944:                ObjectName oname = createObjectName(domain, role);
1945:                mserver.unregisterMBean(oname);
1946:
1947:            }
1948:
1949:            /**
1950:             * Deregister the MBean for this
1951:             * <code>Server</code> object.
1952:             *
1953:             * @param server The Server to be managed
1954:             *
1955:             * @exception Exception if an MBean cannot be deregistered
1956:             */
1957:            public static void destroyMBean(Server server) throws Exception {
1958:
1959:                String mname = createManagedName(server);
1960:                ManagedBean managed = registry.findManagedBean(mname);
1961:                if (managed == null) {
1962:                    return;
1963:                }
1964:                String domain = managed.getDomain();
1965:                if (domain == null)
1966:                    domain = mserver.getDefaultDomain();
1967:                ObjectName oname = createObjectName(domain, server);
1968:                mserver.unregisterMBean(oname);
1969:
1970:            }
1971:
1972:            /**
1973:             * Deregister the MBean for this
1974:             * <code>Service</code> object.
1975:             *
1976:             * @param service The Service to be managed
1977:             *
1978:             * @exception Exception if an MBean cannot be deregistered
1979:             */
1980:            public static void destroyMBean(Service service) throws Exception {
1981:
1982:                String mname = createManagedName(service);
1983:                ManagedBean managed = registry.findManagedBean(mname);
1984:                if (managed == null) {
1985:                    return;
1986:                }
1987:                String domain = managed.getDomain();
1988:                if (domain == null)
1989:                    domain = mserver.getDefaultDomain();
1990:                ObjectName oname = createObjectName(domain, service);
1991:                mserver.unregisterMBean(oname);
1992:
1993:            }
1994:
1995:            /**
1996:             * Deregister the MBean for this
1997:             * <code>User</code> object.
1998:             *
1999:             * @param user The User to be managed
2000:             *
2001:             * @exception Exception if an MBean cannot be deregistered
2002:             */
2003:            public static void destroyMBean(User user) throws Exception {
2004:
2005:                String mname = createManagedName(user);
2006:                ManagedBean managed = registry.findManagedBean(mname);
2007:                if (managed == null) {
2008:                    return;
2009:                }
2010:                String domain = managed.getDomain();
2011:                if (domain == null)
2012:                    domain = mserver.getDefaultDomain();
2013:                ObjectName oname = createObjectName(domain, user);
2014:                mserver.unregisterMBean(oname);
2015:
2016:            }
2017:
2018:            /**
2019:             * Deregister the MBean for this
2020:             * <code>UserDatabase</code> object.
2021:             *
2022:             * @param userDatabase The UserDatabase to be managed
2023:             *
2024:             * @exception Exception if an MBean cannot be deregistered
2025:             */
2026:            public static void destroyMBean(UserDatabase userDatabase)
2027:                    throws Exception {
2028:
2029:                String mname = createManagedName(userDatabase);
2030:                ManagedBean managed = registry.findManagedBean(mname);
2031:                if (managed == null) {
2032:                    return;
2033:                }
2034:                String domain = managed.getDomain();
2035:                if (domain == null)
2036:                    domain = mserver.getDefaultDomain();
2037:                ObjectName oname = createObjectName(domain, userDatabase);
2038:                mserver.unregisterMBean(oname);
2039:
2040:            }
2041:
2042:            /**
2043:             * Deregister the MBean for this
2044:             * <code>Valve</code> object.
2045:             *
2046:             * @param valve The Valve to be managed
2047:             *
2048:             * @exception Exception if an MBean cannot be deregistered
2049:             */
2050:            public static void destroyMBean(Valve valve, Container container)
2051:                    throws Exception {
2052:
2053:                ((Contained) valve).setContainer(container);
2054:                String mname = createManagedName(valve);
2055:                ManagedBean managed = registry.findManagedBean(mname);
2056:                if (managed == null) {
2057:                    return;
2058:                }
2059:                String domain = managed.getDomain();
2060:                if (domain == null)
2061:                    domain = mserver.getDefaultDomain();
2062:                ObjectName oname = createObjectName(domain, valve);
2063:                try {
2064:                    ((Contained) valve).setContainer(null);
2065:                } catch (Throwable t) {
2066:                    ;
2067:                }
2068:                mserver.unregisterMBean(oname);
2069:
2070:            }
2071:
2072:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.