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


0001:        /*
0002:         * Licensed to the Apache Software Foundation (ASF) under one or more
0003:         * contributor license agreements.  See the NOTICE file distributed with
0004:         * this work for additional information regarding copyright ownership.
0005:         * The ASF licenses this file to You under the Apache License, Version 2.0
0006:         * (the "License"); you may not use this file except in compliance with
0007:         * the License.  You may obtain a copy of the License at
0008:         * 
0009:         *      http://www.apache.org/licenses/LICENSE-2.0
0010:         * 
0011:         * Unless required by applicable law or agreed to in writing, software
0012:         * distributed under the License is distributed on an "AS IS" BASIS,
0013:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0014:         * See the License for the specific language governing permissions and
0015:         * limitations under the License.
0016:         */
0017:
0018:        package org.apache.catalina.mbeans;
0019:
0020:        import java.io.File;
0021:        import java.util.Vector;
0022:
0023:        import javax.management.MBeanException;
0024:        import javax.management.MBeanServer;
0025:        import javax.management.ObjectName;
0026:        import javax.management.RuntimeOperationsException;
0027:
0028:        import org.apache.catalina.Context;
0029:        import org.apache.catalina.Engine;
0030:        import org.apache.catalina.Host;
0031:        import org.apache.catalina.Server;
0032:        import org.apache.catalina.ServerFactory;
0033:        import org.apache.catalina.Service;
0034:        import org.apache.catalina.Valve;
0035:        import org.apache.catalina.authenticator.SingleSignOn;
0036:        import org.apache.catalina.connector.Connector;
0037:        import org.apache.catalina.core.ContainerBase;
0038:        import org.apache.catalina.core.StandardContext;
0039:        import org.apache.catalina.core.StandardEngine;
0040:        import org.apache.catalina.core.StandardHost;
0041:        import org.apache.catalina.core.StandardService;
0042:        import org.apache.catalina.loader.WebappLoader;
0043:        import org.apache.catalina.realm.DataSourceRealm;
0044:        import org.apache.catalina.realm.JDBCRealm;
0045:        import org.apache.catalina.realm.JNDIRealm;
0046:        import org.apache.catalina.realm.MemoryRealm;
0047:        import org.apache.catalina.realm.UserDatabaseRealm;
0048:        import org.apache.catalina.session.StandardManager;
0049:        import org.apache.catalina.startup.ContextConfig;
0050:        import org.apache.catalina.startup.HostConfig;
0051:        import org.apache.catalina.valves.AccessLogValve;
0052:        import org.apache.catalina.valves.RemoteAddrValve;
0053:        import org.apache.catalina.valves.RemoteHostValve;
0054:        import org.apache.catalina.valves.RequestDumperValve;
0055:        import org.apache.catalina.valves.ValveBase;
0056:        import org.apache.tomcat.util.modeler.BaseModelMBean;
0057:        import org.apache.tomcat.util.modeler.Registry;
0058:
0059:        /**
0060:         * <p>A <strong>ModelMBean</strong> implementation for the
0061:         * <code>org.apache.catalina.core.StandardServer</code> component.</p>
0062:         *
0063:         * @author Amy Roh
0064:         * @version $Revision: 467222 $ $Date: 2006-10-24 05:17:11 +0200 (mar., 24 oct. 2006) $
0065:         */
0066:
0067:        public class MBeanFactory extends BaseModelMBean {
0068:
0069:            private static org.apache.juli.logging.Log log = org.apache.juli.logging.LogFactory
0070:                    .getLog(MBeanFactory.class);
0071:
0072:            /**
0073:             * The <code>MBeanServer</code> for this application.
0074:             */
0075:            private static MBeanServer mserver = MBeanUtils.createServer();
0076:
0077:            /**
0078:             * The configuration information registry for our managed beans.
0079:             */
0080:            private static Registry registry = MBeanUtils.createRegistry();
0081:
0082:            // ----------------------------------------------------------- Constructors
0083:
0084:            /**
0085:             * Construct a <code>ModelMBean</code> with default
0086:             * <code>ModelMBeanInfo</code> information.
0087:             *
0088:             * @exception MBeanException if the initializer of an object
0089:             *  throws an exception
0090:             * @exception RuntimeOperationsException if an IllegalArgumentException
0091:             *  occurs
0092:             */
0093:            public MBeanFactory() throws MBeanException,
0094:                    RuntimeOperationsException {
0095:
0096:                super ();
0097:
0098:            }
0099:
0100:            // ------------------------------------------------------------- Attributes
0101:
0102:            // ------------------------------------------------------------- Operations
0103:
0104:            /**
0105:             * Return the managed bean definition for the specified bean type
0106:             *
0107:             * @param type MBean type
0108:             */
0109:            public String findObjectName(String type) {
0110:
0111:                if (type.equals("org.apache.catalina.core.StandardContext")) {
0112:                    return "StandardContext";
0113:                } else if (type
0114:                        .equals("org.apache.catalina.core.StandardEngine")) {
0115:                    return "Engine";
0116:                } else if (type.equals("org.apache.catalina.core.StandardHost")) {
0117:                    return "Host";
0118:                } else {
0119:                    return null;
0120:                }
0121:
0122:            }
0123:
0124:            /**
0125:             * Little convenience method to remove redundant code
0126:             * when retrieving the path string
0127:             *
0128:             * @param t path string
0129:             * @return empty string if t==null || t.equals("/")
0130:             */
0131:            private final String getPathStr(String t) {
0132:                if (t == null || t.equals("/")) {
0133:                    return "";
0134:                }
0135:                return t;
0136:            }
0137:
0138:            /**
0139:             * Get Parent ContainerBase to add its child component 
0140:             * from parent's ObjectName
0141:             */
0142:            private ContainerBase getParentContainerFromParent(ObjectName pname)
0143:                    throws Exception {
0144:
0145:                String type = pname.getKeyProperty("type");
0146:                String j2eeType = pname.getKeyProperty("j2eeType");
0147:                Service service = getService(pname);
0148:                StandardEngine engine = (StandardEngine) service.getContainer();
0149:                if ((j2eeType != null) && (j2eeType.equals("WebModule"))) {
0150:                    String name = pname.getKeyProperty("name");
0151:                    name = name.substring(2);
0152:                    int i = name.indexOf("/");
0153:                    String hostName = name.substring(0, i);
0154:                    String path = name.substring(i);
0155:                    Host host = (Host) engine.findChild(hostName);
0156:                    String pathStr = getPathStr(path);
0157:                    StandardContext context = (StandardContext) host
0158:                            .findChild(pathStr);
0159:                    return context;
0160:                } else if (type != null) {
0161:                    if (type.equals("Engine")) {
0162:                        return engine;
0163:                    } else if (type.equals("Host")) {
0164:                        String hostName = pname.getKeyProperty("host");
0165:                        StandardHost host = (StandardHost) engine
0166:                                .findChild(hostName);
0167:                        return host;
0168:                    }
0169:                }
0170:                return null;
0171:
0172:            }
0173:
0174:            /**
0175:             * Get Parent ContainerBase to add its child component 
0176:             * from child component's ObjectName  as a String
0177:             */
0178:            private ContainerBase getParentContainerFromChild(ObjectName oname)
0179:                    throws Exception {
0180:
0181:                String hostName = oname.getKeyProperty("host");
0182:                String path = oname.getKeyProperty("path");
0183:                Service service = getService(oname);
0184:                StandardEngine engine = (StandardEngine) service.getContainer();
0185:                if (hostName == null) {
0186:                    // child's container is Engine
0187:                    return engine;
0188:                } else if (path == null) {
0189:                    // child's container is Host
0190:                    StandardHost host = (StandardHost) engine
0191:                            .findChild(hostName);
0192:                    return host;
0193:                } else {
0194:                    // child's container is Context
0195:                    StandardHost host = (StandardHost) engine
0196:                            .findChild(hostName);
0197:                    path = getPathStr(path);
0198:                    StandardContext context = (StandardContext) host
0199:                            .findChild(path);
0200:                    return context;
0201:                }
0202:            }
0203:
0204:            private Service getService(ObjectName oname) throws Exception {
0205:
0206:                String domain = oname.getDomain();
0207:                Server server = ServerFactory.getServer();
0208:                Service[] services = server.findServices();
0209:                StandardService service = null;
0210:                for (int i = 0; i < services.length; i++) {
0211:                    service = (StandardService) services[i];
0212:                    if (domain.equals(service.getObjectName().getDomain())) {
0213:                        break;
0214:                    }
0215:                }
0216:                if (!service.getObjectName().getDomain().equals(domain)) {
0217:                    throw new Exception("Service with the domain is not found");
0218:                }
0219:                return service;
0220:
0221:            }
0222:
0223:            /**
0224:             * Create a new AccessLoggerValve.
0225:             *
0226:             * @param parent MBean Name of the associated parent component
0227:             *
0228:             * @exception Exception if an MBean cannot be created or registered
0229:             */
0230:            public String createAccessLoggerValve(String parent)
0231:                    throws Exception {
0232:
0233:                ObjectName pname = new ObjectName(parent);
0234:                // Create a new AccessLogValve instance
0235:                AccessLogValve accessLogger = new AccessLogValve();
0236:                ContainerBase containerBase = getParentContainerFromParent(pname);
0237:                // Add the new instance to its parent component
0238:                containerBase.addValve(accessLogger);
0239:                ObjectName oname = accessLogger.getObjectName();
0240:                return (oname.toString());
0241:
0242:            }
0243:
0244:            /**
0245:             * Create a new AjpConnector
0246:             *
0247:             * @param parent MBean Name of the associated parent component
0248:             * @param address The IP address on which to bind
0249:             * @param port TCP port number to listen on
0250:             *
0251:             * @exception Exception if an MBean cannot be created or registered
0252:             */
0253:            public String createAjpConnector(String parent, String address,
0254:                    int port) throws Exception {
0255:
0256:                return createConnector(parent, address, port, true, false);
0257:            }
0258:
0259:            /**
0260:             * Create a new DataSource Realm.
0261:             *
0262:             * @param parent MBean Name of the associated parent component
0263:             *
0264:             * @exception Exception if an MBean cannot be created or registered
0265:             */
0266:            public String createDataSourceRealm(String parent,
0267:                    String dataSourceName, String roleNameCol,
0268:                    String userCredCol, String userNameCol,
0269:                    String userRoleTable, String userTable) throws Exception {
0270:
0271:                // Create a new DataSourceRealm instance
0272:                DataSourceRealm realm = new DataSourceRealm();
0273:                realm.setDataSourceName(dataSourceName);
0274:                realm.setRoleNameCol(roleNameCol);
0275:                realm.setUserCredCol(userCredCol);
0276:                realm.setUserNameCol(userNameCol);
0277:                realm.setUserRoleTable(userRoleTable);
0278:                realm.setUserTable(userTable);
0279:
0280:                // Add the new instance to its parent component
0281:                ObjectName pname = new ObjectName(parent);
0282:                ContainerBase containerBase = getParentContainerFromParent(pname);
0283:                // Add the new instance to its parent component
0284:                containerBase.setRealm(realm);
0285:                // Return the corresponding MBean name
0286:                ObjectName oname = realm.getObjectName();
0287:                if (oname != null) {
0288:                    return (oname.toString());
0289:                } else {
0290:                    return null;
0291:                }
0292:
0293:            }
0294:
0295:            /**
0296:             * Create a new HttpConnector
0297:             *
0298:             * @param parent MBean Name of the associated parent component
0299:             * @param address The IP address on which to bind
0300:             * @param port TCP port number to listen on
0301:             *
0302:             * @exception Exception if an MBean cannot be created or registered
0303:             */
0304:            public String createHttpConnector(String parent, String address,
0305:                    int port) throws Exception {
0306:                return createConnector(parent, address, port, false, false);
0307:            }
0308:
0309:            /**
0310:             * Create a new Connector
0311:             *
0312:             * @param parent MBean Name of the associated parent component
0313:             * @param address The IP address on which to bind
0314:             * @param port TCP port number to listen on
0315:             * @param isAjp Create a AJP/1.3 Connector
0316:             * @param isSSL Create a secure Connector
0317:             *
0318:             * @exception Exception if an MBean cannot be created or registered
0319:             */
0320:            private String createConnector(String parent, String address,
0321:                    int port, boolean isAjp, boolean isSSL) throws Exception {
0322:                Connector retobj = new Connector();
0323:                if ((address != null) && (address.length() > 0)) {
0324:                    retobj.setProperty("address", address);
0325:                }
0326:                // Set port number
0327:                retobj.setPort(port);
0328:                // Set the protocol
0329:                retobj.setProtocol(isAjp ? "AJP/1.3" : "HTTP/1.1");
0330:                // Set SSL
0331:                retobj.setSecure(isSSL);
0332:                retobj.setScheme(isSSL ? "https" : "http");
0333:                // Add the new instance to its parent component
0334:                // FIX ME - addConnector will fail
0335:                ObjectName pname = new ObjectName(parent);
0336:                Service service = getService(pname);
0337:                service.addConnector(retobj);
0338:
0339:                // Return the corresponding MBean name
0340:                ObjectName coname = retobj.getObjectName();
0341:
0342:                return (coname.toString());
0343:            }
0344:
0345:            /**
0346:             * Create a new HttpsConnector
0347:             *
0348:             * @param parent MBean Name of the associated parent component
0349:             * @param address The IP address on which to bind
0350:             * @param port TCP port number to listen on
0351:             *
0352:             * @exception Exception if an MBean cannot be created or registered
0353:             */
0354:            public String createHttpsConnector(String parent, String address,
0355:                    int port) throws Exception {
0356:                return createConnector(parent, address, port, false, true);
0357:            }
0358:
0359:            /**
0360:             * Create a new JDBC Realm.
0361:             *
0362:             * @param parent MBean Name of the associated parent component
0363:             *
0364:             * @exception Exception if an MBean cannot be created or registered
0365:             */
0366:            public String createJDBCRealm(String parent, String driverName,
0367:                    String connectionName, String connectionPassword,
0368:                    String connectionURL) throws Exception {
0369:
0370:                // Create a new JDBCRealm instance
0371:                JDBCRealm realm = new JDBCRealm();
0372:                realm.setDriverName(driverName);
0373:                realm.setConnectionName(connectionName);
0374:                realm.setConnectionPassword(connectionPassword);
0375:                realm.setConnectionURL(connectionURL);
0376:
0377:                // Add the new instance to its parent component
0378:                ObjectName pname = new ObjectName(parent);
0379:                ContainerBase containerBase = getParentContainerFromParent(pname);
0380:                // Add the new instance to its parent component
0381:                containerBase.setRealm(realm);
0382:                // Return the corresponding MBean name
0383:                ObjectName oname = realm.getObjectName();
0384:
0385:                if (oname != null) {
0386:                    return (oname.toString());
0387:                } else {
0388:                    return null;
0389:                }
0390:
0391:            }
0392:
0393:            /**
0394:             * Create a new JNDI Realm.
0395:             *
0396:             * @param parent MBean Name of the associated parent component
0397:             *
0398:             * @exception Exception if an MBean cannot be created or registered
0399:             */
0400:            public String createJNDIRealm(String parent) throws Exception {
0401:
0402:                // Create a new JNDIRealm instance
0403:                JNDIRealm realm = new JNDIRealm();
0404:
0405:                // Add the new instance to its parent component
0406:                ObjectName pname = new ObjectName(parent);
0407:                ContainerBase containerBase = getParentContainerFromParent(pname);
0408:                // Add the new instance to its parent component
0409:                containerBase.setRealm(realm);
0410:                // Return the corresponding MBean name
0411:                ObjectName oname = realm.getObjectName();
0412:
0413:                if (oname != null) {
0414:                    return (oname.toString());
0415:                } else {
0416:                    return null;
0417:                }
0418:
0419:            }
0420:
0421:            /**
0422:             * Create a new Memory Realm.
0423:             *
0424:             * @param parent MBean Name of the associated parent component
0425:             *
0426:             * @exception Exception if an MBean cannot be created or registered
0427:             */
0428:            public String createMemoryRealm(String parent) throws Exception {
0429:
0430:                // Create a new MemoryRealm instance
0431:                MemoryRealm realm = new MemoryRealm();
0432:
0433:                // Add the new instance to its parent component
0434:                ObjectName pname = new ObjectName(parent);
0435:                ContainerBase containerBase = getParentContainerFromParent(pname);
0436:                // Add the new instance to its parent component
0437:                containerBase.setRealm(realm);
0438:                // Return the corresponding MBean name
0439:                ObjectName oname = realm.getObjectName();
0440:                if (oname != null) {
0441:                    return (oname.toString());
0442:                } else {
0443:                    return null;
0444:                }
0445:
0446:            }
0447:
0448:            /**
0449:             * Create a new Remote Address Filter Valve.
0450:             *
0451:             * @param parent MBean Name of the associated parent component
0452:             *
0453:             * @exception Exception if an MBean cannot be created or registered
0454:             */
0455:            public String createRemoteAddrValve(String parent) throws Exception {
0456:
0457:                // Create a new RemoteAddrValve instance
0458:                RemoteAddrValve valve = new RemoteAddrValve();
0459:
0460:                // Add the new instance to its parent component
0461:                ObjectName pname = new ObjectName(parent);
0462:                ContainerBase containerBase = getParentContainerFromParent(pname);
0463:                containerBase.addValve(valve);
0464:                ObjectName oname = valve.getObjectName();
0465:                return (oname.toString());
0466:
0467:            }
0468:
0469:            /**
0470:             * Create a new Remote Host Filter Valve.
0471:             *
0472:             * @param parent MBean Name of the associated parent component
0473:             *
0474:             * @exception Exception if an MBean cannot be created or registered
0475:             */
0476:            public String createRemoteHostValve(String parent) throws Exception {
0477:
0478:                // Create a new RemoteHostValve instance
0479:                RemoteHostValve valve = new RemoteHostValve();
0480:
0481:                // Add the new instance to its parent component
0482:                ObjectName pname = new ObjectName(parent);
0483:                ContainerBase containerBase = getParentContainerFromParent(pname);
0484:                containerBase.addValve(valve);
0485:                ObjectName oname = valve.getObjectName();
0486:                return (oname.toString());
0487:
0488:            }
0489:
0490:            /**
0491:             * Create a new Request Dumper Valve.
0492:             *
0493:             * @param parent MBean Name of the associated parent component
0494:             *
0495:             * @exception Exception if an MBean cannot be created or registered
0496:             */
0497:            public String createRequestDumperValve(String parent)
0498:                    throws Exception {
0499:
0500:                // Create a new RequestDumperValve instance
0501:                RequestDumperValve valve = new RequestDumperValve();
0502:
0503:                // Add the new instance to its parent component
0504:                ObjectName pname = new ObjectName(parent);
0505:                ContainerBase containerBase = getParentContainerFromParent(pname);
0506:                containerBase.addValve(valve);
0507:                ObjectName oname = valve.getObjectName();
0508:                return (oname.toString());
0509:
0510:            }
0511:
0512:            /**
0513:             * Create a new Single Sign On Valve.
0514:             *
0515:             * @param parent MBean Name of the associated parent component
0516:             *
0517:             * @exception Exception if an MBean cannot be created or registered
0518:             */
0519:            public String createSingleSignOn(String parent) throws Exception {
0520:
0521:                // Create a new SingleSignOn instance
0522:                SingleSignOn valve = new SingleSignOn();
0523:
0524:                // Add the new instance to its parent component
0525:                ObjectName pname = new ObjectName(parent);
0526:                ContainerBase containerBase = getParentContainerFromParent(pname);
0527:                containerBase.addValve(valve);
0528:                ObjectName oname = valve.getObjectName();
0529:                return (oname.toString());
0530:
0531:            }
0532:
0533:            /**
0534:             * Create a new StandardContext.
0535:             *
0536:             * @param parent MBean Name of the associated parent component
0537:             * @param path The context path for this Context
0538:             * @param docBase Document base directory (or WAR) for this Context
0539:             *
0540:             * @exception Exception if an MBean cannot be created or registered
0541:             */
0542:            public String createStandardContext(String parent, String path,
0543:                    String docBase) throws Exception {
0544:
0545:                // XXX for backward compatibility. Remove it once supported by the admin
0546:                return createStandardContext(parent, path, docBase, false,
0547:                        false, false, false);
0548:            }
0549:
0550:            /**
0551:             * Given a context path, get the config file name.
0552:             */
0553:            private String getConfigFile(String path) {
0554:                String basename = null;
0555:                if (path.equals("")) {
0556:                    basename = "ROOT";
0557:                } else {
0558:                    basename = path.substring(1).replace('/', '#');
0559:                }
0560:                return (basename);
0561:            }
0562:
0563:            /**
0564:             * Create a new StandardContext.
0565:             *
0566:             * @param parent MBean Name of the associated parent component
0567:             * @param path The context path for this Context
0568:             * @param docBase Document base directory (or WAR) for this Context
0569:             *
0570:             * @exception Exception if an MBean cannot be created or registered
0571:             */
0572:            public String createStandardContext(String parent, String path,
0573:                    String docBase, boolean xmlValidation,
0574:                    boolean xmlNamespaceAware, boolean tldValidation,
0575:                    boolean tldNamespaceAware) throws Exception {
0576:
0577:                // Create a new StandardContext instance
0578:                StandardContext context = new StandardContext();
0579:                path = getPathStr(path);
0580:                context.setPath(path);
0581:                context.setDocBase(docBase);
0582:                context.setXmlValidation(xmlValidation);
0583:                context.setXmlNamespaceAware(xmlNamespaceAware);
0584:                context.setTldValidation(tldValidation);
0585:                context.setTldNamespaceAware(tldNamespaceAware);
0586:
0587:                ContextConfig contextConfig = new ContextConfig();
0588:                context.addLifecycleListener(contextConfig);
0589:
0590:                // Add the new instance to its parent component
0591:                ObjectName pname = new ObjectName(parent);
0592:                ObjectName deployer = new ObjectName(pname.getDomain()
0593:                        + ":type=Deployer,host=" + pname.getKeyProperty("host"));
0594:                if (mserver.isRegistered(deployer)) {
0595:                    String contextPath = context.getPath();
0596:                    mserver.invoke(deployer, "addServiced",
0597:                            new Object[] { contextPath },
0598:                            new String[] { "java.lang.String" });
0599:                    String configPath = (String) mserver.getAttribute(deployer,
0600:                            "configBaseName");
0601:                    String baseName = getConfigFile(contextPath);
0602:                    File configFile = new File(new File(configPath), baseName
0603:                            + ".xml");
0604:                    context.setConfigFile(configFile.getAbsolutePath());
0605:                    mserver.invoke(deployer, "manageApp",
0606:                            new Object[] { context },
0607:                            new String[] { "org.apache.catalina.Context" });
0608:                    mserver.invoke(deployer, "removeServiced",
0609:                            new Object[] { contextPath },
0610:                            new String[] { "java.lang.String" });
0611:                } else {
0612:                    log.warn("Deployer not found for "
0613:                            + pname.getKeyProperty("host"));
0614:                    Service service = getService(pname);
0615:                    Engine engine = (Engine) service.getContainer();
0616:                    Host host = (Host) engine.findChild(pname
0617:                            .getKeyProperty("host"));
0618:                    host.addChild(context);
0619:                }
0620:
0621:                // Return the corresponding MBean name
0622:                ObjectName oname = context.getJmxName();
0623:
0624:                return (oname.toString());
0625:
0626:            }
0627:
0628:            /**
0629:             * Create a new StandardEngine.
0630:             *
0631:             * @param parent MBean Name of the associated parent component
0632:             * @param engineName Unique name of this Engine
0633:             * @param defaultHost Default hostname of this Engine
0634:             * @param serviceName Unique name of this Service
0635:             *
0636:             * @exception Exception if an MBean cannot be created or registered
0637:             */
0638:
0639:            public Vector createStandardEngineService(String parent,
0640:                    String engineName, String defaultHost, String serviceName)
0641:                    throws Exception {
0642:
0643:                // Create a new StandardService instance
0644:                StandardService service = new StandardService();
0645:                service.setName(serviceName);
0646:                // Create a new StandardEngine instance
0647:                StandardEngine engine = new StandardEngine();
0648:                engine.setName(engineName);
0649:                engine.setDefaultHost(defaultHost);
0650:                // Need to set engine before adding it to server in order to set domain
0651:                service.setContainer(engine);
0652:                // Add the new instance to its parent component
0653:                Server server = ServerFactory.getServer();
0654:                server.addService(service);
0655:                Vector onames = new Vector();
0656:                // FIXME service & engine.getObjectName
0657:                //ObjectName oname = engine.getObjectName();
0658:                ObjectName oname = MBeanUtils.createObjectName(engineName,
0659:                        engine);
0660:                onames.add(0, oname);
0661:                //oname = service.getObjectName();
0662:                oname = MBeanUtils.createObjectName(engineName, service);
0663:                onames.add(1, oname);
0664:                return (onames);
0665:
0666:            }
0667:
0668:            /**
0669:             * Create a new StandardHost.
0670:             *
0671:             * @param parent MBean Name of the associated parent component
0672:             * @param name Unique name of this Host
0673:             * @param appBase Application base directory name
0674:             * @param autoDeploy Should we auto deploy?
0675:             * @param deployOnStartup Deploy on server startup?
0676:             * @param deployXML Should we deploy Context XML config files property?
0677:             * @param unpackWARs Should we unpack WARs when auto deploying?
0678:             * @param xmlNamespaceAware Should we turn on/off XML namespace awareness?
0679:             * @param xmlValidation Should we turn on/off XML validation?        
0680:             *
0681:             * @exception Exception if an MBean cannot be created or registered
0682:             */
0683:            public String createStandardHost(String parent, String name,
0684:                    String appBase, boolean autoDeploy,
0685:                    boolean deployOnStartup, boolean deployXML,
0686:                    boolean unpackWARs, boolean xmlNamespaceAware,
0687:                    boolean xmlValidation) throws Exception {
0688:
0689:                // Create a new StandardHost instance
0690:                StandardHost host = new StandardHost();
0691:                host.setName(name);
0692:                host.setAppBase(appBase);
0693:                host.setAutoDeploy(autoDeploy);
0694:                host.setDeployOnStartup(deployOnStartup);
0695:                host.setDeployXML(deployXML);
0696:                host.setUnpackWARs(unpackWARs);
0697:                host.setXmlNamespaceAware(xmlNamespaceAware);
0698:                host.setXmlValidation(xmlValidation);
0699:
0700:                // add HostConfig for active reloading
0701:                HostConfig hostConfig = new HostConfig();
0702:                host.addLifecycleListener(hostConfig);
0703:
0704:                // Add the new instance to its parent component
0705:                ObjectName pname = new ObjectName(parent);
0706:                Service service = getService(pname);
0707:                Engine engine = (Engine) service.getContainer();
0708:                engine.addChild(host);
0709:
0710:                // Return the corresponding MBean name
0711:                return (host.getObjectName().toString());
0712:
0713:            }
0714:
0715:            /**
0716:             * Create a new StandardManager.
0717:             *
0718:             * @param parent MBean Name of the associated parent component
0719:             *
0720:             * @exception Exception if an MBean cannot be created or registered
0721:             */
0722:            public String createStandardManager(String parent) throws Exception {
0723:
0724:                // Create a new StandardManager instance
0725:                StandardManager manager = new StandardManager();
0726:
0727:                // Add the new instance to its parent component
0728:                ObjectName pname = new ObjectName(parent);
0729:                ContainerBase containerBase = getParentContainerFromParent(pname);
0730:                if (containerBase != null) {
0731:                    containerBase.setManager(manager);
0732:                }
0733:                ObjectName oname = manager.getObjectName();
0734:                if (oname != null) {
0735:                    return (oname.toString());
0736:                } else {
0737:                    return null;
0738:                }
0739:
0740:            }
0741:
0742:            /**
0743:             * Create a new StandardService.
0744:             *
0745:             * @param parent MBean Name of the associated parent component
0746:             * @param name Unique name of this StandardService
0747:             *
0748:             * @exception Exception if an MBean cannot be created or registered
0749:             */
0750:            public String createStandardService(String parent, String name,
0751:                    String domain) throws Exception {
0752:
0753:                // Create a new StandardService instance
0754:                StandardService service = new StandardService();
0755:                service.setName(name);
0756:
0757:                // Add the new instance to its parent component
0758:                Server server = ServerFactory.getServer();
0759:                server.addService(service);
0760:
0761:                // Return the corresponding MBean name
0762:                return (service.getObjectName().toString());
0763:
0764:            }
0765:
0766:            /**
0767:             * Create a new  UserDatabaseRealm.
0768:             *
0769:             * @param parent MBean Name of the associated parent component
0770:             * @param resourceName Global JNDI resource name of the associated
0771:             *  UserDatabase
0772:             *
0773:             * @exception Exception if an MBean cannot be created or registered
0774:             */
0775:            public String createUserDatabaseRealm(String parent,
0776:                    String resourceName) throws Exception {
0777:
0778:                // Create a new UserDatabaseRealm instance
0779:                UserDatabaseRealm realm = new UserDatabaseRealm();
0780:                realm.setResourceName(resourceName);
0781:
0782:                // Add the new instance to its parent component
0783:                ObjectName pname = new ObjectName(parent);
0784:                ContainerBase containerBase = getParentContainerFromParent(pname);
0785:                // Add the new instance to its parent component
0786:                containerBase.setRealm(realm);
0787:                // Return the corresponding MBean name
0788:                ObjectName oname = realm.getObjectName();
0789:                // FIXME getObjectName() returns null
0790:                //ObjectName oname = 
0791:                //    MBeanUtils.createObjectName(pname.getDomain(), realm);
0792:                if (oname != null) {
0793:                    return (oname.toString());
0794:                } else {
0795:                    return null;
0796:                }
0797:
0798:            }
0799:
0800:            /**
0801:             * Create a new Web Application Loader.
0802:             *
0803:             * @param parent MBean Name of the associated parent component
0804:             *
0805:             * @exception Exception if an MBean cannot be created or registered
0806:             */
0807:            public String createWebappLoader(String parent) throws Exception {
0808:
0809:                // Create a new WebappLoader instance
0810:                WebappLoader loader = new WebappLoader();
0811:
0812:                // Add the new instance to its parent component
0813:                ObjectName pname = new ObjectName(parent);
0814:                ContainerBase containerBase = getParentContainerFromParent(pname);
0815:                if (containerBase != null) {
0816:                    containerBase.setLoader(loader);
0817:                }
0818:                // FIXME add Loader.getObjectName
0819:                //ObjectName oname = loader.getObjectName();
0820:                ObjectName oname = MBeanUtils.createObjectName(pname
0821:                        .getDomain(), loader);
0822:                return (oname.toString());
0823:
0824:            }
0825:
0826:            /**
0827:             * Remove an existing Connector.
0828:             *
0829:             * @param name MBean Name of the component to remove
0830:             *
0831:             * @exception Exception if a component cannot be removed
0832:             */
0833:            public void removeConnector(String name) throws Exception {
0834:
0835:                // Acquire a reference to the component to be removed
0836:                ObjectName oname = new ObjectName(name);
0837:                Server server = ServerFactory.getServer();
0838:                Service service = getService(oname);
0839:                String port = oname.getKeyProperty("port");
0840:                //String address = oname.getKeyProperty("address");
0841:
0842:                Connector conns[] = (Connector[]) service.findConnectors();
0843:
0844:                for (int i = 0; i < conns.length; i++) {
0845:                    String connAddress = String.valueOf(conns[i]
0846:                            .getProperty("address"));
0847:                    String connPort = "" + conns[i].getPort();
0848:
0849:                    // if (((address.equals("null")) &&
0850:                    if ((connAddress == null) && port.equals(connPort)) {
0851:                        service.removeConnector(conns[i]);
0852:                        conns[i].destroy();
0853:                        break;
0854:                    }
0855:                    // } else if (address.equals(connAddress))
0856:                    if (port.equals(connPort)) {
0857:                        // Remove this component from its parent component
0858:                        service.removeConnector(conns[i]);
0859:                        conns[i].destroy();
0860:                        break;
0861:                    }
0862:                }
0863:
0864:            }
0865:
0866:            /**
0867:             * Remove an existing Context.
0868:             *
0869:             * @param contextName MBean Name of the comonent to remove
0870:             *
0871:             * @exception Exception if a component cannot be removed
0872:             */
0873:            public void removeContext(String contextName) throws Exception {
0874:
0875:                // Acquire a reference to the component to be removed
0876:                ObjectName oname = new ObjectName(contextName);
0877:                String domain = oname.getDomain();
0878:                StandardService service = (StandardService) getService(oname);
0879:
0880:                Engine engine = (Engine) service.getContainer();
0881:                String name = oname.getKeyProperty("name");
0882:                name = name.substring(2);
0883:                int i = name.indexOf("/");
0884:                String hostName = name.substring(0, i);
0885:                String path = name.substring(i);
0886:                ObjectName deployer = new ObjectName(domain
0887:                        + ":type=Deployer,host=" + hostName);
0888:                String pathStr = getPathStr(path);
0889:                if (mserver.isRegistered(deployer)) {
0890:                    mserver.invoke(deployer, "addServiced",
0891:                            new Object[] { pathStr },
0892:                            new String[] { "java.lang.String" });
0893:                    mserver.invoke(deployer, "unmanageApp",
0894:                            new Object[] { pathStr },
0895:                            new String[] { "java.lang.String" });
0896:                    mserver.invoke(deployer, "removeServiced",
0897:                            new Object[] { pathStr },
0898:                            new String[] { "java.lang.String" });
0899:                } else {
0900:                    log.warn("Deployer not found for " + hostName);
0901:                    Host host = (Host) engine.findChild(hostName);
0902:                    Context context = (Context) host.findChild(pathStr);
0903:                    // Remove this component from its parent component
0904:                    host.removeChild(context);
0905:                    if (context instanceof  StandardContext)
0906:                        try {
0907:                            ((StandardContext) context).destroy();
0908:                        } catch (Exception e) {
0909:                            log.warn("Error during context ["
0910:                                    + context.getName() + "] destroy ", e);
0911:                        }
0912:
0913:                }
0914:
0915:            }
0916:
0917:            /**
0918:             * Remove an existing Host.
0919:             *
0920:             * @param name MBean Name of the comonent to remove
0921:             *
0922:             * @exception Exception if a component cannot be removed
0923:             */
0924:            public void removeHost(String name) throws Exception {
0925:
0926:                // Acquire a reference to the component to be removed
0927:                ObjectName oname = new ObjectName(name);
0928:                String hostName = oname.getKeyProperty("host");
0929:                Service service = getService(oname);
0930:                Engine engine = (Engine) service.getContainer();
0931:                Host host = (Host) engine.findChild(hostName);
0932:
0933:                // Remove this component from its parent component
0934:                if (host != null) {
0935:                    if (host instanceof  StandardHost)
0936:                        ((StandardHost) host).destroy();
0937:                    else
0938:                        engine.removeChild(host);
0939:                }
0940:
0941:            }
0942:
0943:            /**
0944:             * Remove an existing Loader.
0945:             *
0946:             * @param name MBean Name of the comonent to remove
0947:             *
0948:             * @exception Exception if a component cannot be removed
0949:             */
0950:            public void removeLoader(String name) throws Exception {
0951:
0952:                ObjectName oname = new ObjectName(name);
0953:                // Acquire a reference to the component to be removed
0954:                ContainerBase container = getParentContainerFromChild(oname);
0955:                container.setLoader(null);
0956:
0957:            }
0958:
0959:            /**
0960:             * Remove an existing Manager.
0961:             *
0962:             * @param name MBean Name of the comonent to remove
0963:             *
0964:             * @exception Exception if a component cannot be removed
0965:             */
0966:            public void removeManager(String name) throws Exception {
0967:
0968:                ObjectName oname = new ObjectName(name);
0969:                // Acquire a reference to the component to be removed
0970:                ContainerBase container = getParentContainerFromChild(oname);
0971:                container.setManager(null);
0972:
0973:            }
0974:
0975:            /**
0976:             * Remove an existing Realm.
0977:             *
0978:             * @param name MBean Name of the comonent to remove
0979:             *
0980:             * @exception Exception if a component cannot be removed
0981:             */
0982:            public void removeRealm(String name) throws Exception {
0983:
0984:                ObjectName oname = new ObjectName(name);
0985:                // Acquire a reference to the component to be removed
0986:                ContainerBase container = getParentContainerFromChild(oname);
0987:                container.setRealm(null);
0988:            }
0989:
0990:            /**
0991:             * Remove an existing Service.
0992:             *
0993:             * @param name MBean Name of the component to remove
0994:             *
0995:             * @exception Exception if a component cannot be removed
0996:             */
0997:            public void removeService(String name) throws Exception {
0998:
0999:                // Acquire a reference to the component to be removed
1000:                ObjectName oname = new ObjectName(name);
1001:                String serviceName = oname.getKeyProperty("serviceName");
1002:                Server server = ServerFactory.getServer();
1003:                Service service = server.findService(serviceName);
1004:
1005:                // Remove this component from its parent component
1006:                server.removeService(service);
1007:
1008:            }
1009:
1010:            /**
1011:             * Remove an existing Valve.
1012:             *
1013:             * @param name MBean Name of the comonent to remove
1014:             *
1015:             * @exception Exception if a component cannot be removed
1016:             */
1017:            public void removeValve(String name) throws Exception {
1018:
1019:                // Acquire a reference to the component to be removed
1020:                ObjectName oname = new ObjectName(name);
1021:                ContainerBase container = getParentContainerFromChild(oname);
1022:                String sequence = oname.getKeyProperty("seq");
1023:                Valve[] valves = (Valve[]) container.getValves();
1024:                for (int i = 0; i < valves.length; i++) {
1025:                    ObjectName voname = ((ValveBase) valves[i]).getObjectName();
1026:                    if (voname.equals(oname)) {
1027:                        container.removeValve(valves[i]);
1028:                    }
1029:                }
1030:            }
1031:
1032:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.