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.util.Hashtable;
0021:
0022: import javax.management.DynamicMBean;
0023: import javax.management.MBeanException;
0024: import javax.management.MBeanServer;
0025: import javax.management.MalformedObjectNameException;
0026: import javax.management.ObjectName;
0027:
0028: import org.apache.catalina.Contained;
0029: import org.apache.catalina.Container;
0030: import org.apache.catalina.Context;
0031: import org.apache.catalina.Engine;
0032: import org.apache.catalina.Group;
0033: import org.apache.catalina.Host;
0034: import org.apache.catalina.Loader;
0035: import org.apache.catalina.Manager;
0036: import org.apache.catalina.Realm;
0037: import org.apache.catalina.Role;
0038: import org.apache.catalina.Server;
0039: import org.apache.catalina.Service;
0040: import org.apache.catalina.User;
0041: import org.apache.catalina.UserDatabase;
0042: import org.apache.catalina.Valve;
0043: import org.apache.catalina.connector.Connector;
0044: import org.apache.catalina.deploy.ContextEnvironment;
0045: import org.apache.catalina.deploy.ContextResource;
0046: import org.apache.catalina.deploy.ContextResourceLink;
0047: import org.apache.catalina.deploy.NamingResources;
0048: import org.apache.catalina.valves.ValveBase;
0049: import org.apache.juli.logging.Log;
0050: import org.apache.juli.logging.LogFactory;
0051: import org.apache.tomcat.util.IntrospectionUtils;
0052: import org.apache.tomcat.util.modeler.ManagedBean;
0053: import org.apache.tomcat.util.modeler.Registry;
0054:
0055: /**
0056: * Public utility methods in support of the server side MBeans implementation.
0057: *
0058: * @author Craig R. McClanahan
0059: * @author Amy Roh
0060: * @version $Revision: 500684 $ $Date: 2007-01-28 00:27:18 +0100 (dim., 28 janv. 2007) $
0061: */
0062:
0063: public class MBeanUtils {
0064: private static Log log = LogFactory.getLog(MBeanUtils.class);
0065:
0066: // ------------------------------------------------------- Static Variables
0067:
0068: /**
0069: * The set of exceptions to the normal rules used by
0070: * <code>createManagedBean()</code>. The first element of each pair
0071: * is a class name, and the second element is the managed bean name.
0072: */
0073: private static String exceptions[][] = {
0074: { "org.apache.ajp.tomcat4.Ajp13Connector", "Ajp13Connector" },
0075: { "org.apache.coyote.tomcat4.Ajp13Connector",
0076: "CoyoteConnector" },
0077: { "org.apache.catalina.users.JDBCGroup", "Group" },
0078: { "org.apache.catalina.users.JDBCRole", "Role" },
0079: { "org.apache.catalina.users.JDBCUser", "User" },
0080: { "org.apache.catalina.users.MemoryGroup", "Group" },
0081: { "org.apache.catalina.users.MemoryRole", "Role" },
0082: { "org.apache.catalina.users.MemoryUser", "User" }, };
0083:
0084: /**
0085: * The configuration information registry for our managed beans.
0086: */
0087: private static Registry registry = createRegistry();
0088:
0089: /**
0090: * The <code>MBeanServer</code> for this application.
0091: */
0092: private static MBeanServer mserver = createServer();
0093:
0094: // --------------------------------------------------------- Static Methods
0095:
0096: /**
0097: * Create and return the name of the <code>ManagedBean</code> that
0098: * corresponds to this Catalina component.
0099: *
0100: * @param component The component for which to create a name
0101: */
0102: static String createManagedName(Object component) {
0103:
0104: // Deal with exceptions to the standard rule
0105: String className = component.getClass().getName();
0106: for (int i = 0; i < exceptions.length; i++) {
0107: if (className.equals(exceptions[i][0])) {
0108: return (exceptions[i][1]);
0109: }
0110: }
0111:
0112: // Perform the standard transformation
0113: int period = className.lastIndexOf('.');
0114: if (period >= 0)
0115: className = className.substring(period + 1);
0116: return (className);
0117:
0118: }
0119:
0120: /**
0121: * Create, register, and return an MBean for this
0122: * <code>Connector</code> object.
0123: *
0124: * @param connector The Connector to be managed
0125: *
0126: * @exception Exception if an MBean cannot be created or registered
0127: */
0128: static DynamicMBean createMBean(Connector connector)
0129: throws Exception {
0130:
0131: String mname = createManagedName(connector);
0132: ManagedBean managed = registry.findManagedBean(mname);
0133: if (managed == null) {
0134: Exception e = new Exception(
0135: "ManagedBean is not found with " + mname);
0136: throw new MBeanException(e);
0137: }
0138: String domain = managed.getDomain();
0139: if (domain == null)
0140: domain = mserver.getDefaultDomain();
0141: DynamicMBean mbean = managed.createMBean(connector);
0142: ObjectName oname = createObjectName(domain, connector);
0143: if (mserver.isRegistered(oname)) {
0144: mserver.unregisterMBean(oname);
0145: }
0146: mserver.registerMBean(mbean, oname);
0147: return (mbean);
0148:
0149: }
0150:
0151: /**
0152: * Create, register, and return an MBean for this
0153: * <code>Context</code> object.
0154: *
0155: * @param context The Context to be managed
0156: *
0157: * @exception Exception if an MBean cannot be created or registered
0158: */
0159: static DynamicMBean createMBean(Context context) throws Exception {
0160:
0161: String mname = createManagedName(context);
0162: ManagedBean managed = registry.findManagedBean(mname);
0163: if (managed == null) {
0164: Exception e = new Exception(
0165: "ManagedBean is not found with " + mname);
0166: throw new MBeanException(e);
0167: }
0168: String domain = managed.getDomain();
0169: if (domain == null)
0170: domain = mserver.getDefaultDomain();
0171: DynamicMBean mbean = managed.createMBean(context);
0172: ObjectName oname = createObjectName(domain, context);
0173: if (mserver.isRegistered(oname)) {
0174: log.debug("Already registered " + oname);
0175: mserver.unregisterMBean(oname);
0176: }
0177: mserver.registerMBean(mbean, oname);
0178: return (mbean);
0179:
0180: }
0181:
0182: /**
0183: * Create, register, and return an MBean for this
0184: * <code>ContextEnvironment</code> object.
0185: *
0186: * @param environment The ContextEnvironment to be managed
0187: *
0188: * @exception Exception if an MBean cannot be created or registered
0189: */
0190: static DynamicMBean createMBean(ContextEnvironment environment)
0191: throws Exception {
0192:
0193: String mname = createManagedName(environment);
0194: ManagedBean managed = registry.findManagedBean(mname);
0195: if (managed == null) {
0196: Exception e = new Exception(
0197: "ManagedBean is not found with " + mname);
0198: throw new MBeanException(e);
0199: }
0200: String domain = managed.getDomain();
0201: if (domain == null)
0202: domain = mserver.getDefaultDomain();
0203: DynamicMBean mbean = managed.createMBean(environment);
0204: ObjectName oname = createObjectName(domain, environment);
0205: if (mserver.isRegistered(oname)) {
0206: mserver.unregisterMBean(oname);
0207: }
0208: mserver.registerMBean(mbean, oname);
0209: return (mbean);
0210:
0211: }
0212:
0213: /**
0214: * Create, register, and return an MBean for this
0215: * <code>ContextResource</code> object.
0216: *
0217: * @param resource The ContextResource to be managed
0218: *
0219: * @exception Exception if an MBean cannot be created or registered
0220: */
0221: static DynamicMBean createMBean(ContextResource resource)
0222: throws Exception {
0223:
0224: String mname = createManagedName(resource);
0225: ManagedBean managed = registry.findManagedBean(mname);
0226: if (managed == null) {
0227: Exception e = new Exception(
0228: "ManagedBean is not found with " + mname);
0229: throw new MBeanException(e);
0230: }
0231: String domain = managed.getDomain();
0232: if (domain == null)
0233: domain = mserver.getDefaultDomain();
0234: DynamicMBean mbean = managed.createMBean(resource);
0235: ObjectName oname = createObjectName(domain, resource);
0236: if (mserver.isRegistered(oname)) {
0237: mserver.unregisterMBean(oname);
0238: }
0239: mserver.registerMBean(mbean, oname);
0240: return (mbean);
0241:
0242: }
0243:
0244: /**
0245: * Create, register, and return an MBean for this
0246: * <code>ContextResourceLink</code> object.
0247: *
0248: * @param resourceLink The ContextResourceLink to be managed
0249: *
0250: * @exception Exception if an MBean cannot be created or registered
0251: */
0252: static DynamicMBean createMBean(ContextResourceLink resourceLink)
0253: throws Exception {
0254:
0255: String mname = createManagedName(resourceLink);
0256: ManagedBean managed = registry.findManagedBean(mname);
0257: if (managed == null) {
0258: Exception e = new Exception(
0259: "ManagedBean is not found with " + mname);
0260: throw new MBeanException(e);
0261: }
0262: String domain = managed.getDomain();
0263: if (domain == null)
0264: domain = mserver.getDefaultDomain();
0265: DynamicMBean mbean = managed.createMBean(resourceLink);
0266: ObjectName oname = createObjectName(domain, resourceLink);
0267: if (mserver.isRegistered(oname)) {
0268: mserver.unregisterMBean(oname);
0269: }
0270: mserver.registerMBean(mbean, oname);
0271: return (mbean);
0272:
0273: }
0274:
0275: /**
0276: * Create, register, and return an MBean for this
0277: * <code>Engine</code> object.
0278: *
0279: * @param engine The Engine to be managed
0280: *
0281: * @exception Exception if an MBean cannot be created or registered
0282: */
0283: static DynamicMBean createMBean(Engine engine) throws Exception {
0284:
0285: String mname = createManagedName(engine);
0286: ManagedBean managed = registry.findManagedBean(mname);
0287: if (managed == null) {
0288: Exception e = new Exception(
0289: "ManagedBean is not found with " + mname);
0290: throw new MBeanException(e);
0291: }
0292: String domain = managed.getDomain();
0293: if (domain == null)
0294: domain = mserver.getDefaultDomain();
0295: DynamicMBean mbean = managed.createMBean(engine);
0296: ObjectName oname = createObjectName(domain, engine);
0297: if (mserver.isRegistered(oname)) {
0298: mserver.unregisterMBean(oname);
0299: }
0300: mserver.registerMBean(mbean, oname);
0301: return (mbean);
0302:
0303: }
0304:
0305: /**
0306: * Create, register, and return an MBean for this
0307: * <code>Group</code> object.
0308: *
0309: * @param group The Group to be managed
0310: *
0311: * @exception Exception if an MBean cannot be created or registered
0312: */
0313: static DynamicMBean createMBean(Group group) throws Exception {
0314:
0315: String mname = createManagedName(group);
0316: ManagedBean managed = registry.findManagedBean(mname);
0317: if (managed == null) {
0318: Exception e = new Exception(
0319: "ManagedBean is not found with " + mname);
0320: throw new MBeanException(e);
0321: }
0322: String domain = managed.getDomain();
0323: if (domain == null)
0324: domain = mserver.getDefaultDomain();
0325: DynamicMBean mbean = managed.createMBean(group);
0326: ObjectName oname = createObjectName(domain, group);
0327: if (mserver.isRegistered(oname)) {
0328: mserver.unregisterMBean(oname);
0329: }
0330: mserver.registerMBean(mbean, oname);
0331: return (mbean);
0332:
0333: }
0334:
0335: /**
0336: * Create, register, and return an MBean for this
0337: * <code>Host</code> object.
0338: *
0339: * @param host The Host to be managed
0340: *
0341: * @exception Exception if an MBean cannot be created or registered
0342: */
0343: static DynamicMBean createMBean(Host host) throws Exception {
0344:
0345: String mname = createManagedName(host);
0346: ManagedBean managed = registry.findManagedBean(mname);
0347: if (managed == null) {
0348: Exception e = new Exception(
0349: "ManagedBean is not found with " + mname);
0350: throw new MBeanException(e);
0351: }
0352: String domain = managed.getDomain();
0353: if (domain == null)
0354: domain = mserver.getDefaultDomain();
0355: DynamicMBean mbean = managed.createMBean(host);
0356: ObjectName oname = createObjectName(domain, host);
0357: if (mserver.isRegistered(oname)) {
0358: mserver.unregisterMBean(oname);
0359: }
0360: mserver.registerMBean(mbean, oname);
0361: return (mbean);
0362:
0363: }
0364:
0365: /**
0366: * Create, register, and return an MBean for this
0367: * <code>Loader</code> object.
0368: *
0369: * @param loader The Loader to be managed
0370: *
0371: * @exception Exception if an MBean cannot be created or registered
0372: */
0373: static DynamicMBean createMBean(Loader loader) throws Exception {
0374:
0375: String mname = createManagedName(loader);
0376: ManagedBean managed = registry.findManagedBean(mname);
0377: if (managed == null) {
0378: Exception e = new Exception(
0379: "ManagedBean is not found with " + mname);
0380: throw new MBeanException(e);
0381: }
0382: String domain = managed.getDomain();
0383: if (domain == null)
0384: domain = mserver.getDefaultDomain();
0385: DynamicMBean mbean = managed.createMBean(loader);
0386: ObjectName oname = createObjectName(domain, loader);
0387: if (mserver.isRegistered(oname)) {
0388: // side effect: stop it
0389: mserver.unregisterMBean(oname);
0390: }
0391: mserver.registerMBean(mbean, oname);
0392: return (mbean);
0393:
0394: }
0395:
0396: /**
0397: * Create, register, and return an MBean for this
0398: * <code>Manager</code> object.
0399: *
0400: * @param manager The Manager to be managed
0401: *
0402: * @exception Exception if an MBean cannot be created or registered
0403: */
0404: static DynamicMBean createMBean(Manager manager) throws Exception {
0405:
0406: String mname = createManagedName(manager);
0407: ManagedBean managed = registry.findManagedBean(mname);
0408: if (managed == null) {
0409: Exception e = new Exception(
0410: "ManagedBean is not found with " + mname);
0411: throw new MBeanException(e);
0412: }
0413: String domain = managed.getDomain();
0414: if (domain == null)
0415: domain = mserver.getDefaultDomain();
0416: DynamicMBean mbean = managed.createMBean(manager);
0417: ObjectName oname = createObjectName(domain, manager);
0418: if (mserver.isRegistered(oname)) {
0419: mserver.unregisterMBean(oname);
0420: }
0421: mserver.registerMBean(mbean, oname);
0422: return (mbean);
0423:
0424: }
0425:
0426: /**
0427: * Create, register, and return an MBean for this
0428: * <code>MBeanFactory</code> object.
0429: *
0430: * @param factory The MBeanFactory to be managed
0431: *
0432: * @exception Exception if an MBean cannot be created or registered
0433: */
0434: static DynamicMBean createMBean(MBeanFactory factory)
0435: throws Exception {
0436:
0437: String mname = createManagedName(factory);
0438: ManagedBean managed = registry.findManagedBean(mname);
0439: if (managed == null) {
0440: Exception e = new Exception(
0441: "ManagedBean is not found with " + mname);
0442: throw new MBeanException(e);
0443: }
0444: String domain = managed.getDomain();
0445: if (domain == null)
0446: domain = mserver.getDefaultDomain();
0447: DynamicMBean mbean = managed.createMBean(factory);
0448: ObjectName oname = createObjectName(domain, factory);
0449: if (mserver.isRegistered(oname)) {
0450: mserver.unregisterMBean(oname);
0451: }
0452: mserver.registerMBean(mbean, oname);
0453: return (mbean);
0454:
0455: }
0456:
0457: /**
0458: * Create, register, and return an MBean for this
0459: * <code>NamingResources</code> object.
0460: *
0461: * @param resource The NamingResources to be managed
0462: *
0463: * @exception Exception if an MBean cannot be created or registered
0464: */
0465: static DynamicMBean createMBean(NamingResources resource)
0466: throws Exception {
0467:
0468: String mname = createManagedName(resource);
0469: ManagedBean managed = registry.findManagedBean(mname);
0470: if (managed == null) {
0471: Exception e = new Exception(
0472: "ManagedBean is not found with " + mname);
0473: throw new MBeanException(e);
0474: }
0475: String domain = managed.getDomain();
0476: if (domain == null)
0477: domain = mserver.getDefaultDomain();
0478: DynamicMBean mbean = managed.createMBean(resource);
0479: ObjectName oname = createObjectName(domain, resource);
0480: if (mserver.isRegistered(oname)) {
0481: mserver.unregisterMBean(oname);
0482: }
0483: mserver.registerMBean(mbean, oname);
0484: return (mbean);
0485:
0486: }
0487:
0488: /**
0489: * Create, register, and return an MBean for this
0490: * <code>Realm</code> object.
0491: *
0492: * @param realm The Realm to be managed
0493: *
0494: * @exception Exception if an MBean cannot be created or registered
0495: */
0496: static DynamicMBean createMBean(Realm realm) throws Exception {
0497:
0498: String mname = createManagedName(realm);
0499: ManagedBean managed = registry.findManagedBean(mname);
0500: if (managed == null) {
0501: Exception e = new Exception(
0502: "ManagedBean is not found with " + mname);
0503: throw new MBeanException(e);
0504: }
0505: String domain = managed.getDomain();
0506: if (domain == null)
0507: domain = mserver.getDefaultDomain();
0508: DynamicMBean mbean = managed.createMBean(realm);
0509: ObjectName oname = createObjectName(domain, realm);
0510: if (mserver.isRegistered(oname)) {
0511: mserver.unregisterMBean(oname);
0512: }
0513: mserver.registerMBean(mbean, oname);
0514: return (mbean);
0515:
0516: }
0517:
0518: /**
0519: * Create, register, and return an MBean for this
0520: * <code>Role</code> object.
0521: *
0522: * @param role The Role to be managed
0523: *
0524: * @exception Exception if an MBean cannot be created or registered
0525: */
0526: static DynamicMBean createMBean(Role role) throws Exception {
0527:
0528: String mname = createManagedName(role);
0529: ManagedBean managed = registry.findManagedBean(mname);
0530: if (managed == null) {
0531: Exception e = new Exception(
0532: "ManagedBean is not found with " + mname);
0533: throw new MBeanException(e);
0534: }
0535: String domain = managed.getDomain();
0536: if (domain == null)
0537: domain = mserver.getDefaultDomain();
0538: DynamicMBean mbean = managed.createMBean(role);
0539: ObjectName oname = createObjectName(domain, role);
0540: if (mserver.isRegistered(oname)) {
0541: mserver.unregisterMBean(oname);
0542: }
0543: mserver.registerMBean(mbean, oname);
0544: return (mbean);
0545:
0546: }
0547:
0548: /**
0549: * Create, register, and return an MBean for this
0550: * <code>Server</code> object.
0551: *
0552: * @param server The Server to be managed
0553: *
0554: * @exception Exception if an MBean cannot be created or registered
0555: */
0556: static DynamicMBean createMBean(Server server) throws Exception {
0557:
0558: String mname = createManagedName(server);
0559: ManagedBean managed = registry.findManagedBean(mname);
0560: if (managed == null) {
0561: Exception e = new Exception(
0562: "ManagedBean is not found with " + mname);
0563: throw new MBeanException(e);
0564: }
0565: String domain = managed.getDomain();
0566: if (domain == null)
0567: domain = mserver.getDefaultDomain();
0568: DynamicMBean mbean = managed.createMBean(server);
0569: ObjectName oname = createObjectName(domain, server);
0570: if (mserver.isRegistered(oname)) {
0571: mserver.unregisterMBean(oname);
0572: }
0573: mserver.registerMBean(mbean, oname);
0574: return (mbean);
0575:
0576: }
0577:
0578: /**
0579: * Create, register, and return an MBean for this
0580: * <code>Service</code> object.
0581: *
0582: * @param service The Service to be managed
0583: *
0584: * @exception Exception if an MBean cannot be created or registered
0585: */
0586: static DynamicMBean createMBean(Service service) throws Exception {
0587:
0588: String mname = createManagedName(service);
0589: ManagedBean managed = registry.findManagedBean(mname);
0590: if (managed == null) {
0591: Exception e = new Exception(
0592: "ManagedBean is not found with " + mname);
0593: throw new MBeanException(e);
0594: }
0595: String domain = managed.getDomain();
0596: if (domain == null)
0597: domain = mserver.getDefaultDomain();
0598: DynamicMBean mbean = managed.createMBean(service);
0599: ObjectName oname = createObjectName(domain, service);
0600: if (mserver.isRegistered(oname)) {
0601: mserver.unregisterMBean(oname);
0602: }
0603: mserver.registerMBean(mbean, oname);
0604: return (mbean);
0605:
0606: }
0607:
0608: /**
0609: * Create, register, and return an MBean for this
0610: * <code>User</code> object.
0611: *
0612: * @param user The User to be managed
0613: *
0614: * @exception Exception if an MBean cannot be created or registered
0615: */
0616: static DynamicMBean createMBean(User user) throws Exception {
0617:
0618: String mname = createManagedName(user);
0619: ManagedBean managed = registry.findManagedBean(mname);
0620: if (managed == null) {
0621: Exception e = new Exception(
0622: "ManagedBean is not found with " + mname);
0623: throw new MBeanException(e);
0624: }
0625: String domain = managed.getDomain();
0626: if (domain == null)
0627: domain = mserver.getDefaultDomain();
0628: DynamicMBean mbean = managed.createMBean(user);
0629: ObjectName oname = createObjectName(domain, user);
0630: if (mserver.isRegistered(oname)) {
0631: mserver.unregisterMBean(oname);
0632: }
0633: mserver.registerMBean(mbean, oname);
0634: return (mbean);
0635:
0636: }
0637:
0638: /**
0639: * Create, register, and return an MBean for this
0640: * <code>UserDatabase</code> object.
0641: *
0642: * @param userDatabase The UserDatabase to be managed
0643: *
0644: * @exception Exception if an MBean cannot be created or registered
0645: */
0646: static DynamicMBean createMBean(UserDatabase userDatabase)
0647: throws Exception {
0648:
0649: String mname = createManagedName(userDatabase);
0650: ManagedBean managed = registry.findManagedBean(mname);
0651: if (managed == null) {
0652: Exception e = new Exception(
0653: "ManagedBean is not found with " + mname);
0654: throw new MBeanException(e);
0655: }
0656: String domain = managed.getDomain();
0657: if (domain == null)
0658: domain = mserver.getDefaultDomain();
0659: DynamicMBean mbean = managed.createMBean(userDatabase);
0660: ObjectName oname = createObjectName(domain, userDatabase);
0661: if (mserver.isRegistered(oname)) {
0662: mserver.unregisterMBean(oname);
0663: }
0664: mserver.registerMBean(mbean, oname);
0665: return (mbean);
0666:
0667: }
0668:
0669: /**
0670: * Create, register, and return an MBean for this
0671: * <code>Valve</code> object.
0672: *
0673: * @param valve The Valve to be managed
0674: *
0675: * @exception Exception if an MBean cannot be created or registered
0676: */
0677: static DynamicMBean createMBean(Valve valve) throws Exception {
0678:
0679: String mname = createManagedName(valve);
0680: ManagedBean managed = registry.findManagedBean(mname);
0681: if (managed == null) {
0682: Exception e = new Exception(
0683: "ManagedBean is not found with " + mname);
0684: throw new MBeanException(e);
0685: }
0686: String domain = managed.getDomain();
0687: if (domain == null)
0688: domain = mserver.getDefaultDomain();
0689: DynamicMBean mbean = managed.createMBean(valve);
0690: ObjectName oname = createObjectName(domain, valve);
0691: if (mserver.isRegistered(oname)) {
0692: mserver.unregisterMBean(oname);
0693: }
0694: mserver.registerMBean(mbean, oname);
0695: return (mbean);
0696:
0697: }
0698:
0699: /**
0700: * Create an <code>ObjectName</code> for this
0701: * <code>Connector</code> object.
0702: *
0703: * @param domain Domain in which this name is to be created
0704: * @param connector The Connector to be named
0705: *
0706: * @exception MalformedObjectNameException if a name cannot be created
0707: */
0708: static ObjectName createObjectName(String domain,
0709: Connector connector) throws MalformedObjectNameException {
0710:
0711: ObjectName name = null;
0712: if (connector.getClass().getName().indexOf("CoyoteConnector") >= 0) {
0713: try {
0714: String address = (String) IntrospectionUtils
0715: .getProperty(connector, "address");
0716: Integer port = (Integer) IntrospectionUtils
0717: .getProperty(connector, "port");
0718: Service service = connector.getService();
0719: String serviceName = null;
0720: if (service != null)
0721: serviceName = service.getName();
0722: StringBuffer sb = new StringBuffer(domain);
0723: sb.append(":type=Connector");
0724: sb.append(",port=" + port);
0725: if ((address != null) && (address.length() > 0)) {
0726: sb.append(",address=" + address);
0727: }
0728: name = new ObjectName(sb.toString());
0729: return (name);
0730: } catch (Exception e) {
0731: throw new MalformedObjectNameException(
0732: "Cannot create object name for " + connector
0733: + e);
0734: }
0735: } else {
0736: throw new MalformedObjectNameException(
0737: "Cannot create object name for " + connector);
0738: }
0739:
0740: }
0741:
0742: /**
0743: * Create an <code>ObjectName</code> for this
0744: * <code>Context</code> object.
0745: *
0746: * @param domain Domain in which this name is to be created
0747: * @param context The Context to be named
0748: *
0749: * @exception MalformedObjectNameException if a name cannot be created
0750: */
0751: static ObjectName createObjectName(String domain, Context context)
0752: throws MalformedObjectNameException {
0753:
0754: ObjectName name = null;
0755: Host host = (Host) context.getParent();
0756: Service service = ((Engine) host.getParent()).getService();
0757: String path = context.getPath();
0758: if (path.length() < 1)
0759: path = "/";
0760: // FIXME
0761: name = new ObjectName(domain + ":j2eeType=WebModule,name=//"
0762: + host.getName() + path
0763: + ",J2EEApplication=none,J2EEServer=none");
0764:
0765: return (name);
0766:
0767: }
0768:
0769: /**
0770: * Create an <code>ObjectName</code> for this
0771: * <code>Service</code> object.
0772: *
0773: * @param domain Domain in which this name is to be created
0774: * @param environment The ContextEnvironment to be named
0775: *
0776: * @exception MalformedObjectNameException if a name cannot be created
0777: */
0778: public static ObjectName createObjectName(String domain,
0779: ContextEnvironment environment)
0780: throws MalformedObjectNameException {
0781:
0782: ObjectName name = null;
0783: Object container = environment.getNamingResources()
0784: .getContainer();
0785: if (container instanceof Server) {
0786: name = new ObjectName(domain + ":type=Environment"
0787: + ",resourcetype=Global,name="
0788: + environment.getName());
0789: } else if (container instanceof Context) {
0790: String path = ((Context) container).getPath();
0791: if (path.length() < 1)
0792: path = "/";
0793: Host host = (Host) ((Context) container).getParent();
0794: Engine engine = (Engine) host.getParent();
0795: Service service = engine.getService();
0796: name = new ObjectName(domain + ":type=Environment"
0797: + ",resourcetype=Context,path=" + path + ",host="
0798: + host.getName() + ",name=" + environment.getName());
0799: }
0800: return (name);
0801:
0802: }
0803:
0804: /**
0805: * Create an <code>ObjectName</code> for this
0806: * <code>ContextResource</code> object.
0807: *
0808: * @param domain Domain in which this name is to be created
0809: * @param resource The ContextResource to be named
0810: *
0811: * @exception MalformedObjectNameException if a name cannot be created
0812: */
0813: public static ObjectName createObjectName(String domain,
0814: ContextResource resource)
0815: throws MalformedObjectNameException {
0816:
0817: ObjectName name = null;
0818: String quotedResourceName = ObjectName
0819: .quote(resource.getName());
0820: Object container = resource.getNamingResources().getContainer();
0821: if (container instanceof Server) {
0822: name = new ObjectName(domain + ":type=Resource"
0823: + ",resourcetype=Global,class="
0824: + resource.getType() + ",name="
0825: + quotedResourceName);
0826: } else if (container instanceof Context) {
0827: String path = ((Context) container).getPath();
0828: if (path.length() < 1)
0829: path = "/";
0830: Host host = (Host) ((Context) container).getParent();
0831: Engine engine = (Engine) host.getParent();
0832: Service service = engine.getService();
0833: name = new ObjectName(domain + ":type=Resource"
0834: + ",resourcetype=Context,path=" + path + ",host="
0835: + host.getName() + ",class=" + resource.getType()
0836: + ",name=" + quotedResourceName);
0837: }
0838:
0839: return (name);
0840:
0841: }
0842:
0843: /**
0844: * Create an <code>ObjectName</code> for this
0845: * <code>ContextResourceLink</code> object.
0846: *
0847: * @param domain Domain in which this name is to be created
0848: * @param resourceLink The ContextResourceLink to be named
0849: *
0850: * @exception MalformedObjectNameException if a name cannot be created
0851: */
0852: public static ObjectName createObjectName(String domain,
0853: ContextResourceLink resourceLink)
0854: throws MalformedObjectNameException {
0855:
0856: ObjectName name = null;
0857: String quotedResourceLinkName = ObjectName.quote(resourceLink
0858: .getName());
0859: Object container = resourceLink.getNamingResources()
0860: .getContainer();
0861: if (container instanceof Server) {
0862: name = new ObjectName(domain + ":type=ResourceLink"
0863: + ",resourcetype=Global" + ",name="
0864: + quotedResourceLinkName);
0865: } else if (container instanceof Context) {
0866: String path = ((Context) container).getPath();
0867: if (path.length() < 1)
0868: path = "/";
0869: Host host = (Host) ((Context) container).getParent();
0870: Engine engine = (Engine) host.getParent();
0871: Service service = engine.getService();
0872: name = new ObjectName(domain + ":type=ResourceLink"
0873: + ",resourcetype=Context,path=" + path + ",host="
0874: + host.getName() + ",name="
0875: + quotedResourceLinkName);
0876: }
0877:
0878: return (name);
0879:
0880: }
0881:
0882: /**
0883: * Create an <code>ObjectName</code> for this
0884: * <code>Engine</code> object.
0885: *
0886: * @param domain Domain in which this name is to be created
0887: * @param engine The Engine to be named
0888: *
0889: * @exception MalformedObjectNameException if a name cannot be created
0890: */
0891: static ObjectName createObjectName(String domain, Engine engine)
0892: throws MalformedObjectNameException {
0893:
0894: ObjectName name = null;
0895: name = new ObjectName(domain + ":type=Engine");
0896: return (name);
0897:
0898: }
0899:
0900: /**
0901: * Create an <code>ObjectName</code> for this
0902: * <code>Group</code> object.
0903: *
0904: * @param domain Domain in which this name is to be created
0905: * @param group The Group to be named
0906: *
0907: * @exception MalformedObjectNameException if a name cannot be created
0908: */
0909: static ObjectName createObjectName(String domain, Group group)
0910: throws MalformedObjectNameException {
0911:
0912: ObjectName name = null;
0913: name = new ObjectName(domain + ":type=Group,groupname="
0914: + ObjectName.quote(group.getGroupname()) + ",database="
0915: + group.getUserDatabase().getId());
0916: return (name);
0917:
0918: }
0919:
0920: /**
0921: * Create an <code>ObjectName</code> for this
0922: * <code>Host</code> object.
0923: *
0924: * @param domain Domain in which this name is to be created
0925: * @param host The Host to be named
0926: *
0927: * @exception MalformedObjectNameException if a name cannot be created
0928: */
0929: static ObjectName createObjectName(String domain, Host host)
0930: throws MalformedObjectNameException {
0931:
0932: ObjectName name = null;
0933: Engine engine = (Engine) host.getParent();
0934: Service service = engine.getService();
0935: name = new ObjectName(domain + ":type=Host,host="
0936: + host.getName());
0937: return (name);
0938:
0939: }
0940:
0941: /**
0942: * Create an <code>ObjectName</code> for this
0943: * <code>Loader</code> object.
0944: *
0945: * @param domain Domain in which this name is to be created
0946: * @param loader The Loader to be named
0947: *
0948: * @exception MalformedObjectNameException if a name cannot be created
0949: */
0950: static ObjectName createObjectName(String domain, Loader loader)
0951: throws MalformedObjectNameException {
0952:
0953: ObjectName name = null;
0954: Container container = loader.getContainer();
0955:
0956: if (container instanceof Engine) {
0957: Service service = ((Engine) container).getService();
0958: name = new ObjectName(domain + ":type=Loader");
0959: } else if (container instanceof Host) {
0960: Engine engine = (Engine) container.getParent();
0961: Service service = engine.getService();
0962: name = new ObjectName(domain + ":type=Loader,host="
0963: + container.getName());
0964: } else if (container instanceof Context) {
0965: String path = ((Context) container).getPath();
0966: if (path.length() < 1) {
0967: path = "/";
0968: }
0969: Host host = (Host) container.getParent();
0970: Engine engine = (Engine) host.getParent();
0971: Service service = engine.getService();
0972: name = new ObjectName(domain + ":type=Loader,path=" + path
0973: + ",host=" + host.getName());
0974: }
0975:
0976: return (name);
0977:
0978: }
0979:
0980: /**
0981: * Create an <code>ObjectName</code> for this
0982: * <code>Manager</code> object.
0983: *
0984: * @param domain Domain in which this name is to be created
0985: * @param manager The Manager to be named
0986: *
0987: * @exception MalformedObjectNameException if a name cannot be created
0988: */
0989: static ObjectName createObjectName(String domain, Manager manager)
0990: throws MalformedObjectNameException {
0991:
0992: ObjectName name = null;
0993: Container container = manager.getContainer();
0994:
0995: if (container instanceof Engine) {
0996: Service service = ((Engine) container).getService();
0997: name = new ObjectName(domain + ":type=Manager");
0998: } else if (container instanceof Host) {
0999: Engine engine = (Engine) container.getParent();
1000: Service service = engine.getService();
1001: name = new ObjectName(domain + ":type=Manager,host="
1002: + container.getName());
1003: } else if (container instanceof Context) {
1004: String path = ((Context) container).getPath();
1005: if (path.length() < 1) {
1006: path = "/";
1007: }
1008: Host host = (Host) container.getParent();
1009: Engine engine = (Engine) host.getParent();
1010: Service service = engine.getService();
1011: name = new ObjectName(domain + ":type=Manager,path=" + path
1012: + ",host=" + host.getName());
1013: }
1014:
1015: return (name);
1016:
1017: }
1018:
1019: /**
1020: * Create an <code>ObjectName</code> for this
1021: * <code>Server</code> object.
1022: *
1023: * @param domain Domain in which this name is to be created
1024: * @param resources The NamingResources to be named
1025: *
1026: * @exception MalformedObjectNameException if a name cannot be created
1027: */
1028: static ObjectName createObjectName(String domain,
1029: NamingResources resources)
1030: throws MalformedObjectNameException {
1031:
1032: ObjectName name = null;
1033: Object container = resources.getContainer();
1034: if (container instanceof Server) {
1035: name = new ObjectName(domain + ":type=NamingResources"
1036: + ",resourcetype=Global");
1037: } else if (container instanceof Context) {
1038: String path = ((Context) container).getPath();
1039: if (path.length() < 1)
1040: path = "/";
1041: Host host = (Host) ((Context) container).getParent();
1042: Engine engine = (Engine) host.getParent();
1043: Service service = engine.getService();
1044: name = new ObjectName(domain + ":type=NamingResources"
1045: + ",resourcetype=Context,path=" + path + ",host="
1046: + host.getName());
1047: }
1048:
1049: return (name);
1050:
1051: }
1052:
1053: /**
1054: * Create an <code>ObjectName</code> for this
1055: * <code>MBeanFactory</code> object.
1056: *
1057: * @param domain Domain in which this name is to be created
1058: * @param factory The MBeanFactory to be named
1059: *
1060: * @exception MalformedObjectNameException if a name cannot be created
1061: */
1062: static ObjectName createObjectName(String domain,
1063: MBeanFactory factory) throws MalformedObjectNameException {
1064:
1065: ObjectName name = new ObjectName(domain + ":type=MBeanFactory");
1066:
1067: return (name);
1068:
1069: }
1070:
1071: /**
1072: * Create an <code>ObjectName</code> for this
1073: * <code>Realm</code> object.
1074: *
1075: * @param domain Domain in which this name is to be created
1076: * @param realm The Realm to be named
1077: *
1078: * @exception MalformedObjectNameException if a name cannot be created
1079: */
1080: static ObjectName createObjectName(String domain, Realm realm)
1081: throws MalformedObjectNameException {
1082:
1083: ObjectName name = null;
1084: Container container = realm.getContainer();
1085:
1086: if (container instanceof Engine) {
1087: Service service = ((Engine) container).getService();
1088: name = new ObjectName(domain + ":type=Realm");
1089: } else if (container instanceof Host) {
1090: Engine engine = (Engine) container.getParent();
1091: Service service = engine.getService();
1092: name = new ObjectName(domain + ":type=Realm,host="
1093: + container.getName());
1094: } else if (container instanceof Context) {
1095: String path = ((Context) container).getPath();
1096: if (path.length() < 1) {
1097: path = "/";
1098: }
1099: Host host = (Host) container.getParent();
1100: Engine engine = (Engine) host.getParent();
1101: Service service = engine.getService();
1102: name = new ObjectName(domain + ":type=Realm,path=" + path
1103: + ",host=" + host.getName());
1104: }
1105:
1106: return (name);
1107:
1108: }
1109:
1110: /**
1111: * Create an <code>ObjectName</code> for this
1112: * <code>Role</code> object.
1113: *
1114: * @param domain Domain in which this name is to be created
1115: * @param role The Role to be named
1116: *
1117: * @exception MalformedObjectNameException if a name cannot be created
1118: */
1119: static ObjectName createObjectName(String domain, Role role)
1120: throws MalformedObjectNameException {
1121:
1122: ObjectName name = null;
1123: name = new ObjectName(domain + ":type=Role,rolename="
1124: + role.getRolename() + ",database="
1125: + role.getUserDatabase().getId());
1126: return (name);
1127:
1128: }
1129:
1130: /**
1131: * Create an <code>ObjectName</code> for this
1132: * <code>Server</code> object.
1133: *
1134: * @param domain Domain in which this name is to be created
1135: * @param server The Server to be named
1136: *
1137: * @exception MalformedObjectNameException if a name cannot be created
1138: */
1139: static ObjectName createObjectName(String domain, Server server)
1140: throws MalformedObjectNameException {
1141:
1142: ObjectName name = null;
1143: name = new ObjectName(domain + ":type=Server");
1144: return (name);
1145:
1146: }
1147:
1148: /**
1149: * Create an <code>ObjectName</code> for this
1150: * <code>Service</code> object.
1151: *
1152: * @param domain Domain in which this name is to be created
1153: * @param service The Service to be named
1154: *
1155: * @exception MalformedObjectNameException if a name cannot be created
1156: */
1157: static ObjectName createObjectName(String domain, Service service)
1158: throws MalformedObjectNameException {
1159:
1160: ObjectName name = null;
1161: name = new ObjectName(domain + ":type=Service,serviceName="
1162: + service.getName());
1163: return (name);
1164:
1165: }
1166:
1167: /**
1168: * Create an <code>ObjectName</code> for this
1169: * <code>User</code> object.
1170: *
1171: * @param domain Domain in which this name is to be created
1172: * @param user The User to be named
1173: *
1174: * @exception MalformedObjectNameException if a name cannot be created
1175: */
1176: static ObjectName createObjectName(String domain, User user)
1177: throws MalformedObjectNameException {
1178:
1179: ObjectName name = null;
1180: name = new ObjectName(domain + ":type=User,username="
1181: + ObjectName.quote(user.getUsername()) + ",database="
1182: + user.getUserDatabase().getId());
1183: return (name);
1184:
1185: }
1186:
1187: /**
1188: * Create an <code>ObjectName</code> for this
1189: * <code>UserDatabase</code> object.
1190: *
1191: * @param domain Domain in which this name is to be created
1192: * @param userDatabase The UserDatabase to be named
1193: *
1194: * @exception MalformedObjectNameException if a name cannot be created
1195: */
1196: static ObjectName createObjectName(String domain,
1197: UserDatabase userDatabase)
1198: throws MalformedObjectNameException {
1199:
1200: ObjectName name = null;
1201: name = new ObjectName(domain + ":type=UserDatabase,database="
1202: + userDatabase.getId());
1203: return (name);
1204:
1205: }
1206:
1207: /**
1208: * Create an <code>ObjectName</code> for this
1209: * <code>Valve</code> object.
1210: *
1211: * @param domain Domain in which this name is to be created
1212: * @param valve The Valve to be named
1213: *
1214: * @exception MalformedObjectNameException if a name cannot be created
1215: */
1216: static ObjectName createObjectName(String domain, Valve valve)
1217: throws MalformedObjectNameException {
1218: if (valve instanceof ValveBase) {
1219: ObjectName name = ((ValveBase) valve).getObjectName();
1220: if (name != null)
1221: return name;
1222: }
1223:
1224: ObjectName name = null;
1225: Container container = null;
1226: String className = valve.getClass().getName();
1227: int period = className.lastIndexOf('.');
1228: if (period >= 0)
1229: className = className.substring(period + 1);
1230: if (valve instanceof Contained) {
1231: container = ((Contained) valve).getContainer();
1232: }
1233: if (container == null) {
1234: throw new MalformedObjectNameException(
1235: "Cannot create mbean for non-contained valve "
1236: + valve);
1237: }
1238: if (container instanceof Engine) {
1239: Service service = ((Engine) container).getService();
1240: String local = "";
1241: int seq = getSeq(local);
1242: String ext = "";
1243: if (seq > 0) {
1244: ext = ",seq=" + seq;
1245: }
1246: name = new ObjectName(domain + ":type=Valve,name="
1247: + className + ext + local);
1248: } else if (container instanceof Host) {
1249: Service service = ((Engine) container.getParent())
1250: .getService();
1251: String local = ",host=" + container.getName();
1252: int seq = getSeq(local);
1253: String ext = "";
1254: if (seq > 0) {
1255: ext = ",seq=" + seq;
1256: }
1257: name = new ObjectName(domain + ":type=Valve,name="
1258: + className + ext + local);
1259: } else if (container instanceof Context) {
1260: String path = ((Context) container).getPath();
1261: if (path.length() < 1) {
1262: path = "/";
1263: }
1264: Host host = (Host) container.getParent();
1265: Service service = ((Engine) host.getParent()).getService();
1266: String local = ",path=" + path + ",host=" + host.getName();
1267: int seq = getSeq(local);
1268: String ext = "";
1269: if (seq > 0) {
1270: ext = ",seq=" + seq;
1271: }
1272: name = new ObjectName(domain + ":type=Valve,name="
1273: + className + ext + local);
1274: }
1275:
1276: return (name);
1277:
1278: }
1279:
1280: static Hashtable seq = new Hashtable();
1281:
1282: static int getSeq(String key) {
1283: int i[] = (int[]) seq.get(key);
1284: if (i == null) {
1285: i = new int[1];
1286: i[0] = 0;
1287: seq.put(key, i);
1288: } else {
1289: i[0]++;
1290: }
1291: return i[0];
1292: }
1293:
1294: /**
1295: * Create and configure (if necessary) and return the registry of
1296: * managed object descriptions.
1297: */
1298: public synchronized static Registry createRegistry() {
1299:
1300: if (registry == null) {
1301: registry = Registry.getRegistry(null, null);
1302: ClassLoader cl = ServerLifecycleListener.class
1303: .getClassLoader();
1304:
1305: registry.loadDescriptors("org.apache.catalina.mbeans", cl);
1306: registry.loadDescriptors(
1307: "org.apache.catalina.authenticator", cl);
1308: registry.loadDescriptors("org.apache.catalina.core", cl);
1309: registry.loadDescriptors("org.apache.catalina", cl);
1310: registry.loadDescriptors("org.apache.catalina.deploy", cl);
1311: registry.loadDescriptors("org.apache.catalina.loader", cl);
1312: registry.loadDescriptors("org.apache.catalina.realm", cl);
1313: registry.loadDescriptors("org.apache.catalina.session", cl);
1314: registry.loadDescriptors("org.apache.catalina.startup", cl);
1315: registry.loadDescriptors("org.apache.catalina.users", cl);
1316: registry.loadDescriptors("org.apache.catalina.ha", cl);
1317: registry.loadDescriptors("org.apache.catalina.connector",
1318: cl);
1319: registry.loadDescriptors("org.apache.catalina.valves", cl);
1320: }
1321: return (registry);
1322:
1323: }
1324:
1325: /**
1326: * Create and configure (if necessary) and return the
1327: * <code>MBeanServer</code> with which we will be
1328: * registering our <code>DynamicMBean</code> implementations.
1329: */
1330: public synchronized static MBeanServer createServer() {
1331:
1332: if (mserver == null) {
1333: try {
1334: mserver = Registry.getRegistry(null, null)
1335: .getMBeanServer();
1336: } catch (Throwable t) {
1337: t.printStackTrace(System.out);
1338: System.exit(1);
1339: }
1340: }
1341: return (mserver);
1342:
1343: }
1344:
1345: /**
1346: * Deregister the MBean for this
1347: * <code>Connector</code> object.
1348: *
1349: * @param connector The Connector to be managed
1350: *
1351: * @exception Exception if an MBean cannot be deregistered
1352: */
1353: static void destroyMBean(Connector connector, Service service)
1354: throws Exception {
1355:
1356: connector.setService(service);
1357: String mname = createManagedName(connector);
1358: ManagedBean managed = registry.findManagedBean(mname);
1359: if (managed == null) {
1360: return;
1361: }
1362: String domain = managed.getDomain();
1363: if (domain == null)
1364: domain = mserver.getDefaultDomain();
1365: ObjectName oname = createObjectName(domain, connector);
1366: connector.setService(null);
1367: if (mserver.isRegistered(oname)) {
1368: mserver.unregisterMBean(oname);
1369: }
1370: }
1371:
1372: /**
1373: * Deregister the MBean for this
1374: * <code>Context</code> object.
1375: *
1376: * @param context The Context to be managed
1377: *
1378: * @exception Exception if an MBean cannot be deregistered
1379: */
1380: static void destroyMBean(Context context) throws Exception {
1381:
1382: String mname = createManagedName(context);
1383: ManagedBean managed = registry.findManagedBean(mname);
1384: if (managed == null) {
1385: return;
1386: }
1387: String domain = managed.getDomain();
1388: if (domain == null)
1389: domain = mserver.getDefaultDomain();
1390: ObjectName oname = createObjectName(domain, context);
1391: if (mserver.isRegistered(oname))
1392: mserver.unregisterMBean(oname);
1393:
1394: }
1395:
1396: /**
1397: * Deregister the MBean for this
1398: * <code>ContextEnvironment</code> object.
1399: *
1400: * @param environment The ContextEnvironment to be managed
1401: *
1402: * @exception Exception if an MBean cannot be deregistered
1403: */
1404: static void destroyMBean(ContextEnvironment environment)
1405: throws Exception {
1406:
1407: String mname = createManagedName(environment);
1408: ManagedBean managed = registry.findManagedBean(mname);
1409: if (managed == null) {
1410: return;
1411: }
1412: String domain = managed.getDomain();
1413: if (domain == null)
1414: domain = mserver.getDefaultDomain();
1415: ObjectName oname = createObjectName(domain, environment);
1416: if (mserver.isRegistered(oname))
1417: mserver.unregisterMBean(oname);
1418:
1419: }
1420:
1421: /**
1422: * Deregister the MBean for this
1423: * <code>ContextResource</code> object.
1424: *
1425: * @param resource The ContextResource to be managed
1426: *
1427: * @exception Exception if an MBean cannot be deregistered
1428: */
1429: static void destroyMBean(ContextResource resource) throws Exception {
1430:
1431: String mname = createManagedName(resource);
1432: ManagedBean managed = registry.findManagedBean(mname);
1433: if (managed == null) {
1434: return;
1435: }
1436: String domain = managed.getDomain();
1437: if (domain == null)
1438: domain = mserver.getDefaultDomain();
1439: ObjectName oname = createObjectName(domain, resource);
1440: if (mserver.isRegistered(oname))
1441: mserver.unregisterMBean(oname);
1442:
1443: }
1444:
1445: /**
1446: * Deregister the MBean for this
1447: * <code>ContextResourceLink</code> object.
1448: *
1449: * @param resourceLink The ContextResourceLink to be managed
1450: *
1451: * @exception Exception if an MBean cannot be deregistered
1452: */
1453: static void destroyMBean(ContextResourceLink resourceLink)
1454: throws Exception {
1455:
1456: String mname = createManagedName(resourceLink);
1457: ManagedBean managed = registry.findManagedBean(mname);
1458: if (managed == null) {
1459: return;
1460: }
1461: String domain = managed.getDomain();
1462: if (domain == null)
1463: domain = mserver.getDefaultDomain();
1464: ObjectName oname = createObjectName(domain, resourceLink);
1465: if (mserver.isRegistered(oname))
1466: mserver.unregisterMBean(oname);
1467:
1468: }
1469:
1470: /**
1471: * Deregister the MBean for this
1472: * <code>Engine</code> object.
1473: *
1474: * @param engine The Engine to be managed
1475: *
1476: * @exception Exception if an MBean cannot be deregistered
1477: */
1478: static void destroyMBean(Engine engine) throws Exception {
1479:
1480: String mname = createManagedName(engine);
1481: ManagedBean managed = registry.findManagedBean(mname);
1482: if (managed == null) {
1483: return;
1484: }
1485: String domain = managed.getDomain();
1486: if (domain == null)
1487: domain = mserver.getDefaultDomain();
1488: ObjectName oname = createObjectName(domain, engine);
1489: if (mserver.isRegistered(oname))
1490: mserver.unregisterMBean(oname);
1491:
1492: }
1493:
1494: /**
1495: * Deregister the MBean for this
1496: * <code>Group</code> object.
1497: *
1498: * @param group The Group to be managed
1499: *
1500: * @exception Exception if an MBean cannot be deregistered
1501: */
1502: static void destroyMBean(Group group) throws Exception {
1503:
1504: String mname = createManagedName(group);
1505: ManagedBean managed = registry.findManagedBean(mname);
1506: if (managed == null) {
1507: return;
1508: }
1509: String domain = managed.getDomain();
1510: if (domain == null)
1511: domain = mserver.getDefaultDomain();
1512: ObjectName oname = createObjectName(domain, group);
1513: if (mserver.isRegistered(oname))
1514: mserver.unregisterMBean(oname);
1515:
1516: }
1517:
1518: /**
1519: * Deregister the MBean for this
1520: * <code>Host</code> object.
1521: *
1522: * @param host The Host to be managed
1523: *
1524: * @exception Exception if an MBean cannot be deregistered
1525: */
1526: static void destroyMBean(Host host) throws Exception {
1527:
1528: String mname = createManagedName(host);
1529: ManagedBean managed = registry.findManagedBean(mname);
1530: if (managed == null) {
1531: return;
1532: }
1533: String domain = managed.getDomain();
1534: if (domain == null)
1535: domain = mserver.getDefaultDomain();
1536: ObjectName oname = createObjectName(domain, host);
1537: if (mserver.isRegistered(oname))
1538: mserver.unregisterMBean(oname);
1539:
1540: }
1541:
1542: /**
1543: * Deregister the MBean for this
1544: * <code>Loader</code> object.
1545: *
1546: * @param loader The Loader to be managed
1547: *
1548: * @exception Exception if an MBean cannot be deregistered
1549: */
1550: static void destroyMBean(Loader loader) throws Exception {
1551:
1552: String mname = createManagedName(loader);
1553: ManagedBean managed = registry.findManagedBean(mname);
1554: if (managed == null) {
1555: return;
1556: }
1557: String domain = managed.getDomain();
1558: if (domain == null)
1559: domain = mserver.getDefaultDomain();
1560: ObjectName oname = createObjectName(domain, loader);
1561: if (mserver.isRegistered(oname))
1562: mserver.unregisterMBean(oname);
1563:
1564: }
1565:
1566: /**
1567: * Deregister the MBean for this
1568: * <code>Manager</code> object.
1569: *
1570: * @param manager The Manager to be managed
1571: *
1572: * @exception Exception if an MBean cannot be deregistered
1573: */
1574: static void destroyMBean(Manager manager) throws Exception {
1575:
1576: String mname = createManagedName(manager);
1577: ManagedBean managed = registry.findManagedBean(mname);
1578: if (managed == null) {
1579: return;
1580: }
1581: String domain = managed.getDomain();
1582: if (domain == null)
1583: domain = mserver.getDefaultDomain();
1584: ObjectName oname = createObjectName(domain, manager);
1585: if (mserver.isRegistered(oname))
1586: mserver.unregisterMBean(oname);
1587:
1588: }
1589:
1590: /**
1591: * Deregister the MBean for this
1592: * <code>NamingResources</code> object.
1593: *
1594: * @param resources The NamingResources to be managed
1595: *
1596: * @exception Exception if an MBean cannot be deregistered
1597: */
1598: static void destroyMBean(NamingResources resources)
1599: throws Exception {
1600:
1601: String mname = createManagedName(resources);
1602: ManagedBean managed = registry.findManagedBean(mname);
1603: if (managed == null) {
1604: return;
1605: }
1606: String domain = managed.getDomain();
1607: if (domain == null)
1608: domain = mserver.getDefaultDomain();
1609: ObjectName oname = createObjectName(domain, resources);
1610: if (mserver.isRegistered(oname))
1611: mserver.unregisterMBean(oname);
1612:
1613: }
1614:
1615: /**
1616: * Deregister the MBean for this
1617: * <code>Realm</code> object.
1618: *
1619: * @param realm The Realm to be managed
1620: *
1621: * @exception Exception if an MBean cannot be deregistered
1622: */
1623: static void destroyMBean(Realm realm) throws Exception {
1624:
1625: String mname = createManagedName(realm);
1626: ManagedBean managed = registry.findManagedBean(mname);
1627: if (managed == null) {
1628: return;
1629: }
1630: String domain = managed.getDomain();
1631: if (domain == null)
1632: domain = mserver.getDefaultDomain();
1633: ObjectName oname = createObjectName(domain, realm);
1634: if (mserver.isRegistered(oname))
1635: mserver.unregisterMBean(oname);
1636:
1637: }
1638:
1639: /**
1640: * Deregister the MBean for this
1641: * <code>Role</code> object.
1642: *
1643: * @param role The Role to be managed
1644: *
1645: * @exception Exception if an MBean cannot be deregistered
1646: */
1647: static void destroyMBean(Role role) throws Exception {
1648:
1649: String mname = createManagedName(role);
1650: ManagedBean managed = registry.findManagedBean(mname);
1651: if (managed == null) {
1652: return;
1653: }
1654: String domain = managed.getDomain();
1655: if (domain == null)
1656: domain = mserver.getDefaultDomain();
1657: ObjectName oname = createObjectName(domain, role);
1658: if (mserver.isRegistered(oname))
1659: mserver.unregisterMBean(oname);
1660:
1661: }
1662:
1663: /**
1664: * Deregister the MBean for this
1665: * <code>Server</code> object.
1666: *
1667: * @param server The Server to be managed
1668: *
1669: * @exception Exception if an MBean cannot be deregistered
1670: */
1671: static void destroyMBean(Server server) throws Exception {
1672:
1673: String mname = createManagedName(server);
1674: ManagedBean managed = registry.findManagedBean(mname);
1675: if (managed == null) {
1676: return;
1677: }
1678: String domain = managed.getDomain();
1679: if (domain == null)
1680: domain = mserver.getDefaultDomain();
1681: ObjectName oname = createObjectName(domain, server);
1682: if (mserver.isRegistered(oname))
1683: mserver.unregisterMBean(oname);
1684:
1685: }
1686:
1687: /**
1688: * Deregister the MBean for this
1689: * <code>Service</code> object.
1690: *
1691: * @param service The Service to be managed
1692: *
1693: * @exception Exception if an MBean cannot be deregistered
1694: */
1695: static void destroyMBean(Service service) throws Exception {
1696:
1697: String mname = createManagedName(service);
1698: ManagedBean managed = registry.findManagedBean(mname);
1699: if (managed == null) {
1700: return;
1701: }
1702: String domain = managed.getDomain();
1703: if (domain == null)
1704: domain = mserver.getDefaultDomain();
1705: ObjectName oname = createObjectName(domain, service);
1706: if (mserver.isRegistered(oname))
1707: mserver.unregisterMBean(oname);
1708:
1709: }
1710:
1711: /**
1712: * Deregister the MBean for this
1713: * <code>User</code> object.
1714: *
1715: * @param user The User to be managed
1716: *
1717: * @exception Exception if an MBean cannot be deregistered
1718: */
1719: static void destroyMBean(User user) throws Exception {
1720:
1721: String mname = createManagedName(user);
1722: ManagedBean managed = registry.findManagedBean(mname);
1723: if (managed == null) {
1724: return;
1725: }
1726: String domain = managed.getDomain();
1727: if (domain == null)
1728: domain = mserver.getDefaultDomain();
1729: ObjectName oname = createObjectName(domain, user);
1730: if (mserver.isRegistered(oname))
1731: mserver.unregisterMBean(oname);
1732:
1733: }
1734:
1735: /**
1736: * Deregister the MBean for this
1737: * <code>UserDatabase</code> object.
1738: *
1739: * @param userDatabase The UserDatabase to be managed
1740: *
1741: * @exception Exception if an MBean cannot be deregistered
1742: */
1743: static void destroyMBean(UserDatabase userDatabase)
1744: throws Exception {
1745:
1746: String mname = createManagedName(userDatabase);
1747: ManagedBean managed = registry.findManagedBean(mname);
1748: if (managed == null) {
1749: return;
1750: }
1751: String domain = managed.getDomain();
1752: if (domain == null)
1753: domain = mserver.getDefaultDomain();
1754: ObjectName oname = createObjectName(domain, userDatabase);
1755: if (mserver.isRegistered(oname))
1756: mserver.unregisterMBean(oname);
1757:
1758: }
1759:
1760: /**
1761: * Deregister the MBean for this
1762: * <code>Valve</code> object.
1763: *
1764: * @param valve The Valve to be managed
1765: *
1766: * @exception Exception if an MBean cannot be deregistered
1767: */
1768: static void destroyMBean(Valve valve, Container container)
1769: throws Exception {
1770:
1771: ((Contained) valve).setContainer(container);
1772: String mname = createManagedName(valve);
1773: ManagedBean managed = registry.findManagedBean(mname);
1774: if (managed == null) {
1775: return;
1776: }
1777: String domain = managed.getDomain();
1778: if (domain == null)
1779: domain = mserver.getDefaultDomain();
1780: ObjectName oname = createObjectName(domain, valve);
1781: try {
1782: ((Contained) valve).setContainer(null);
1783: } catch (Throwable t) {
1784: ;
1785: }
1786: if (mserver.isRegistered(oname)) {
1787: mserver.unregisterMBean(oname);
1788: }
1789:
1790: }
1791:
1792: }
|