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

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


0001:        /*
0002:         * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/mbeans/MBeanFactory.java,v 1.34 2002/05/21 20:10:53 amyroh Exp $
0003:         * $Revision: 1.34 $
0004:         * $Date: 2002/05/21 20:10:53 $
0005:         *
0006:         * ====================================================================
0007:         *
0008:         * The Apache Software License, Version 1.1
0009:         *
0010:         * Copyright (c) 1999-2002 The Apache Software Foundation.  All rights
0011:         * reserved.
0012:         *
0013:         * Redistribution and use in source and binary forms, with or without
0014:         * modification, are permitted provided that the following conditions
0015:         * are met:
0016:         *
0017:         * 1. Redistributions of source code must retain the above copyright
0018:         *    notice, this list of conditions and the following disclaimer.
0019:         *
0020:         * 2. Redistributions in binary form must reproduce the above copyright
0021:         *    notice, this list of conditions and the following disclaimer in
0022:         *    the documentation and/or other materials provided with the
0023:         *    distribution.
0024:         *
0025:         * 3. The end-user documentation included with the redistribution, if
0026:         *    any, must include the following acknowlegement:
0027:         *       "This product includes software developed by the
0028:         *        Apache Software Foundation (http://www.apache.org/)."
0029:         *    Alternately, this acknowlegement may appear in the software itself,
0030:         *    if and wherever such third-party acknowlegements normally appear.
0031:         *
0032:         * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
0033:         *    Foundation" must not be used to endorse or promote products derived
0034:         *    from this software without prior written permission. For written
0035:         *    permission, please contact apache@apache.org.
0036:         *
0037:         * 5. Products derived from this software may not be called "Apache"
0038:         *    nor may "Apache" appear in their names without prior written
0039:         *    permission of the Apache Group.
0040:         *
0041:         * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
0042:         * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
0043:         * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
0044:         * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
0045:         * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
0046:         * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
0047:         * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
0048:         * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
0049:         * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
0050:         * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
0051:         * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
0052:         * SUCH DAMAGE.
0053:         * ====================================================================
0054:         *
0055:         * This software consists of voluntary contributions made by many
0056:         * individuals on behalf of the Apache Software Foundation.  For more
0057:         * information on the Apache Software Foundation, please see
0058:         * <http://www.apache.org/>.
0059:         *
0060:         * [Additional notices, if required by prior licensing conditions]
0061:         *
0062:         */
0063:
0064:        package org.apache.catalina.mbeans;
0065:
0066:        import java.lang.reflect.Constructor;
0067:        import java.lang.reflect.Method;
0068:        import javax.management.MBeanException;
0069:        import javax.management.MBeanServer;
0070:        import javax.management.ObjectName;
0071:        import javax.management.ObjectInstance;
0072:        import javax.management.RuntimeOperationsException;
0073:        import org.apache.catalina.Connector;
0074:        import org.apache.catalina.Container;
0075:        import org.apache.catalina.Context;
0076:        import org.apache.catalina.DefaultContext;
0077:        import org.apache.catalina.Engine;
0078:        import org.apache.catalina.Host;
0079:        import org.apache.catalina.Loader;
0080:        import org.apache.catalina.Logger;
0081:        import org.apache.catalina.Manager;
0082:        import org.apache.catalina.Realm;
0083:        import org.apache.catalina.Server;
0084:        import org.apache.catalina.ServerFactory;
0085:        import org.apache.catalina.Service;
0086:        import org.apache.catalina.Valve;
0087:        import org.apache.catalina.authenticator.SingleSignOn;
0088:        import org.apache.catalina.core.StandardContext;
0089:        import org.apache.catalina.core.StandardServer;
0090:        import org.apache.catalina.core.StandardService;
0091:        import org.apache.catalina.core.StandardDefaultContext;
0092:        import org.apache.catalina.core.StandardEngine;
0093:        import org.apache.catalina.core.StandardHost;
0094:        import org.apache.catalina.core.StandardServer;
0095:        import org.apache.catalina.core.StandardService;
0096:        import org.apache.catalina.loader.WebappLoader;
0097:        import org.apache.catalina.logger.FileLogger;
0098:        import org.apache.catalina.logger.SystemErrLogger;
0099:        import org.apache.catalina.logger.SystemOutLogger;
0100:        import org.apache.catalina.realm.JDBCRealm;
0101:        import org.apache.catalina.realm.JNDIRealm;
0102:        import org.apache.catalina.realm.MemoryRealm;
0103:        import org.apache.catalina.realm.UserDatabaseRealm;
0104:        import org.apache.catalina.session.StandardManager;
0105:        import org.apache.catalina.valves.AccessLogValve;
0106:        import org.apache.catalina.valves.RemoteAddrValve;
0107:        import org.apache.catalina.valves.RemoteHostValve;
0108:        import org.apache.catalina.valves.RequestDumperValve;
0109:        import org.apache.catalina.valves.ValveBase;
0110:        import org.apache.commons.modeler.BaseModelMBean;
0111:        import org.apache.commons.modeler.ManagedBean;
0112:        import org.apache.commons.modeler.Registry;
0113:
0114:        /**
0115:         * <p>A <strong>ModelMBean</strong> implementation for the
0116:         * <code>org.apache.catalina.core.StandardServer</code> component.</p>
0117:         *
0118:         * @author Amy Roh
0119:         * @version $Revision: 1.34 $ $Date: 2002/05/21 20:10:53 $
0120:         */
0121:
0122:        public class MBeanFactory extends BaseModelMBean {
0123:
0124:            /**
0125:             * The <code>MBeanServer</code> for this application.
0126:             */
0127:            private static MBeanServer mserver = MBeanUtils.createServer();
0128:
0129:            /**
0130:             * The configuration information registry for our managed beans.
0131:             */
0132:            private static Registry registry = MBeanUtils.createRegistry();
0133:
0134:            // ----------------------------------------------------------- Constructors
0135:
0136:            /**
0137:             * Construct a <code>ModelMBean</code> with default
0138:             * <code>ModelMBeanInfo</code> information.
0139:             *
0140:             * @exception MBeanException if the initializer of an object
0141:             *  throws an exception
0142:             * @exception RuntimeOperationsException if an IllegalArgumentException
0143:             *  occurs
0144:             */
0145:            public MBeanFactory() throws MBeanException,
0146:                    RuntimeOperationsException {
0147:
0148:                super ();
0149:
0150:            }
0151:
0152:            // ------------------------------------------------------------- Attributes
0153:
0154:            // ------------------------------------------------------------- Operations
0155:
0156:            /**
0157:             * Return the managed bean definition for the specified bean type
0158:             *
0159:             * @param type MBean type
0160:             */
0161:            public String findObjectName(String type) {
0162:
0163:                if (type.equals("org.apache.catalina.core.StandardContext")) {
0164:                    return "StandardContext";
0165:                } else if (type
0166:                        .equals("org.apache.catalina.core.StandardDefaultContext")) {
0167:                    return "DefaultContext";
0168:                } else if (type
0169:                        .equals("org.apache.catalina.core.StandardEngine")) {
0170:                    return "Engine";
0171:                } else if (type.equals("org.apache.catalina.core.StandardHost")) {
0172:                    return "Host";
0173:                } else {
0174:                    return null;
0175:                }
0176:
0177:            }
0178:
0179:            /**
0180:             * Little convenience method to remove redundant code
0181:             * when retrieving the path string
0182:             *
0183:             * @param t path string
0184:             * @return empty string if t==null || t.equals("/")
0185:             */
0186:            private final String getPathStr(String t) {
0187:                if (t == null || t.equals("/")) {
0188:                    return "";
0189:                }
0190:                return t;
0191:            }
0192:
0193:            /**
0194:             * Create a new AccessLoggerValve.
0195:             *
0196:             * @param parent MBean Name of the associated parent component
0197:             *
0198:             * @exception Exception if an MBean cannot be created or registered
0199:             */
0200:            public String createAccessLoggerValve(String parent)
0201:                    throws Exception {
0202:
0203:                // Create a new AccessLogValve instance
0204:                AccessLogValve accessLogger = new AccessLogValve();
0205:
0206:                // Add the new instance to its parent component
0207:                ObjectName pname = new ObjectName(parent);
0208:                String type = pname.getKeyProperty("type");
0209:                Server server = ServerFactory.getServer();
0210:                Service service = server.findService(pname
0211:                        .getKeyProperty("service"));
0212:                Engine engine = (Engine) service.getContainer();
0213:                if (type.equals("Context")) {
0214:                    Host host = (Host) engine.findChild(pname
0215:                            .getKeyProperty("host"));
0216:                    String pathStr = getPathStr(pname.getKeyProperty("path"));
0217:                    Context context = (Context) host.findChild(pathStr);
0218:                    ((StandardContext) context).addValve(accessLogger);
0219:                } else if (type.equals("Engine")) {
0220:                    ((StandardEngine) engine).addValve(accessLogger);
0221:                } else if (type.equals("Host")) {
0222:                    Host host = (Host) engine.findChild(pname
0223:                            .getKeyProperty("host"));
0224:                    ((StandardHost) host).addValve(accessLogger);
0225:                }
0226:
0227:                // Return the corresponding MBean name
0228:                ManagedBean managed = registry
0229:                        .findManagedBean("AccessLogValve");
0230:                ObjectName oname = MBeanUtils.createObjectName(managed
0231:                        .getDomain(), accessLogger);
0232:                return (oname.toString());
0233:
0234:            }
0235:
0236:            /**
0237:             * Create a new AjpConnector
0238:             *
0239:             * @param parent MBean Name of the associated parent component
0240:             * @param address The IP address on which to bind
0241:             * @param port TCP port number to listen on
0242:             *
0243:             * @exception Exception if an MBean cannot be created or registered
0244:             */
0245:            public String createAjpConnector(String parent, String address,
0246:                    int port) throws Exception {
0247:
0248:                Object retobj = null;
0249:
0250:                try {
0251:
0252:                    // Create a new CoyoteConnector instance for AJP
0253:                    // use reflection to avoid j-t-c compile-time circular dependencies
0254:                    Class cls = Class
0255:                            .forName("org.apache.coyote.tomcat4.CoyoteConnector");
0256:                    Constructor ct = cls.getConstructor(null);
0257:                    retobj = ct.newInstance(null);
0258:                    Class partypes1[] = new Class[1];
0259:                    // Set address
0260:                    String str = new String();
0261:                    partypes1[0] = str.getClass();
0262:                    Method meth1 = cls.getMethod("setAddress", partypes1);
0263:                    Object arglist1[] = new Object[1];
0264:                    arglist1[0] = address;
0265:                    meth1.invoke(retobj, arglist1);
0266:                    // Set port number
0267:                    Class partypes2[] = new Class[1];
0268:                    partypes2[0] = Integer.TYPE;
0269:                    Method meth2 = cls.getMethod("setPort", partypes2);
0270:                    Object arglist2[] = new Object[1];
0271:                    arglist2[0] = new Integer(port);
0272:                    meth2.invoke(retobj, arglist2);
0273:                    // set protocolHandlerClassName for AJP
0274:                    Class partypes3[] = new Class[1];
0275:                    partypes3[0] = str.getClass();
0276:                    Method meth3 = cls.getMethod("setProtocolHandlerClassName",
0277:                            partypes3);
0278:                    Object arglist3[] = new Object[1];
0279:                    arglist3[0] = new String(
0280:                            "org.apache.jk.server.JkCoyoteHandler");
0281:                    meth3.invoke(retobj, arglist3);
0282:
0283:                } catch (Exception e) {
0284:                    throw new MBeanException(e);
0285:                }
0286:
0287:                // Add the new instance to its parent component
0288:                ObjectName pname = new ObjectName(parent);
0289:                Server server = ServerFactory.getServer();
0290:                Service service = server.findService(pname
0291:                        .getKeyProperty("name"));
0292:                service.addConnector((Connector) retobj);
0293:
0294:                // Return the corresponding MBean name
0295:                ManagedBean managed = registry
0296:                        .findManagedBean("CoyoteConnector");
0297:                ObjectName oname = MBeanUtils.createObjectName(managed
0298:                        .getDomain(), (Connector) retobj);
0299:                return (oname.toString());
0300:
0301:            }
0302:
0303:            /**
0304:             * Create a new DefaultContext.
0305:             *
0306:             * @param parent MBean Name of the associated parent component
0307:             *
0308:             * @exception Exception if an MBean cannot be created or registered
0309:             */
0310:            public String createDefaultContext(String parent) throws Exception {
0311:
0312:                // Create a new StandardDefaultContext instance
0313:                StandardDefaultContext context = new StandardDefaultContext();
0314:
0315:                // Add the new instance to its parent component
0316:                ObjectName pname = new ObjectName(parent);
0317:                String type = pname.getKeyProperty("type");
0318:                Server server = ServerFactory.getServer();
0319:                Service service = server.findService(pname
0320:                        .getKeyProperty("service"));
0321:                Engine engine = (Engine) service.getContainer();
0322:                String hostName = pname.getKeyProperty("host");
0323:                if (hostName == null) { //if DefaultContext is nested in Engine
0324:                    engine.addDefaultContext(context);
0325:                } else { // if DefaultContext is nested in Host
0326:                    Host host = (Host) engine.findChild(hostName);
0327:                    host.addDefaultContext(context);
0328:                }
0329:
0330:                // Return the corresponding MBean name
0331:                ManagedBean managed = registry
0332:                        .findManagedBean("DefaultContext");
0333:                ObjectName oname = MBeanUtils.createObjectName(managed
0334:                        .getDomain(), context);
0335:                return (oname.toString());
0336:
0337:            }
0338:
0339:            /**
0340:             * Create a new FileLogger.
0341:             *
0342:             * @param parent MBean Name of the associated parent component
0343:             *
0344:             * @exception Exception if an MBean cannot be created or registered
0345:             */
0346:            public String createFileLogger(String parent) throws Exception {
0347:
0348:                // Create a new FileLogger instance
0349:                FileLogger fileLogger = new FileLogger();
0350:
0351:                // Add the new instance to its parent component
0352:                ObjectName pname = new ObjectName(parent);
0353:                String type = pname.getKeyProperty("type");
0354:                Server server = ServerFactory.getServer();
0355:                Service service = server.findService(pname
0356:                        .getKeyProperty("service"));
0357:                Engine engine = (Engine) service.getContainer();
0358:                if (type.equals("Context")) {
0359:                    Host host = (Host) engine.findChild(pname
0360:                            .getKeyProperty("host"));
0361:                    String pathStr = getPathStr(pname.getKeyProperty("path"));
0362:                    Context context = (Context) host.findChild(pathStr);
0363:                    context.setLogger(fileLogger);
0364:                } else if (type.equals("Engine")) {
0365:                    engine.setLogger(fileLogger);
0366:                } else if (type.equals("Host")) {
0367:                    Host host = (Host) engine.findChild(pname
0368:                            .getKeyProperty("host"));
0369:                    host.setLogger(fileLogger);
0370:                }
0371:
0372:                // Return the corresponding MBean name
0373:                ManagedBean managed = registry.findManagedBean("FileLogger");
0374:                ObjectName oname = MBeanUtils.createObjectName(managed
0375:                        .getDomain(), fileLogger);
0376:                return (oname.toString());
0377:
0378:            }
0379:
0380:            /**
0381:             * Create a new HttpConnector
0382:             *
0383:             * @param parent MBean Name of the associated parent component
0384:             * @param address The IP address on which to bind
0385:             * @param port TCP port number to listen on
0386:             *
0387:             * @exception Exception if an MBean cannot be created or registered
0388:             */
0389:            public String createHttpConnector(String parent, String address,
0390:                    int port) throws Exception {
0391:
0392:                Object retobj = null;
0393:
0394:                try {
0395:
0396:                    // Create a new CoyoteConnector instance
0397:                    // use reflection to avoid j-t-c compile-time circular dependencies
0398:                    Class cls = Class
0399:                            .forName("org.apache.coyote.tomcat4.CoyoteConnector");
0400:                    Constructor ct = cls.getConstructor(null);
0401:                    retobj = ct.newInstance(null);
0402:                    Class partypes1[] = new Class[1];
0403:                    // Set address
0404:                    String str = new String();
0405:                    partypes1[0] = str.getClass();
0406:                    Method meth1 = cls.getMethod("setAddress", partypes1);
0407:                    Object arglist1[] = new Object[1];
0408:                    arglist1[0] = address;
0409:                    meth1.invoke(retobj, arglist1);
0410:                    // Set port number
0411:                    Class partypes2[] = new Class[1];
0412:                    partypes2[0] = Integer.TYPE;
0413:                    Method meth2 = cls.getMethod("setPort", partypes2);
0414:                    Object arglist2[] = new Object[1];
0415:                    arglist2[0] = new Integer(port);
0416:                    meth2.invoke(retobj, arglist2);
0417:                } catch (Exception e) {
0418:                    throw new MBeanException(e);
0419:                }
0420:
0421:                // Add the new instance to its parent component
0422:                ObjectName pname = new ObjectName(parent);
0423:                Server server = ServerFactory.getServer();
0424:                Service service = server.findService(pname
0425:                        .getKeyProperty("name"));
0426:                service.addConnector((Connector) retobj);
0427:
0428:                // Return the corresponding MBean name
0429:                ManagedBean managed = registry
0430:                        .findManagedBean("CoyoteConnector");
0431:                ObjectName oname = MBeanUtils.createObjectName(managed
0432:                        .getDomain(), (Connector) retobj);
0433:                return (oname.toString());
0434:
0435:            }
0436:
0437:            /**
0438:             * Create a new HttpsConnector
0439:             *
0440:             * @param parent MBean Name of the associated parent component
0441:             * @param address The IP address on which to bind
0442:             * @param port TCP port number to listen on
0443:             *
0444:             * @exception Exception if an MBean cannot be created or registered
0445:             */
0446:            public String createHttpsConnector(String parent, String address,
0447:                    int port) throws Exception {
0448:
0449:                Object retobj = null;
0450:
0451:                try {
0452:
0453:                    // Create a new CoyoteConnector instance
0454:                    // use reflection to avoid j-t-c compile-time circular dependencies
0455:                    Class cls = Class
0456:                            .forName("org.apache.coyote.tomcat4.CoyoteConnector");
0457:                    Constructor ct = cls.getConstructor(null);
0458:                    retobj = ct.newInstance(null);
0459:                    Class partypes1[] = new Class[1];
0460:                    // Set address
0461:                    String str = new String();
0462:                    partypes1[0] = str.getClass();
0463:                    Method meth1 = cls.getMethod("setAddress", partypes1);
0464:                    Object arglist1[] = new Object[1];
0465:                    arglist1[0] = address;
0466:                    meth1.invoke(retobj, arglist1);
0467:                    // Set port number
0468:                    Class partypes2[] = new Class[1];
0469:                    partypes2[0] = Integer.TYPE;
0470:                    Method meth2 = cls.getMethod("setPort", partypes2);
0471:                    Object arglist2[] = new Object[1];
0472:                    arglist2[0] = new Integer(port);
0473:                    meth2.invoke(retobj, arglist2);
0474:                    // Set scheme
0475:                    Class partypes3[] = new Class[1];
0476:                    partypes3[0] = str.getClass();
0477:                    Method meth3 = cls.getMethod("setScheme", partypes3);
0478:                    Object arglist3[] = new Object[1];
0479:                    arglist3[0] = new String("https");
0480:                    meth3.invoke(retobj, arglist3);
0481:                    // Set secure
0482:                    Class partypes4[] = new Class[1];
0483:                    partypes4[0] = Boolean.TYPE;
0484:                    Method meth4 = cls.getMethod("setSecure", partypes4);
0485:                    Object arglist4[] = new Object[1];
0486:                    arglist4[0] = new Boolean(true);
0487:                    meth4.invoke(retobj, arglist4);
0488:                    // Set factory 
0489:                    Class serverSocketFactoryCls = Class
0490:                            .forName("org.apache.catalina.net.ServerSocketFactory");
0491:                    Class coyoteServerSocketFactoryCls = Class
0492:                            .forName("org.apache.coyote.tomcat4.CoyoteServerSocketFactory");
0493:                    Constructor factoryConst = coyoteServerSocketFactoryCls
0494:                            .getConstructor(null);
0495:                    Object factoryObj = factoryConst.newInstance(null);
0496:                    Class partypes5[] = new Class[1];
0497:                    partypes5[0] = serverSocketFactoryCls;
0498:                    Method meth5 = cls.getMethod("setFactory", partypes5);
0499:                    Object arglist5[] = new Object[1];
0500:                    arglist5[0] = factoryObj;
0501:                    meth5.invoke(retobj, arglist5);
0502:                } catch (Exception e) {
0503:                    throw new MBeanException(e);
0504:                }
0505:
0506:                try {
0507:                    // Add the new instance to its parent component
0508:                    ObjectName pname = new ObjectName(parent);
0509:                    Server server = ServerFactory.getServer();
0510:                    Service service = server.findService(pname
0511:                            .getKeyProperty("name"));
0512:                    service.addConnector((Connector) retobj);
0513:                } catch (Exception e) {
0514:                    // FIXME
0515:                    // disply error message 
0516:                    // the user needs to use keytool to configure SSL first
0517:                    // addConnector will fail otherwise
0518:                    return null;
0519:                }
0520:
0521:                // Return the corresponding MBean name
0522:                ManagedBean managed = registry
0523:                        .findManagedBean("CoyoteConnector");
0524:                ObjectName oname = MBeanUtils.createObjectName(managed
0525:                        .getDomain(), (Connector) retobj);
0526:                return (oname.toString());
0527:
0528:            }
0529:
0530:            /**
0531:             * Create a new JDBC Realm.
0532:             *
0533:             * @param parent MBean Name of the associated parent component
0534:             *
0535:             * @exception Exception if an MBean cannot be created or registered
0536:             */
0537:            public String createJDBCRealm(String parent) throws Exception {
0538:
0539:                // Create a new JDBCRealm instance
0540:                JDBCRealm realm = new JDBCRealm();
0541:
0542:                // Add the new instance to its parent component
0543:                ObjectName pname = new ObjectName(parent);
0544:                String type = pname.getKeyProperty("type");
0545:                Server server = ServerFactory.getServer();
0546:                Service service = server.findService(pname
0547:                        .getKeyProperty("service"));
0548:                Engine engine = (Engine) service.getContainer();
0549:                if (type.equals("Context")) {
0550:                    Host host = (Host) engine.findChild(pname
0551:                            .getKeyProperty("host"));
0552:                    String pathStr = getPathStr(pname.getKeyProperty("path"));
0553:                    Context context = (Context) host.findChild(pathStr);
0554:                    context.setRealm(realm);
0555:                } else if (type.equals("Engine")) {
0556:                    engine.setRealm(realm);
0557:                } else if (type.equals("Host")) {
0558:                    Host host = (Host) engine.findChild(pname
0559:                            .getKeyProperty("host"));
0560:                    host.setRealm(realm);
0561:                }
0562:
0563:                // Return the corresponding MBean name
0564:                ManagedBean managed = registry.findManagedBean("JDBCRealm");
0565:                ObjectName oname = MBeanUtils.createObjectName(managed
0566:                        .getDomain(), realm);
0567:                return (oname.toString());
0568:
0569:            }
0570:
0571:            /**
0572:             * Create a new JNDI Realm.
0573:             *
0574:             * @param parent MBean Name of the associated parent component
0575:             *
0576:             * @exception Exception if an MBean cannot be created or registered
0577:             */
0578:            public String createJNDIRealm(String parent) throws Exception {
0579:
0580:                // Create a new JNDIRealm instance
0581:                JNDIRealm realm = new JNDIRealm();
0582:
0583:                // Add the new instance to its parent component
0584:                ObjectName pname = new ObjectName(parent);
0585:                String type = pname.getKeyProperty("type");
0586:                Server server = ServerFactory.getServer();
0587:                Service service = server.findService(pname
0588:                        .getKeyProperty("service"));
0589:                Engine engine = (Engine) service.getContainer();
0590:                if (type.equals("Context")) {
0591:                    Host host = (Host) engine.findChild(pname
0592:                            .getKeyProperty("host"));
0593:                    String pathStr = getPathStr(pname.getKeyProperty("path"));
0594:                    Context context = (Context) host.findChild(pathStr);
0595:                    context.setRealm(realm);
0596:                } else if (type.equals("Engine")) {
0597:                    engine.setRealm(realm);
0598:                } else if (type.equals("Host")) {
0599:                    Host host = (Host) engine.findChild(pname
0600:                            .getKeyProperty("host"));
0601:                    host.setRealm(realm);
0602:                }
0603:
0604:                // Return the corresponding MBean name
0605:                ManagedBean managed = registry.findManagedBean("JNDIRealm");
0606:                ObjectName oname = MBeanUtils.createObjectName(managed
0607:                        .getDomain(), realm);
0608:                return (oname.toString());
0609:
0610:            }
0611:
0612:            /**
0613:             * Create a new Memory Realm.
0614:             *
0615:             * @param parent MBean Name of the associated parent component
0616:             *
0617:             * @exception Exception if an MBean cannot be created or registered
0618:             */
0619:            public String createMemoryRealm(String parent) throws Exception {
0620:
0621:                // Create a new MemoryRealm instance
0622:                MemoryRealm realm = new MemoryRealm();
0623:
0624:                // Add the new instance to its parent component
0625:                ObjectName pname = new ObjectName(parent);
0626:                String type = pname.getKeyProperty("type");
0627:                Server server = ServerFactory.getServer();
0628:                Service service = server.findService(pname
0629:                        .getKeyProperty("service"));
0630:                Engine engine = (Engine) service.getContainer();
0631:                if (type.equals("Context")) {
0632:                    Host host = (Host) engine.findChild(pname
0633:                            .getKeyProperty("host"));
0634:                    String pathStr = getPathStr(pname.getKeyProperty("path"));
0635:                    Context context = (Context) host.findChild(pathStr);
0636:                    context.setRealm(realm);
0637:                } else if (type.equals("Engine")) {
0638:                    engine.setRealm(realm);
0639:                } else if (type.equals("Host")) {
0640:                    Host host = (Host) engine.findChild(pname
0641:                            .getKeyProperty("host"));
0642:                    host.setRealm(realm);
0643:                }
0644:
0645:                // Return the corresponding MBean name
0646:                ManagedBean managed = registry.findManagedBean("MemoryRealm");
0647:                ObjectName oname = MBeanUtils.createObjectName(managed
0648:                        .getDomain(), realm);
0649:                return (oname.toString());
0650:
0651:            }
0652:
0653:            /**
0654:             * Create a new Remote Address Filter Valve.
0655:             *
0656:             * @param parent MBean Name of the associated parent component
0657:             *
0658:             * @exception Exception if an MBean cannot be created or registered
0659:             */
0660:            public String createRemoteAddrValve(String parent) throws Exception {
0661:
0662:                // Create a new RemoteAddrValve instance
0663:                RemoteAddrValve valve = new RemoteAddrValve();
0664:
0665:                // Add the new instance to its parent component
0666:                ObjectName pname = new ObjectName(parent);
0667:                String type = pname.getKeyProperty("type");
0668:                Server server = ServerFactory.getServer();
0669:                Service service = server.findService(pname
0670:                        .getKeyProperty("service"));
0671:                Engine engine = (Engine) service.getContainer();
0672:                if (type.equals("Context")) {
0673:                    Host host = (Host) engine.findChild(pname
0674:                            .getKeyProperty("host"));
0675:                    String pathStr = getPathStr(pname.getKeyProperty("path"));
0676:                    Context context = (Context) host.findChild(pathStr);
0677:                    ((StandardContext) context).addValve(valve);
0678:                } else if (type.equals("Engine")) {
0679:                    ((StandardEngine) engine).addValve(valve);
0680:                } else if (type.equals("Host")) {
0681:                    Host host = (Host) engine.findChild(pname
0682:                            .getKeyProperty("host"));
0683:                    ((StandardHost) host).addValve(valve);
0684:                }
0685:
0686:                // Return the corresponding MBean name
0687:                ManagedBean managed = registry
0688:                        .findManagedBean("RemoteAddrValve");
0689:                ObjectName oname = MBeanUtils.createObjectName(managed
0690:                        .getDomain(), valve);
0691:                return (oname.toString());
0692:
0693:            }
0694:
0695:            /**
0696:             * Create a new Remote Host Filter Valve.
0697:             *
0698:             * @param parent MBean Name of the associated parent component
0699:             *
0700:             * @exception Exception if an MBean cannot be created or registered
0701:             */
0702:            public String createRemoteHostValve(String parent) throws Exception {
0703:
0704:                // Create a new RemoteHostValve instance
0705:                RemoteHostValve valve = new RemoteHostValve();
0706:
0707:                // Add the new instance to its parent component
0708:                ObjectName pname = new ObjectName(parent);
0709:                String type = pname.getKeyProperty("type");
0710:                Server server = ServerFactory.getServer();
0711:                Service service = server.findService(pname
0712:                        .getKeyProperty("service"));
0713:                Engine engine = (Engine) service.getContainer();
0714:                if (type.equals("Context")) {
0715:                    Host host = (Host) engine.findChild(pname
0716:                            .getKeyProperty("host"));
0717:                    String pathStr = getPathStr(pname.getKeyProperty("path"));
0718:                    Context context = (Context) host.findChild(pathStr);
0719:                    ((StandardContext) context).addValve(valve);
0720:                } else if (type.equals("Engine")) {
0721:                    ((StandardEngine) engine).addValve(valve);
0722:                } else if (type.equals("Host")) {
0723:                    Host host = (Host) engine.findChild(pname
0724:                            .getKeyProperty("host"));
0725:                    ((StandardHost) host).addValve(valve);
0726:                }
0727:
0728:                // Return the corresponding MBean name
0729:                ManagedBean managed = registry
0730:                        .findManagedBean("RemoteHostValve");
0731:                ObjectName oname = MBeanUtils.createObjectName(managed
0732:                        .getDomain(), valve);
0733:                return (oname.toString());
0734:
0735:            }
0736:
0737:            /**
0738:             * Create a new Request Dumper Valve.
0739:             *
0740:             * @param parent MBean Name of the associated parent component
0741:             *
0742:             * @exception Exception if an MBean cannot be created or registered
0743:             */
0744:            public String createRequestDumperValve(String parent)
0745:                    throws Exception {
0746:
0747:                // Create a new RequestDumperValve instance
0748:                RequestDumperValve valve = new RequestDumperValve();
0749:
0750:                // Add the new instance to its parent component
0751:                ObjectName pname = new ObjectName(parent);
0752:                String type = pname.getKeyProperty("type");
0753:                Server server = ServerFactory.getServer();
0754:                Service service = server.findService(pname
0755:                        .getKeyProperty("service"));
0756:                Engine engine = (Engine) service.getContainer();
0757:                if (type.equals("Context")) {
0758:                    Host host = (Host) engine.findChild(pname
0759:                            .getKeyProperty("host"));
0760:                    String pathStr = getPathStr(pname.getKeyProperty("path"));
0761:                    Context context = (Context) host.findChild(pathStr);
0762:                    ((StandardContext) context).addValve(valve);
0763:                } else if (type.equals("Engine")) {
0764:                    ((StandardEngine) engine).addValve(valve);
0765:                } else if (type.equals("Host")) {
0766:                    Host host = (Host) engine.findChild(pname
0767:                            .getKeyProperty("host"));
0768:                    ((StandardHost) host).addValve(valve);
0769:                }
0770:
0771:                // Return the corresponding MBean name
0772:                ManagedBean managed = registry
0773:                        .findManagedBean("RequestDumperValve");
0774:                ObjectName oname = MBeanUtils.createObjectName(managed
0775:                        .getDomain(), valve);
0776:                return (oname.toString());
0777:
0778:            }
0779:
0780:            /**
0781:             * Create a new Single Sign On Valve.
0782:             *
0783:             * @param parent MBean Name of the associated parent component
0784:             *
0785:             * @exception Exception if an MBean cannot be created or registered
0786:             */
0787:            public String createSingleSignOn(String parent) throws Exception {
0788:
0789:                // Create a new SingleSignOn instance
0790:                SingleSignOn valve = new SingleSignOn();
0791:
0792:                // Add the new instance to its parent component
0793:                ObjectName pname = new ObjectName(parent);
0794:                String type = pname.getKeyProperty("type");
0795:                Server server = ServerFactory.getServer();
0796:                Service service = server.findService(pname
0797:                        .getKeyProperty("service"));
0798:                Engine engine = (Engine) service.getContainer();
0799:                if (type.equals("Context")) {
0800:                    Host host = (Host) engine.findChild(pname
0801:                            .getKeyProperty("host"));
0802:                    String pathStr = getPathStr(pname.getKeyProperty("path"));
0803:                    Context context = (Context) host.findChild(pathStr);
0804:                    ((StandardContext) context).addValve(valve);
0805:                } else if (type.equals("Engine")) {
0806:                    ((StandardEngine) engine).addValve(valve);
0807:                } else if (type.equals("Host")) {
0808:                    Host host = (Host) engine.findChild(pname
0809:                            .getKeyProperty("host"));
0810:                    ((StandardHost) host).addValve(valve);
0811:                }
0812:
0813:                // Return the corresponding MBean name
0814:                ManagedBean managed = registry.findManagedBean("SingleSignOn");
0815:                ObjectName oname = MBeanUtils.createObjectName(managed
0816:                        .getDomain(), valve);
0817:                return (oname.toString());
0818:
0819:            }
0820:
0821:            /**
0822:             * Create a new StandardContext.
0823:             *
0824:             * @param parent MBean Name of the associated parent component
0825:             * @param path The context path for this Context
0826:             * @param docBase Document base directory (or WAR) for this Context
0827:             *
0828:             * @exception Exception if an MBean cannot be created or registered
0829:             */
0830:            public String createStandardContext(String parent, String path,
0831:                    String docBase) throws Exception {
0832:
0833:                // Create a new StandardContext instance
0834:                StandardContext context = new StandardContext();
0835:                path = getPathStr(path);
0836:                context.setPath(path);
0837:                context.setDocBase(docBase);
0838:
0839:                // Add the new instance to its parent component
0840:                ObjectName pname = new ObjectName(parent);
0841:                Server server = ServerFactory.getServer();
0842:                Service service = server.findService(pname
0843:                        .getKeyProperty("service"));
0844:                Engine engine = (Engine) service.getContainer();
0845:                Host host = (Host) engine.findChild(pname
0846:                        .getKeyProperty("host"));
0847:                host.addChild(context);
0848:
0849:                // Return the corresponding MBean name
0850:                ManagedBean managed = registry
0851:                        .findManagedBean("StandardContext");
0852:                ObjectName oname = MBeanUtils.createObjectName(managed
0853:                        .getDomain(), context);
0854:                return (oname.toString());
0855:
0856:            }
0857:
0858:            /**
0859:             * Create a new StandardEngine.
0860:             *
0861:             * @param parent MBean Name of the associated parent component
0862:             * @param name Unique name of this Engine
0863:             * @param defaultHost Default hostname of this Engine
0864:             *
0865:             * @exception Exception if an MBean cannot be created or registered
0866:             */
0867:            public String createStandardEngine(String parent, String name,
0868:                    String defaultHost) throws Exception {
0869:
0870:                // Create a new StandardEngine instance
0871:                StandardEngine engine = new StandardEngine();
0872:                engine.setName(name);
0873:                engine.setDefaultHost(defaultHost);
0874:
0875:                // Add the new instance to its parent component
0876:                ObjectName pname = new ObjectName(parent);
0877:                Server server = ServerFactory.getServer();
0878:                Service service = server.findService(pname
0879:                        .getKeyProperty("name"));
0880:                service.setContainer(engine);
0881:
0882:                // Return the corresponding MBean name
0883:                ManagedBean managed = registry
0884:                        .findManagedBean("StandardEngine");
0885:                ObjectName oname = MBeanUtils.createObjectName(managed
0886:                        .getDomain(), engine);
0887:                return (oname.toString());
0888:
0889:            }
0890:
0891:            /**
0892:             * Create a new StandardHost.
0893:             *
0894:             * @param parent MBean Name of the associated parent component
0895:             * @param name Unique name of this Host
0896:             * @param appBase Application base directory name
0897:             * @param unpackWARs Should we unpack WARs when auto deploying?
0898:             *
0899:             * @exception Exception if an MBean cannot be created or registered
0900:             */
0901:            public String createStandardHost(String parent, String name,
0902:                    String appBase, boolean unpackWARs) throws Exception {
0903:
0904:                // Create a new StandardHost instance
0905:                StandardHost host = new StandardHost();
0906:                host.setName(name);
0907:                host.setAppBase(appBase);
0908:                host.setUnpackWARs(unpackWARs);
0909:
0910:                // Add the new instance to its parent component
0911:                ObjectName pname = new ObjectName(parent);
0912:                Server server = ServerFactory.getServer();
0913:                Service service = server.findService(pname
0914:                        .getKeyProperty("service"));
0915:                Engine engine = (Engine) service.getContainer();
0916:                engine.addChild(host);
0917:
0918:                // Return the corresponding MBean name
0919:                ManagedBean managed = registry.findManagedBean("StandardHost");
0920:                ObjectName oname = MBeanUtils.createObjectName(managed
0921:                        .getDomain(), host);
0922:                return (oname.toString());
0923:
0924:            }
0925:
0926:            /**
0927:             * Create a new StandardManager.
0928:             *
0929:             * @param parent MBean Name of the associated parent component
0930:             *
0931:             * @exception Exception if an MBean cannot be created or registered
0932:             */
0933:            public String createStandardManager(String parent) throws Exception {
0934:
0935:                // Create a new StandardManager instance
0936:                StandardManager manager = new StandardManager();
0937:
0938:                // Add the new instance to its parent component
0939:                ObjectName pname = new ObjectName(parent);
0940:                Server server = ServerFactory.getServer();
0941:                Service service = server.findService(pname
0942:                        .getKeyProperty("service"));
0943:                Engine engine = (Engine) service.getContainer();
0944:                Host host = (Host) engine.findChild(pname
0945:                        .getKeyProperty("host"));
0946:                String pathStr = getPathStr(pname.getKeyProperty("path"));
0947:                Context context = (Context) host.findChild(pathStr);
0948:                context.setManager(manager);
0949:
0950:                // Return the corresponding MBean name
0951:                ManagedBean managed = registry
0952:                        .findManagedBean("StandardManager");
0953:                ObjectName oname = MBeanUtils.createObjectName(managed
0954:                        .getDomain(), manager);
0955:                return (oname.toString());
0956:
0957:            }
0958:
0959:            /**
0960:             * Create a new StandardService.
0961:             *
0962:             * @param parent MBean Name of the associated parent component
0963:             * @param name Unique name of this StandardService
0964:             *
0965:             * @exception Exception if an MBean cannot be created or registered
0966:             */
0967:            public String createStandardService(String parent, String name)
0968:                    throws Exception {
0969:
0970:                // Create a new StandardService instance
0971:                StandardService service = new StandardService();
0972:                service.setName(name);
0973:
0974:                // Add the new instance to its parent component
0975:                Server server = ServerFactory.getServer();
0976:                server.addService(service);
0977:
0978:                // Return the corresponding MBean name
0979:                ManagedBean managed = registry
0980:                        .findManagedBean("StandardService");
0981:                ObjectName oname = MBeanUtils.createObjectName(managed
0982:                        .getDomain(), service);
0983:                return (oname.toString());
0984:
0985:            }
0986:
0987:            /**
0988:             * Create a new System Error Logger.
0989:             *
0990:             * @param parent MBean Name of the associated parent component
0991:             *
0992:             * @exception Exception if an MBean cannot be created or registered
0993:             */
0994:            public String createSystemErrLogger(String parent) throws Exception {
0995:
0996:                // Create a new SystemErrLogger instance
0997:                SystemErrLogger logger = new SystemErrLogger();
0998:
0999:                // Add the new instance to its parent component
1000:                ObjectName pname = new ObjectName(parent);
1001:                String type = pname.getKeyProperty("type");
1002:                Server server = ServerFactory.getServer();
1003:                Service service = server.findService(pname
1004:                        .getKeyProperty("service"));
1005:                Engine engine = (Engine) service.getContainer();
1006:                if (type.equals("Context")) {
1007:                    Host host = (Host) engine.findChild(pname
1008:                            .getKeyProperty("host"));
1009:                    String pathStr = getPathStr(pname.getKeyProperty("path"));
1010:                    Context context = (Context) host.findChild(pathStr);
1011:                    context.setLogger(logger);
1012:                } else if (type.equals("Engine")) {
1013:                    engine.setLogger(logger);
1014:                } else if (type.equals("Host")) {
1015:                    Host host = (Host) engine.findChild(pname
1016:                            .getKeyProperty("host"));
1017:                    host.setLogger(logger);
1018:                }
1019:
1020:                // Return the corresponding MBean name
1021:                ManagedBean managed = registry
1022:                        .findManagedBean("SystemErrLogger");
1023:                ObjectName oname = MBeanUtils.createObjectName(managed
1024:                        .getDomain(), logger);
1025:                return (oname.toString());
1026:
1027:            }
1028:
1029:            /**
1030:             * Create a new System Output Logger.
1031:             *
1032:             * @param parent MBean Name of the associated parent component
1033:             *
1034:             * @exception Exception if an MBean cannot be created or registered
1035:             */
1036:            public String createSystemOutLogger(String parent) throws Exception {
1037:
1038:                // Create a new SystemOutLogger instance
1039:                SystemOutLogger logger = new SystemOutLogger();
1040:
1041:                // Add the new instance to its parent component
1042:                ObjectName pname = new ObjectName(parent);
1043:                String type = pname.getKeyProperty("type");
1044:                Server server = ServerFactory.getServer();
1045:                Service service = server.findService(pname
1046:                        .getKeyProperty("service"));
1047:                Engine engine = (Engine) service.getContainer();
1048:                if (type.equals("Context")) {
1049:                    Host host = (Host) engine.findChild(pname
1050:                            .getKeyProperty("host"));
1051:                    String pathStr = getPathStr(pname.getKeyProperty("path"));
1052:                    Context context = (Context) host.findChild(pathStr);
1053:                    context.setLogger(logger);
1054:                } else if (type.equals("Engine")) {
1055:                    engine.setLogger(logger);
1056:                } else if (type.equals("Host")) {
1057:                    Host host = (Host) engine.findChild(pname
1058:                            .getKeyProperty("host"));
1059:                    host.setLogger(logger);
1060:                }
1061:
1062:                // Return the corresponding MBean name
1063:                ManagedBean managed = registry
1064:                        .findManagedBean("SystemOutLogger");
1065:                ObjectName oname = MBeanUtils.createObjectName(managed
1066:                        .getDomain(), logger);
1067:                return (oname.toString());
1068:            }
1069:
1070:            /**
1071:             * Create a new  UserDatabaseRealm.
1072:             *
1073:             * @param parent MBean Name of the associated parent component
1074:             * @param resourceName Global JNDI resource name of the associated
1075:             *  UserDatabase
1076:             *
1077:             * @exception Exception if an MBean cannot be created or registered
1078:             */
1079:            public String createUserDatabaseRealm(String parent,
1080:                    String resourceName) throws Exception {
1081:
1082:                // Create a new UserDatabaseRealm instance
1083:                UserDatabaseRealm realm = new UserDatabaseRealm();
1084:                realm.setResourceName(resourceName);
1085:                // Add the new instance to its parent component
1086:                ObjectName pname = new ObjectName(parent);
1087:                String type = pname.getKeyProperty("type");
1088:                Server server = ServerFactory.getServer();
1089:                Service service = server.findService(pname
1090:                        .getKeyProperty("service"));
1091:                Engine engine = (Engine) service.getContainer();
1092:                if (type.equals("Context")) {
1093:                    Host host = (Host) engine.findChild(pname
1094:                            .getKeyProperty("host"));
1095:                    String pathStr = getPathStr(pname.getKeyProperty("path"));
1096:                    Context context = (Context) host.findChild(pathStr);
1097:                    context.setRealm(realm);
1098:                } else if (type.equals("Engine")) {
1099:                    engine.setRealm(realm);
1100:                } else if (type.equals("Host")) {
1101:                    Host host = (Host) engine.findChild(pname
1102:                            .getKeyProperty("host"));
1103:                    host.setRealm(realm);
1104:                }
1105:
1106:                // Return the corresponding MBean name
1107:                ManagedBean managed = registry
1108:                        .findManagedBean("UserDatabaseRealm");
1109:                ObjectName oname = MBeanUtils.createObjectName(managed
1110:                        .getDomain(), realm);
1111:                return (oname.toString());
1112:
1113:            }
1114:
1115:            /**
1116:             * Create a new Web Application Loader.
1117:             *
1118:             * @param parent MBean Name of the associated parent component
1119:             *
1120:             * @exception Exception if an MBean cannot be created or registered
1121:             */
1122:            public String createWebappLoader(String parent) throws Exception {
1123:
1124:                // Create a new WebappLoader instance
1125:                WebappLoader loader = new WebappLoader();
1126:
1127:                // Add the new instance to its parent component
1128:                ObjectName pname = new ObjectName(parent);
1129:                Server server = ServerFactory.getServer();
1130:                Service service = server.findService(pname
1131:                        .getKeyProperty("service"));
1132:                Engine engine = (Engine) service.getContainer();
1133:                Host host = (Host) engine.findChild(pname
1134:                        .getKeyProperty("host"));
1135:                String pathStr = getPathStr(pname.getKeyProperty("path"));
1136:                Context context = (Context) host.findChild(pathStr);
1137:                context.setLoader(loader);
1138:
1139:                // Return the corresponding MBean name
1140:                ManagedBean managed = registry.findManagedBean("WebappLoader");
1141:                ObjectName oname = MBeanUtils.createObjectName(managed
1142:                        .getDomain(), loader);
1143:                return (oname.toString());
1144:
1145:            }
1146:
1147:            /**
1148:             * Remove an existing Connector.
1149:             *
1150:             * @param name MBean Name of the comonent to remove
1151:             *
1152:             * @param serviceName Service name of the connector to remove
1153:             *
1154:             * @exception Exception if a component cannot be removed
1155:             */
1156:            public void removeConnector(String name) throws Exception {
1157:
1158:                // Acquire a reference to the component to be removed
1159:                ObjectName oname = new ObjectName(name);
1160:                Server server = ServerFactory.getServer();
1161:                String serviceName = oname.getKeyProperty("service");
1162:                Service service = server.findService(serviceName);
1163:                String port = oname.getKeyProperty("port");
1164:                String address = oname.getKeyProperty("address");
1165:
1166:                Connector conns[] = (Connector[]) service.findConnectors();
1167:
1168:                for (int i = 0; i < conns.length; i++) {
1169:                    Class cls = conns[i].getClass();
1170:                    Method getAddrMeth = cls.getMethod("getAddress", null);
1171:                    Object addrObj = getAddrMeth.invoke(conns[i], null);
1172:                    String connAddress = null;
1173:                    if (addrObj != null) {
1174:                        connAddress = addrObj.toString();
1175:                    }
1176:                    Method getPortMeth = cls.getMethod("getPort", null);
1177:                    Object portObj = getPortMeth.invoke(conns[i], null);
1178:                    String connPort = new String();
1179:                    if (portObj != null) {
1180:                        connPort = portObj.toString();
1181:                    }
1182:                    if (((address.equals("null")) && (connAddress == null))
1183:                            && port.equals(connPort)) {
1184:                        service.removeConnector(conns[i]);
1185:                        break;
1186:                    } else if (address.equals(connAddress)
1187:                            && port.equals(connPort)) {
1188:                        // Remove this component from its parent component
1189:                        service.removeConnector(conns[i]);
1190:                        break;
1191:                    }
1192:                }
1193:
1194:            }
1195:
1196:            /**
1197:             * Remove an existing Context.
1198:             *
1199:             * @param name MBean Name of the comonent to remove
1200:             *
1201:             * @exception Exception if a component cannot be removed
1202:             */
1203:            public void removeContext(String name) throws Exception {
1204:
1205:                // Acquire a reference to the component to be removed
1206:                ObjectName oname = new ObjectName(name);
1207:                String serviceName = oname.getKeyProperty("service");
1208:                String hostName = oname.getKeyProperty("host");
1209:                String contextName = getPathStr(oname.getKeyProperty("path"));
1210:                Server server = ServerFactory.getServer();
1211:                Service service = server.findService(serviceName);
1212:                Engine engine = (Engine) service.getContainer();
1213:                Host host = (Host) engine.findChild(hostName);
1214:                Context context = (Context) host.findChild(contextName);
1215:
1216:                // Remove this component from its parent component
1217:                host.removeChild(context);
1218:
1219:            }
1220:
1221:            /**
1222:             * Remove an existing Host.
1223:             *
1224:             * @param name MBean Name of the comonent to remove
1225:             *
1226:             * @exception Exception if a component cannot be removed
1227:             */
1228:            public void removeHost(String name) throws Exception {
1229:
1230:                // Acquire a reference to the component to be removed
1231:                ObjectName oname = new ObjectName(name);
1232:                String serviceName = oname.getKeyProperty("service");
1233:                String hostName = oname.getKeyProperty("host");
1234:                Server server = ServerFactory.getServer();
1235:                Service service = server.findService(serviceName);
1236:                Engine engine = (Engine) service.getContainer();
1237:                Host host = (Host) engine.findChild(hostName);
1238:
1239:                // Remove this component from its parent component
1240:                engine.removeChild(host);
1241:
1242:            }
1243:
1244:            /**
1245:             * Remove an existing Logger.
1246:             *
1247:             * @param name MBean Name of the comonent to remove
1248:             *
1249:             * @exception Exception if a component cannot be removed
1250:             */
1251:            public void removeLogger(String name) throws Exception {
1252:
1253:                // Acquire a reference to the component to be removed
1254:                ObjectName oname = new ObjectName(name);
1255:                String serviceName = oname.getKeyProperty("service");
1256:                String hostName = oname.getKeyProperty("host");
1257:
1258:                String path = oname.getKeyProperty("path");
1259:                Server server = ServerFactory.getServer();
1260:                Service service = server.findService(serviceName);
1261:                StandardEngine engine = (StandardEngine) service.getContainer();
1262:                if (hostName == null) { // if logger's container is Engine
1263:                    Logger logger = engine.getLogger();
1264:                    Container container = logger.getContainer();
1265:                    if (container instanceof  StandardEngine) {
1266:                        String sname = ((StandardEngine) container)
1267:                                .getService().getName();
1268:                        if (sname.equals(serviceName)) {
1269:                            engine.setLogger(null);
1270:                        }
1271:                    }
1272:                } else if (path == null) { // if logger's container is Host
1273:                    StandardHost host = (StandardHost) engine
1274:                            .findChild(hostName);
1275:                    Logger logger = host.getLogger();
1276:                    Container container = logger.getContainer();
1277:                    if (container instanceof  StandardHost) {
1278:                        String hn = ((StandardHost) container).getName();
1279:                        StandardEngine se = (StandardEngine) ((StandardHost) container)
1280:                                .getParent();
1281:                        String sname = se.getService().getName();
1282:                        if (sname.equals(serviceName) && hn.equals(hostName)) {
1283:                            host.setLogger(null);
1284:                        }
1285:                    }
1286:                } else { // logger's container is Context
1287:                    StandardHost host = (StandardHost) engine
1288:                            .findChild(hostName);
1289:                    path = getPathStr(path);
1290:                    StandardContext context = (StandardContext) host
1291:                            .findChild(path);
1292:                    Logger logger = context.getLogger();
1293:                    Container container = logger.getContainer();
1294:                    if (container instanceof  StandardContext) {
1295:                        String pathName = ((StandardContext) container)
1296:                                .getName();
1297:                        StandardHost sh = (StandardHost) ((StandardContext) container)
1298:                                .getParent();
1299:                        String hn = sh.getName();
1300:                        ;
1301:                        StandardEngine se = (StandardEngine) sh.getParent();
1302:                        String sname = se.getService().getName();
1303:                        if ((sname.equals(serviceName) && hn.equals(hostName))
1304:                                && pathName.equals(path)) {
1305:                            context.setLogger(null);
1306:                        }
1307:                    }
1308:                }
1309:            }
1310:
1311:            /**
1312:             * Remove an existing Loader.
1313:             *
1314:             * @param name MBean Name of the comonent to remove
1315:             *
1316:             * @exception Exception if a component cannot be removed
1317:             */
1318:            public void removeLoader(String name) throws Exception {
1319:
1320:                // Acquire a reference to the component to be removed
1321:                ObjectName oname = new ObjectName(name);
1322:                String serviceName = oname.getKeyProperty("service");
1323:                String hostName = oname.getKeyProperty("host");
1324:                String contextName = getPathStr(oname.getKeyProperty("path"));
1325:                Server server = ServerFactory.getServer();
1326:                Service service = server.findService(serviceName);
1327:                Engine engine = (Engine) service.getContainer();
1328:                Host host = (Host) engine.findChild(hostName);
1329:                Context context = (Context) host.findChild(contextName);
1330:
1331:                // Remove this component from its parent component
1332:                context.setLoader(null);
1333:
1334:            }
1335:
1336:            /**
1337:             * Remove an existing Manager.
1338:             *
1339:             * @param name MBean Name of the comonent to remove
1340:             *
1341:             * @exception Exception if a component cannot be removed
1342:             */
1343:            public void removeManager(String name) throws Exception {
1344:
1345:                // Acquire a reference to the component to be removed
1346:                ObjectName oname = new ObjectName(name);
1347:                String serviceName = oname.getKeyProperty("service");
1348:                String hostName = oname.getKeyProperty("host");
1349:                String contextName = getPathStr(oname.getKeyProperty("path"));
1350:                Server server = ServerFactory.getServer();
1351:                Service service = server.findService(serviceName);
1352:                Engine engine = (Engine) service.getContainer();
1353:                Host host = (Host) engine.findChild(hostName);
1354:                Context context = (Context) host.findChild(contextName);
1355:
1356:                // Remove this component from its parent component
1357:                context.setManager(null);
1358:
1359:            }
1360:
1361:            /**
1362:             * Remove an existing Realm.
1363:             *
1364:             * @param name MBean Name of the comonent to remove
1365:             *
1366:             * @exception Exception if a component cannot be removed
1367:             */
1368:            public void removeRealm(String name) throws Exception {
1369:
1370:                // Acquire a reference to the component to be removed
1371:                ObjectName oname = new ObjectName(name);
1372:                String serviceName = oname.getKeyProperty("service");
1373:                String hostName = oname.getKeyProperty("host");
1374:                String path = oname.getKeyProperty("path");
1375:                Server server = ServerFactory.getServer();
1376:                Service service = server.findService(serviceName);
1377:                StandardEngine engine = (StandardEngine) service.getContainer();
1378:                if (hostName == null) { // if realm's container is Engine
1379:                    Realm realm = engine.getRealm();
1380:                    Container container = realm.getContainer();
1381:                    if (container instanceof  StandardEngine) {
1382:                        String sname = ((StandardEngine) container)
1383:                                .getService().getName();
1384:                        if (sname.equals(serviceName)) {
1385:                            engine.setRealm(null);
1386:                        }
1387:                    }
1388:                } else if (path == null) { // if realm's container is Host
1389:                    StandardHost host = (StandardHost) engine
1390:                            .findChild(hostName);
1391:                    Realm realm = host.getRealm();
1392:                    Container container = realm.getContainer();
1393:                    if (container instanceof  StandardHost) {
1394:                        String hn = ((StandardHost) container).getName();
1395:                        StandardEngine se = (StandardEngine) ((StandardHost) container)
1396:                                .getParent();
1397:                        String sname = se.getService().getName();
1398:                        if (sname.equals(serviceName) && hn.equals(hostName)) {
1399:                            host.setRealm(null);
1400:                        }
1401:                    }
1402:                } else { // realm's container is Context
1403:                    StandardHost host = (StandardHost) engine
1404:                            .findChild(hostName);
1405:                    path = getPathStr(path);
1406:                    StandardContext context = (StandardContext) host
1407:                            .findChild(path);
1408:                    Realm realm = context.getRealm();
1409:                    Container container = realm.getContainer();
1410:                    if (container instanceof  StandardContext) {
1411:                        String pathName = ((StandardContext) container)
1412:                                .getName();
1413:                        StandardHost sh = (StandardHost) ((StandardContext) container)
1414:                                .getParent();
1415:                        String hn = sh.getName();
1416:                        ;
1417:                        StandardEngine se = (StandardEngine) sh.getParent();
1418:                        String sname = se.getService().getName();
1419:                        if ((sname.equals(serviceName) && hn.equals(hostName))
1420:                                && pathName.equals(path)) {
1421:                            context.setRealm(null);
1422:                        }
1423:                    }
1424:                }
1425:            }
1426:
1427:            /**
1428:             * Remove an existing Service.
1429:             *
1430:             * @param name MBean Name of the component to remove
1431:             *
1432:             * @exception Exception if a component cannot be removed
1433:             */
1434:            public void removeService(String name) throws Exception {
1435:
1436:                // Acquire a reference to the component to be removed
1437:                ObjectName oname = new ObjectName(name);
1438:                String serviceName = oname.getKeyProperty("name");
1439:                Server server = ServerFactory.getServer();
1440:                Service service = server.findService(serviceName);
1441:
1442:                // Remove this component from its parent component
1443:                server.removeService(service);
1444:
1445:            }
1446:
1447:            /**
1448:             * Remove an existing Valve.
1449:             *
1450:             * @param name MBean Name of the comonent to remove
1451:             *
1452:             * @exception Exception if a component cannot be removed
1453:             */
1454:            public void removeValve(String name) throws Exception {
1455:
1456:                // Acquire a reference to the component to be removed
1457:                ObjectName oname = new ObjectName(name);
1458:                String serviceName = oname.getKeyProperty("service");
1459:                String hostName = oname.getKeyProperty("host");
1460:                String path = oname.getKeyProperty("path");
1461:                String sequence = oname.getKeyProperty("sequence");
1462:                Server server = ServerFactory.getServer();
1463:                Service service = server.findService(serviceName);
1464:                StandardEngine engine = (StandardEngine) service.getContainer();
1465:                if (hostName == null) { // if valve's container is Engine
1466:                    Valve[] valves = engine.getValves();
1467:                    for (int i = 0; i < valves.length; i++) {
1468:                        Container container = ((ValveBase) valves[i])
1469:                                .getContainer();
1470:                        if (container instanceof  StandardEngine) {
1471:                            String sname = ((StandardEngine) container)
1472:                                    .getService().getName();
1473:                            Integer sequenceInt = new Integer(valves[i]
1474:                                    .hashCode());
1475:                            if (sname.equals(serviceName)
1476:                                    && sequence.equals(sequenceInt.toString())) {
1477:                                engine.removeValve(valves[i]);
1478:                                break;
1479:                            }
1480:                        }
1481:                    }
1482:                } else if (path == null) { // if valve's container is Host
1483:                    StandardHost host = (StandardHost) engine
1484:                            .findChild(hostName);
1485:                    Valve[] valves = host.getValves();
1486:                    for (int i = 0; i < valves.length; i++) {
1487:                        Container container = ((ValveBase) valves[i])
1488:                                .getContainer();
1489:                        if (container instanceof  StandardHost) {
1490:                            String hn = ((StandardHost) container).getName();
1491:                            StandardEngine se = (StandardEngine) ((StandardHost) container)
1492:                                    .getParent();
1493:                            String sname = se.getService().getName();
1494:                            Integer sequenceInt = new Integer(valves[i]
1495:                                    .hashCode());
1496:                            if ((sname.equals(serviceName) && hn
1497:                                    .equals(hostName))
1498:                                    && sequence.equals(sequenceInt.toString())) {
1499:                                host.removeValve(valves[i]);
1500:                                break;
1501:                            }
1502:                        }
1503:                    }
1504:                } else { // valve's container is Context
1505:                    StandardHost host = (StandardHost) engine
1506:                            .findChild(hostName);
1507:                    path = getPathStr(path);
1508:                    StandardContext context = (StandardContext) host
1509:                            .findChild(path);
1510:                    Valve[] valves = context.getValves();
1511:                    for (int i = 0; i < valves.length; i++) {
1512:                        Container container = ((ValveBase) valves[i])
1513:                                .getContainer();
1514:                        if (container instanceof  StandardContext) {
1515:                            String pathName = ((StandardContext) container)
1516:                                    .getName();
1517:                            StandardHost sh = (StandardHost) ((StandardContext) container)
1518:                                    .getParent();
1519:                            String hn = sh.getName();
1520:                            ;
1521:                            StandardEngine se = (StandardEngine) sh.getParent();
1522:                            String sname = se.getService().getName();
1523:                            Integer sequenceInt = new Integer(valves[i]
1524:                                    .hashCode());
1525:                            if (((sname.equals(serviceName) && hn
1526:                                    .equals(hostName)) && pathName.equals(path))
1527:                                    && sequence.equals(sequenceInt.toString())) {
1528:                                context.removeValve(valves[i]);
1529:                                break;
1530:                            }
1531:                        }
1532:                    }
1533:                }
1534:            }
1535:
1536:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.