Source Code Cross Referenced for MBeanUtils.java in  » Sevlet-Container » tomcat-catalina » 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 » Sevlet Container » tomcat catalina » org.apache.catalina.mbeans 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


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