FileDocCategorySizeDatePackage
MBeanUtils.javaAPI DocApache Tomcat 6.0.1463996Fri Jul 20 04:20:30 BST 2007org.apache.catalina.mbeans

MBeanUtils

public class MBeanUtils extends Object
Public utility methods in support of the server side MBeans implementation.
author
Craig R. McClanahan
author
Amy Roh
version
$Revision: 500684 $ $Date: 2007-01-28 00:27:18 +0100 (dim., 28 janv. 2007) $

Fields Summary
private static org.apache.juli.logging.Log
log
private static String[]
exceptions
The set of exceptions to the normal rules used by createManagedBean(). The first element of each pair is a class name, and the second element is the managed bean name.
private static org.apache.tomcat.util.modeler.Registry
registry
The configuration information registry for our managed beans.
private static MBeanServer
mserver
The MBeanServer for this application.
static Hashtable
seq
Constructors Summary
Methods Summary
static javax.management.DynamicMBeancreateMBean(org.apache.catalina.Loader loader)
Create, register, and return an MBean for this Loader object.

param
loader The Loader to be managed
exception
Exception if an MBean cannot be created or registered


        String mname = createManagedName(loader);
        ManagedBean managed = registry.findManagedBean(mname);
        if (managed == null) {
            Exception e = new Exception("ManagedBean is not found with "+mname);
            throw new MBeanException(e);
        }
        String domain = managed.getDomain();
        if (domain == null)
            domain = mserver.getDefaultDomain();
        DynamicMBean mbean = managed.createMBean(loader);
        ObjectName oname = createObjectName(domain, loader);
        if( mserver.isRegistered( oname ))  {
            // side effect: stop it
            mserver.unregisterMBean( oname );
        }
        mserver.registerMBean(mbean, oname);
        return (mbean);

    
static javax.management.DynamicMBeancreateMBean(org.apache.catalina.Manager manager)
Create, register, and return an MBean for this Manager object.

param
manager The Manager to be managed
exception
Exception if an MBean cannot be created or registered


        String mname = createManagedName(manager);
        ManagedBean managed = registry.findManagedBean(mname);
        if (managed == null) {
            Exception e = new Exception("ManagedBean is not found with "+mname);
            throw new MBeanException(e);
        }
        String domain = managed.getDomain();
        if (domain == null)
            domain = mserver.getDefaultDomain();
        DynamicMBean mbean = managed.createMBean(manager);
        ObjectName oname = createObjectName(domain, manager);
        if( mserver.isRegistered( oname ))  {
            mserver.unregisterMBean(oname);
        }
        mserver.registerMBean(mbean, oname);
        return (mbean);

    
static javax.management.DynamicMBeancreateMBean(MBeanFactory factory)
Create, register, and return an MBean for this MBeanFactory object.

param
factory The MBeanFactory to be managed
exception
Exception if an MBean cannot be created or registered


        String mname = createManagedName(factory);
        ManagedBean managed = registry.findManagedBean(mname);
        if (managed == null) {
            Exception e = new Exception("ManagedBean is not found with "+mname);
            throw new MBeanException(e);
        }
        String domain = managed.getDomain();
        if (domain == null)
            domain = mserver.getDefaultDomain();
        DynamicMBean mbean = managed.createMBean(factory);
        ObjectName oname = createObjectName(domain, factory);
        if( mserver.isRegistered(oname )) {
            mserver.unregisterMBean(oname);
        }
        mserver.registerMBean(mbean, oname);
        return (mbean);

    
static javax.management.DynamicMBeancreateMBean(org.apache.catalina.deploy.NamingResources resource)
Create, register, and return an MBean for this NamingResources object.

param
resource The NamingResources to be managed
exception
Exception if an MBean cannot be created or registered


        String mname = createManagedName(resource);
        ManagedBean managed = registry.findManagedBean(mname);
        if (managed == null) {
            Exception e = new Exception("ManagedBean is not found with "+mname);
            throw new MBeanException(e);
        }
        String domain = managed.getDomain();
        if (domain == null)
            domain = mserver.getDefaultDomain();
        DynamicMBean mbean = managed.createMBean(resource);
        ObjectName oname = createObjectName(domain, resource);
        if( mserver.isRegistered( oname ))  {
            mserver.unregisterMBean(oname);
        }
        mserver.registerMBean(mbean, oname);
        return (mbean);

    
static javax.management.DynamicMBeancreateMBean(org.apache.catalina.Realm realm)
Create, register, and return an MBean for this Realm object.

param
realm The Realm to be managed
exception
Exception if an MBean cannot be created or registered


        String mname = createManagedName(realm);
        ManagedBean managed = registry.findManagedBean(mname);
        if (managed == null) {
            Exception e = new Exception("ManagedBean is not found with "+mname);
            throw new MBeanException(e);
        }
        String domain = managed.getDomain();
        if (domain == null)
            domain = mserver.getDefaultDomain();
        DynamicMBean mbean = managed.createMBean(realm);
        ObjectName oname = createObjectName(domain, realm);
        if( mserver.isRegistered( oname ))  {
            mserver.unregisterMBean(oname);
        }
        mserver.registerMBean(mbean, oname);
        return (mbean);

    
static javax.management.DynamicMBeancreateMBean(org.apache.catalina.Role role)
Create, register, and return an MBean for this Role object.

param
role The Role to be managed
exception
Exception if an MBean cannot be created or registered


        String mname = createManagedName(role);
        ManagedBean managed = registry.findManagedBean(mname);
        if (managed == null) {
            Exception e = new Exception("ManagedBean is not found with "+mname);
            throw new MBeanException(e);
        }
        String domain = managed.getDomain();
        if (domain == null)
            domain = mserver.getDefaultDomain();
        DynamicMBean mbean = managed.createMBean(role);
        ObjectName oname = createObjectName(domain, role);
        if( mserver.isRegistered( oname ))  {
            mserver.unregisterMBean(oname);
        }
        mserver.registerMBean(mbean, oname);
        return (mbean);

    
static javax.management.DynamicMBeancreateMBean(org.apache.catalina.Server server)
Create, register, and return an MBean for this Server object.

param
server The Server to be managed
exception
Exception if an MBean cannot be created or registered


        String mname = createManagedName(server);
        ManagedBean managed = registry.findManagedBean(mname);
        if (managed == null) {
            Exception e = new Exception("ManagedBean is not found with "+mname);
            throw new MBeanException(e);
        }
        String domain = managed.getDomain();
        if (domain == null)
            domain = mserver.getDefaultDomain();
        DynamicMBean mbean = managed.createMBean(server);
        ObjectName oname = createObjectName(domain, server);
        if( mserver.isRegistered( oname ))  {
            mserver.unregisterMBean(oname);
        }
        mserver.registerMBean(mbean, oname);
        return (mbean);

    
static javax.management.DynamicMBeancreateMBean(org.apache.catalina.Service service)
Create, register, and return an MBean for this Service object.

param
service The Service to be managed
exception
Exception if an MBean cannot be created or registered


        String mname = createManagedName(service);
        ManagedBean managed = registry.findManagedBean(mname);
        if (managed == null) {
            Exception e = new Exception("ManagedBean is not found with "+mname);
            throw new MBeanException(e);
        }
        String domain = managed.getDomain();
        if (domain == null)
            domain = mserver.getDefaultDomain();
        DynamicMBean mbean = managed.createMBean(service);
        ObjectName oname = createObjectName(domain, service);
        if( mserver.isRegistered( oname ))  {
            mserver.unregisterMBean(oname);
        }
        mserver.registerMBean(mbean, oname);
        return (mbean);

    
static javax.management.DynamicMBeancreateMBean(org.apache.catalina.User user)
Create, register, and return an MBean for this User object.

param
user The User to be managed
exception
Exception if an MBean cannot be created or registered


        String mname = createManagedName(user);
        ManagedBean managed = registry.findManagedBean(mname);
        if (managed == null) {
            Exception e = new Exception("ManagedBean is not found with "+mname);
            throw new MBeanException(e);
        }
        String domain = managed.getDomain();
        if (domain == null)
            domain = mserver.getDefaultDomain();
        DynamicMBean mbean = managed.createMBean(user);
        ObjectName oname = createObjectName(domain, user);
        if( mserver.isRegistered( oname ))  {
            mserver.unregisterMBean(oname);
        }
        mserver.registerMBean(mbean, oname);
        return (mbean);

    
static javax.management.DynamicMBeancreateMBean(org.apache.catalina.UserDatabase userDatabase)
Create, register, and return an MBean for this UserDatabase object.

param
userDatabase The UserDatabase to be managed
exception
Exception if an MBean cannot be created or registered


        String mname = createManagedName(userDatabase);
        ManagedBean managed = registry.findManagedBean(mname);
        if (managed == null) {
            Exception e = new Exception("ManagedBean is not found with "+mname);
            throw new MBeanException(e);
        }
        String domain = managed.getDomain();
        if (domain == null)
            domain = mserver.getDefaultDomain();
        DynamicMBean mbean = managed.createMBean(userDatabase);
        ObjectName oname = createObjectName(domain, userDatabase);
        if( mserver.isRegistered( oname ))  {
            mserver.unregisterMBean(oname);
        }
        mserver.registerMBean(mbean, oname);
        return (mbean);

    
static javax.management.DynamicMBeancreateMBean(org.apache.catalina.connector.Connector connector)
Create, register, and return an MBean for this Connector object.

param
connector The Connector to be managed
exception
Exception if an MBean cannot be created or registered


        String mname = createManagedName(connector);
        ManagedBean managed = registry.findManagedBean(mname);
        if (managed == null) {
            Exception e = new Exception("ManagedBean is not found with "+mname);
            throw new MBeanException(e);
        }
        String domain = managed.getDomain();
        if (domain == null)
            domain = mserver.getDefaultDomain();
        DynamicMBean mbean = managed.createMBean(connector);
        ObjectName oname = createObjectName(domain, connector);
        if( mserver.isRegistered( oname ))  {
            mserver.unregisterMBean(oname);
        }
        mserver.registerMBean(mbean, oname);
        return (mbean);

    
static javax.management.DynamicMBeancreateMBean(org.apache.catalina.Valve valve)
Create, register, and return an MBean for this Valve object.

param
valve The Valve to be managed
exception
Exception if an MBean cannot be created or registered


        String mname = createManagedName(valve);
        ManagedBean managed = registry.findManagedBean(mname);
        if (managed == null) {
            Exception e = new Exception("ManagedBean is not found with "+mname);
            throw new MBeanException(e);
        }
        String domain = managed.getDomain();
        if (domain == null)
            domain = mserver.getDefaultDomain();
        DynamicMBean mbean = managed.createMBean(valve);
        ObjectName oname = createObjectName(domain, valve);
        if( mserver.isRegistered( oname ))  {
            mserver.unregisterMBean(oname);
        }
        mserver.registerMBean(mbean, oname);
        return (mbean);

    
static javax.management.DynamicMBeancreateMBean(org.apache.catalina.Context context)
Create, register, and return an MBean for this Context object.

param
context The Context to be managed
exception
Exception if an MBean cannot be created or registered


        String mname = createManagedName(context);
        ManagedBean managed = registry.findManagedBean(mname);
        if (managed == null) {
            Exception e = new Exception("ManagedBean is not found with "+mname);
            throw new MBeanException(e);
        }
        String domain = managed.getDomain();
        if (domain == null)
            domain = mserver.getDefaultDomain();
        DynamicMBean mbean = managed.createMBean(context);
        ObjectName oname = createObjectName(domain, context);
        if( mserver.isRegistered(oname)) {
            log.debug("Already registered " + oname);
            mserver.unregisterMBean(oname);
        }
        mserver.registerMBean(mbean, oname);
        return (mbean);

    
static javax.management.DynamicMBeancreateMBean(org.apache.catalina.deploy.ContextEnvironment environment)
Create, register, and return an MBean for this ContextEnvironment object.

param
environment The ContextEnvironment to be managed
exception
Exception if an MBean cannot be created or registered


        String mname = createManagedName(environment);
        ManagedBean managed = registry.findManagedBean(mname);
        if (managed == null) {
            Exception e = new Exception("ManagedBean is not found with "+mname);
            throw new MBeanException(e);
        }
        String domain = managed.getDomain();
        if (domain == null)
            domain = mserver.getDefaultDomain();
        DynamicMBean mbean = managed.createMBean(environment);
        ObjectName oname = createObjectName(domain, environment);
        if( mserver.isRegistered( oname ))  {
            mserver.unregisterMBean(oname);
        }
        mserver.registerMBean(mbean, oname);
        return (mbean);

    
static javax.management.DynamicMBeancreateMBean(org.apache.catalina.deploy.ContextResource resource)
Create, register, and return an MBean for this ContextResource object.

param
resource The ContextResource to be managed
exception
Exception if an MBean cannot be created or registered


        String mname = createManagedName(resource);
        ManagedBean managed = registry.findManagedBean(mname);
        if (managed == null) {
            Exception e = new Exception("ManagedBean is not found with "+mname);
            throw new MBeanException(e);
        }
        String domain = managed.getDomain();
        if (domain == null)
            domain = mserver.getDefaultDomain();
        DynamicMBean mbean = managed.createMBean(resource);
        ObjectName oname = createObjectName(domain, resource);
        if( mserver.isRegistered( oname ))  {
            mserver.unregisterMBean(oname);
        }
        mserver.registerMBean(mbean, oname);
        return (mbean);

    
static javax.management.DynamicMBeancreateMBean(org.apache.catalina.deploy.ContextResourceLink resourceLink)
Create, register, and return an MBean for this ContextResourceLink object.

param
resourceLink The ContextResourceLink to be managed
exception
Exception if an MBean cannot be created or registered


        String mname = createManagedName(resourceLink);
        ManagedBean managed = registry.findManagedBean(mname);
        if (managed == null) {
            Exception e = new Exception("ManagedBean is not found with "+mname);
            throw new MBeanException(e);
        }
        String domain = managed.getDomain();
        if (domain == null)
            domain = mserver.getDefaultDomain();
        DynamicMBean mbean = managed.createMBean(resourceLink);
        ObjectName oname = createObjectName(domain, resourceLink);
        if( mserver.isRegistered( oname ))  {
            mserver.unregisterMBean(oname);
        }
        mserver.registerMBean(mbean, oname);
        return (mbean);

    
static javax.management.DynamicMBeancreateMBean(org.apache.catalina.Engine engine)
Create, register, and return an MBean for this Engine object.

param
engine The Engine to be managed
exception
Exception if an MBean cannot be created or registered


        String mname = createManagedName(engine);
        ManagedBean managed = registry.findManagedBean(mname);
        if (managed == null) {
            Exception e = new Exception("ManagedBean is not found with "+mname);
            throw new MBeanException(e);
        }
        String domain = managed.getDomain();
        if (domain == null)
            domain = mserver.getDefaultDomain();
        DynamicMBean mbean = managed.createMBean(engine);
        ObjectName oname = createObjectName(domain, engine);
        if( mserver.isRegistered( oname ))  {
            mserver.unregisterMBean(oname);
        }
        mserver.registerMBean(mbean, oname);
        return (mbean);

    
static javax.management.DynamicMBeancreateMBean(org.apache.catalina.Group group)
Create, register, and return an MBean for this Group object.

param
group The Group to be managed
exception
Exception if an MBean cannot be created or registered


        String mname = createManagedName(group);
        ManagedBean managed = registry.findManagedBean(mname);
        if (managed == null) {
            Exception e = new Exception("ManagedBean is not found with "+mname);
            throw new MBeanException(e);
        }
        String domain = managed.getDomain();
        if (domain == null)
            domain = mserver.getDefaultDomain();
        DynamicMBean mbean = managed.createMBean(group);
        ObjectName oname = createObjectName(domain, group);
        if( mserver.isRegistered( oname ))  {
            mserver.unregisterMBean(oname);
        }
        mserver.registerMBean(mbean, oname);
        return (mbean);

    
static javax.management.DynamicMBeancreateMBean(org.apache.catalina.Host host)
Create, register, and return an MBean for this Host object.

param
host The Host to be managed
exception
Exception if an MBean cannot be created or registered


        String mname = createManagedName(host);
        ManagedBean managed = registry.findManagedBean(mname);
        if (managed == null) {
            Exception e = new Exception("ManagedBean is not found with "+mname);
            throw new MBeanException(e);
        }
        String domain = managed.getDomain();
        if (domain == null)
            domain = mserver.getDefaultDomain();
        DynamicMBean mbean = managed.createMBean(host);
        ObjectName oname = createObjectName(domain, host);
        if( mserver.isRegistered( oname ))  {
            mserver.unregisterMBean(oname);
        }
        mserver.registerMBean(mbean, oname);
        return (mbean);

    
static java.lang.StringcreateManagedName(java.lang.Object component)
Create and return the name of the ManagedBean that corresponds to this Catalina component.

param
component The component for which to create a name



    // --------------------------------------------------------- Static Methods

                                 
        

        // Deal with exceptions to the standard rule
        String className = component.getClass().getName();
        for (int i = 0; i < exceptions.length; i++) {
            if (className.equals(exceptions[i][0])) {
                return (exceptions[i][1]);
            }
        }

        // Perform the standard transformation
        int period = className.lastIndexOf('.");
        if (period >= 0)
            className = className.substring(period + 1);
        return (className);

    
static javax.management.ObjectNamecreateObjectName(java.lang.String domain, org.apache.catalina.connector.Connector connector)
Create an ObjectName for this Connector object.

param
domain Domain in which this name is to be created
param
connector The Connector to be named
exception
MalformedObjectNameException if a name cannot be created


        ObjectName name = null;
        if (connector.getClass().getName().indexOf("CoyoteConnector") >= 0 ) {
            try {
                String address = (String)
                    IntrospectionUtils.getProperty(connector, "address");
                Integer port = (Integer)
                    IntrospectionUtils.getProperty(connector, "port");
                Service service = connector.getService();
                String serviceName = null;
                if (service != null)
                    serviceName = service.getName();
                StringBuffer sb = new StringBuffer(domain);
                sb.append(":type=Connector");
                sb.append(",port=" + port);
                if ((address != null) && (address.length()>0)) {
                    sb.append(",address=" + address);
                }
                name = new ObjectName(sb.toString());
                return (name);
            } catch (Exception e) {
                throw new MalformedObjectNameException
                    ("Cannot create object name for " + connector+e);
            }
        } else {
            throw new MalformedObjectNameException
                ("Cannot create object name for " + connector);
        }

    
static javax.management.ObjectNamecreateObjectName(java.lang.String domain, org.apache.catalina.Context context)
Create an ObjectName for this Context object.

param
domain Domain in which this name is to be created
param
context The Context to be named
exception
MalformedObjectNameException if a name cannot be created


        ObjectName name = null;
        Host host = (Host)context.getParent();
        Service service = ((Engine)host.getParent()).getService();
        String path = context.getPath();
        if (path.length() < 1)
            path = "/";
        // FIXME 
        name = new ObjectName(domain + ":j2eeType=WebModule,name=//" +
                              host.getName()+ path +
                              ",J2EEApplication=none,J2EEServer=none");
    
        return (name);

    
public static javax.management.ObjectNamecreateObjectName(java.lang.String domain, org.apache.catalina.deploy.ContextEnvironment environment)
Create an ObjectName for this Service object.

param
domain Domain in which this name is to be created
param
environment The ContextEnvironment to be named
exception
MalformedObjectNameException if a name cannot be created


        ObjectName name = null;
        Object container = 
                environment.getNamingResources().getContainer();
        if (container instanceof Server) {
            name = new ObjectName(domain + ":type=Environment" + 
                        ",resourcetype=Global,name=" + environment.getName());
        } else if (container instanceof Context) {        
            String path = ((Context)container).getPath();
            if (path.length() < 1)
                path = "/";
            Host host = (Host) ((Context)container).getParent();
            Engine engine = (Engine) host.getParent();
            Service service = engine.getService();
            name = new ObjectName(domain + ":type=Environment" + 
                        ",resourcetype=Context,path=" + path + 
                        ",host=" + host.getName() +
                        ",name=" + environment.getName());
        }        
        return (name);

    
public static javax.management.ObjectNamecreateObjectName(java.lang.String domain, org.apache.catalina.deploy.ContextResource resource)
Create an ObjectName for this ContextResource object.

param
domain Domain in which this name is to be created
param
resource The ContextResource to be named
exception
MalformedObjectNameException if a name cannot be created


        ObjectName name = null;
        String quotedResourceName = ObjectName.quote(resource.getName());
        Object container = 
                resource.getNamingResources().getContainer();
        if (container instanceof Server) {        
            name = new ObjectName(domain + ":type=Resource" +
                        ",resourcetype=Global,class=" + resource.getType() + 
                        ",name=" + quotedResourceName);
        } else if (container instanceof Context) {                    
            String path = ((Context)container).getPath();
            if (path.length() < 1)
                path = "/";
            Host host = (Host) ((Context)container).getParent();
            Engine engine = (Engine) host.getParent();
            Service service = engine.getService();
            name = new ObjectName(domain + ":type=Resource" +
                        ",resourcetype=Context,path=" + path + 
                        ",host=" + host.getName() +
                        ",class=" + resource.getType() +
                        ",name=" + quotedResourceName);
        }
        
        return (name);

    
public static javax.management.ObjectNamecreateObjectName(java.lang.String domain, org.apache.catalina.deploy.ContextResourceLink resourceLink)
Create an ObjectName for this ContextResourceLink object.

param
domain Domain in which this name is to be created
param
resourceLink The ContextResourceLink to be named
exception
MalformedObjectNameException if a name cannot be created


        ObjectName name = null;
        String quotedResourceLinkName
                = ObjectName.quote(resourceLink.getName());        
        Object container = 
                resourceLink.getNamingResources().getContainer();
        if (container instanceof Server) {        
            name = new ObjectName(domain + ":type=ResourceLink" +
                        ",resourcetype=Global" + 
                        ",name=" + quotedResourceLinkName);
        } else if (container instanceof Context) {                    
            String path = ((Context)container).getPath();
            if (path.length() < 1)
                path = "/";
            Host host = (Host) ((Context)container).getParent();
            Engine engine = (Engine) host.getParent();
            Service service = engine.getService();
            name = new ObjectName(domain + ":type=ResourceLink" +
                        ",resourcetype=Context,path=" + path + 
                        ",host=" + host.getName() +
                        ",name=" + quotedResourceLinkName);
        }
        
        return (name);

    
static javax.management.ObjectNamecreateObjectName(java.lang.String domain, org.apache.catalina.Engine engine)
Create an ObjectName for this Engine object.

param
domain Domain in which this name is to be created
param
engine The Engine to be named
exception
MalformedObjectNameException if a name cannot be created


        ObjectName name = null;
        name = new ObjectName(domain + ":type=Engine");
        return (name);

    
static javax.management.ObjectNamecreateObjectName(java.lang.String domain, org.apache.catalina.Group group)
Create an ObjectName for this Group object.

param
domain Domain in which this name is to be created
param
group The Group to be named
exception
MalformedObjectNameException if a name cannot be created


        ObjectName name = null;
        name = new ObjectName(domain + ":type=Group,groupname=" +
                              ObjectName.quote(group.getGroupname()) +
                              ",database=" + group.getUserDatabase().getId());
        return (name);

    
static javax.management.ObjectNamecreateObjectName(java.lang.String domain, org.apache.catalina.Host host)
Create an ObjectName for this Host object.

param
domain Domain in which this name is to be created
param
host The Host to be named
exception
MalformedObjectNameException if a name cannot be created


        ObjectName name = null;
        Engine engine = (Engine)host.getParent();
        Service service = engine.getService();
        name = new ObjectName(domain + ":type=Host,host=" +
                              host.getName());
        return (name);

    
static javax.management.ObjectNamecreateObjectName(java.lang.String domain, org.apache.catalina.Loader loader)
Create an ObjectName for this Loader object.

param
domain Domain in which this name is to be created
param
loader The Loader to be named
exception
MalformedObjectNameException if a name cannot be created


        ObjectName name = null;
        Container container = loader.getContainer();

        if (container instanceof Engine) {
            Service service = ((Engine)container).getService();
            name = new ObjectName(domain + ":type=Loader");
        } else if (container instanceof Host) {
            Engine engine = (Engine) container.getParent();
            Service service = engine.getService();
            name = new ObjectName(domain + ":type=Loader,host=" +
                              container.getName());
        } else if (container instanceof Context) {
            String path = ((Context)container).getPath();
            if (path.length() < 1) {
                path = "/";
            }
            Host host = (Host) container.getParent();
            Engine engine = (Engine) host.getParent();
            Service service = engine.getService();
            name = new ObjectName(domain + ":type=Loader,path=" + path +
                              ",host=" + host.getName());
        }

        return (name);

    
static javax.management.ObjectNamecreateObjectName(java.lang.String domain, org.apache.catalina.Manager manager)
Create an ObjectName for this Manager object.

param
domain Domain in which this name is to be created
param
manager The Manager to be named
exception
MalformedObjectNameException if a name cannot be created


        ObjectName name = null;
        Container container = manager.getContainer();

        if (container instanceof Engine) {
            Service service = ((Engine)container).getService();
            name = new ObjectName(domain + ":type=Manager");
        } else if (container instanceof Host) {
            Engine engine = (Engine) container.getParent();
            Service service = engine.getService();
            name = new ObjectName(domain + ":type=Manager,host=" +
                              container.getName());
        } else if (container instanceof Context) {
            String path = ((Context)container).getPath();
            if (path.length() < 1) {
                path = "/";
            }
            Host host = (Host) container.getParent();
            Engine engine = (Engine) host.getParent();
            Service service = engine.getService();
            name = new ObjectName(domain + ":type=Manager,path=" + path +
                              ",host=" + host.getName());
        }

        return (name);

    
static javax.management.ObjectNamecreateObjectName(java.lang.String domain, org.apache.catalina.deploy.NamingResources resources)
Create an ObjectName for this Server object.

param
domain Domain in which this name is to be created
param
resources The NamingResources to be named
exception
MalformedObjectNameException if a name cannot be created


        ObjectName name = null;
        Object container = resources.getContainer();        
        if (container instanceof Server) {        
            name = new ObjectName(domain + ":type=NamingResources" + 
                        ",resourcetype=Global");
        } else if (container instanceof Context) {        
            String path = ((Context)container).getPath();
            if (path.length() < 1)
                path = "/";
            Host host = (Host) ((Context)container).getParent();
            Engine engine = (Engine) host.getParent();
            Service service = engine.getService();
            name = new ObjectName(domain + ":type=NamingResources" + 
                        ",resourcetype=Context,path=" + path + 
                        ",host=" + host.getName());
        }
        
        return (name);

    
static javax.management.ObjectNamecreateObjectName(java.lang.String domain, MBeanFactory factory)
Create an ObjectName for this MBeanFactory object.

param
domain Domain in which this name is to be created
param
factory The MBeanFactory to be named
exception
MalformedObjectNameException if a name cannot be created


        ObjectName name = new ObjectName(domain + ":type=MBeanFactory");

        return (name);

    
static javax.management.ObjectNamecreateObjectName(java.lang.String domain, org.apache.catalina.Realm realm)
Create an ObjectName for this Realm object.

param
domain Domain in which this name is to be created
param
realm The Realm to be named
exception
MalformedObjectNameException if a name cannot be created


        ObjectName name = null;
        Container container = realm.getContainer();

        if (container instanceof Engine) {
            Service service = ((Engine)container).getService();
            name = new ObjectName(domain + ":type=Realm");
        } else if (container instanceof Host) {
            Engine engine = (Engine) container.getParent();
            Service service = engine.getService();
            name = new ObjectName(domain + ":type=Realm,host=" +
                              container.getName());
        } else if (container instanceof Context) {
            String path = ((Context)container).getPath();
            if (path.length() < 1) {
                path = "/";
            }
            Host host = (Host) container.getParent();
            Engine engine = (Engine) host.getParent();
            Service service = engine.getService();
            name = new ObjectName(domain + ":type=Realm,path=" + path +
                              ",host=" + host.getName());
        }

        return (name);

    
static javax.management.ObjectNamecreateObjectName(java.lang.String domain, org.apache.catalina.Role role)
Create an ObjectName for this Role object.

param
domain Domain in which this name is to be created
param
role The Role to be named
exception
MalformedObjectNameException if a name cannot be created


        ObjectName name = null;
        name = new ObjectName(domain + ":type=Role,rolename=" +
                              role.getRolename() + ",database=" +
                              role.getUserDatabase().getId());
        return (name);

    
static javax.management.ObjectNamecreateObjectName(java.lang.String domain, org.apache.catalina.Server server)
Create an ObjectName for this Server object.

param
domain Domain in which this name is to be created
param
server The Server to be named
exception
MalformedObjectNameException if a name cannot be created


        ObjectName name = null;
        name = new ObjectName(domain + ":type=Server");
        return (name);

    
static javax.management.ObjectNamecreateObjectName(java.lang.String domain, org.apache.catalina.Service service)
Create an ObjectName for this Service object.

param
domain Domain in which this name is to be created
param
service The Service to be named
exception
MalformedObjectNameException if a name cannot be created


        ObjectName name = null;
        name = new ObjectName(domain + ":type=Service,serviceName=" + 
                            service.getName());
        return (name);

    
static javax.management.ObjectNamecreateObjectName(java.lang.String domain, org.apache.catalina.User user)
Create an ObjectName for this User object.

param
domain Domain in which this name is to be created
param
user The User to be named
exception
MalformedObjectNameException if a name cannot be created


        ObjectName name = null;
        name = new ObjectName(domain + ":type=User,username=" +
                              ObjectName.quote(user.getUsername())
                              + ",database=" + user.getUserDatabase().getId());
        return (name);

    
static javax.management.ObjectNamecreateObjectName(java.lang.String domain, org.apache.catalina.UserDatabase userDatabase)
Create an ObjectName for this UserDatabase object.

param
domain Domain in which this name is to be created
param
userDatabase The UserDatabase to be named
exception
MalformedObjectNameException if a name cannot be created


        ObjectName name = null;
        name = new ObjectName(domain + ":type=UserDatabase,database=" +
                              userDatabase.getId());
        return (name);

    
static javax.management.ObjectNamecreateObjectName(java.lang.String domain, org.apache.catalina.Valve valve)
Create an ObjectName for this Valve object.

param
domain Domain in which this name is to be created
param
valve The Valve to be named
exception
MalformedObjectNameException if a name cannot be created

        if( valve instanceof ValveBase ) {
            ObjectName name=((ValveBase)valve).getObjectName();
            if( name != null )
                return name;
        }

        ObjectName name = null;
        Container container = null;
        String className=valve.getClass().getName();
        int period = className.lastIndexOf('.");
        if (period >= 0)
            className = className.substring(period + 1);
        if( valve instanceof Contained ) {
            container = ((Contained)valve).getContainer();
        }
        if( container == null ) {
            throw new MalformedObjectNameException(
                               "Cannot create mbean for non-contained valve " +
                               valve);
        }        
        if (container instanceof Engine) {
            Service service = ((Engine)container).getService();
            String local="";
            int seq = getSeq(local);
            String ext="";
            if( seq > 0 ) {
                ext=",seq=" + seq;
            }
            name = new ObjectName(domain + ":type=Valve,name=" + className + 
                                    ext + local );
        } else if (container instanceof Host) {
            Service service = ((Engine)container.getParent()).getService();
            String local=",host=" +container.getName();
            int seq = getSeq(local);
            String ext="";
            if( seq > 0 ) {
                ext=",seq=" + seq;
            }
            name = new ObjectName(domain + ":type=Valve,name=" + className + 
                                    ext + local );
        } else if (container instanceof Context) {
            String path = ((Context)container).getPath();
            if (path.length() < 1) {
                path = "/";
            }
            Host host = (Host) container.getParent();
            Service service = ((Engine) host.getParent()).getService();
            String local=",path=" + path + ",host=" +
                    host.getName();
            int seq = getSeq(local);
            String ext="";
            if( seq > 0 ) {
                ext=",seq=" + seq;
            }
            name = new ObjectName(domain + ":type=Valve,name=" + className + 
                                    ext + local );
        }

        return (name);

    
public static synchronized org.apache.tomcat.util.modeler.RegistrycreateRegistry()
Create and configure (if necessary) and return the registry of managed object descriptions.


        if (registry == null) {
            registry = Registry.getRegistry(null, null);
            ClassLoader cl=ServerLifecycleListener.class.getClassLoader();

            registry.loadDescriptors("org.apache.catalina.mbeans",  cl);
            registry.loadDescriptors("org.apache.catalina.authenticator", cl);
            registry.loadDescriptors("org.apache.catalina.core", cl);
            registry.loadDescriptors("org.apache.catalina", cl);
            registry.loadDescriptors("org.apache.catalina.deploy", cl);
            registry.loadDescriptors("org.apache.catalina.loader", cl);
            registry.loadDescriptors("org.apache.catalina.realm", cl);
            registry.loadDescriptors("org.apache.catalina.session", cl);
            registry.loadDescriptors("org.apache.catalina.startup", cl);
            registry.loadDescriptors("org.apache.catalina.users", cl);
            registry.loadDescriptors("org.apache.catalina.ha", cl);
            registry.loadDescriptors("org.apache.catalina.connector", cl);
            registry.loadDescriptors("org.apache.catalina.valves",  cl);
        }
        return (registry);

    
public static synchronized javax.management.MBeanServercreateServer()
Create and configure (if necessary) and return the MBeanServer with which we will be registering our DynamicMBean implementations.


        if (mserver == null) {
            try {
                mserver = Registry.getRegistry(null, null).getMBeanServer();
            } catch (Throwable t) {
                t.printStackTrace(System.out);
                System.exit(1);
            }
        }
        return (mserver);

    
static voiddestroyMBean(org.apache.catalina.connector.Connector connector, org.apache.catalina.Service service)
Deregister the MBean for this Connector object.

param
connector The Connector to be managed
exception
Exception if an MBean cannot be deregistered


        connector.setService(service);
        String mname = createManagedName(connector);
        ManagedBean managed = registry.findManagedBean(mname);
        if (managed == null) {
            return;
        }
        String domain = managed.getDomain();
        if (domain == null)
            domain = mserver.getDefaultDomain();
        ObjectName oname = createObjectName(domain, connector);
        connector.setService(null);
        if( mserver.isRegistered( oname ))  {
            mserver.unregisterMBean(oname);
        }
    
static voiddestroyMBean(org.apache.catalina.Context context)
Deregister the MBean for this Context object.

param
context The Context to be managed
exception
Exception if an MBean cannot be deregistered


        String mname = createManagedName(context);
        ManagedBean managed = registry.findManagedBean(mname);
        if (managed == null) {
            return;
        }
        String domain = managed.getDomain();
        if (domain == null)
            domain = mserver.getDefaultDomain();
        ObjectName oname = createObjectName(domain, context);
        if( mserver.isRegistered(oname) )
            mserver.unregisterMBean(oname);

    
static voiddestroyMBean(org.apache.catalina.deploy.ContextEnvironment environment)
Deregister the MBean for this ContextEnvironment object.

param
environment The ContextEnvironment to be managed
exception
Exception if an MBean cannot be deregistered


        String mname = createManagedName(environment);
        ManagedBean managed = registry.findManagedBean(mname);
        if (managed == null) {
            return;
        }
        String domain = managed.getDomain();
        if (domain == null)
            domain = mserver.getDefaultDomain();
        ObjectName oname = createObjectName(domain, environment);
        if( mserver.isRegistered(oname) )
            mserver.unregisterMBean(oname);

    
static voiddestroyMBean(org.apache.catalina.deploy.ContextResource resource)
Deregister the MBean for this ContextResource object.

param
resource The ContextResource to be managed
exception
Exception if an MBean cannot be deregistered


        String mname = createManagedName(resource);
        ManagedBean managed = registry.findManagedBean(mname);
        if (managed == null) {
            return;
        }
        String domain = managed.getDomain();
        if (domain == null)
            domain = mserver.getDefaultDomain();
        ObjectName oname = createObjectName(domain, resource);
        if( mserver.isRegistered(oname ))
            mserver.unregisterMBean(oname);

    
static voiddestroyMBean(org.apache.catalina.deploy.ContextResourceLink resourceLink)
Deregister the MBean for this ContextResourceLink object.

param
resourceLink The ContextResourceLink to be managed
exception
Exception if an MBean cannot be deregistered


        String mname = createManagedName(resourceLink);
        ManagedBean managed = registry.findManagedBean(mname);
        if (managed == null) {
            return;
        }
        String domain = managed.getDomain();
        if (domain == null)
            domain = mserver.getDefaultDomain();
        ObjectName oname = createObjectName(domain, resourceLink);
        if( mserver.isRegistered(oname) )
            mserver.unregisterMBean(oname);

    
static voiddestroyMBean(org.apache.catalina.Engine engine)
Deregister the MBean for this Engine object.

param
engine The Engine to be managed
exception
Exception if an MBean cannot be deregistered


        String mname = createManagedName(engine);
        ManagedBean managed = registry.findManagedBean(mname);
        if (managed == null) {
            return;
        }
        String domain = managed.getDomain();
        if (domain == null)
            domain = mserver.getDefaultDomain();
        ObjectName oname = createObjectName(domain, engine);
        if( mserver.isRegistered(oname) )
            mserver.unregisterMBean(oname);

    
static voiddestroyMBean(org.apache.catalina.Group group)
Deregister the MBean for this Group object.

param
group The Group to be managed
exception
Exception if an MBean cannot be deregistered


        String mname = createManagedName(group);
        ManagedBean managed = registry.findManagedBean(mname);
        if (managed == null) {
            return;
        }
        String domain = managed.getDomain();
        if (domain == null)
            domain = mserver.getDefaultDomain();
        ObjectName oname = createObjectName(domain, group);
        if( mserver.isRegistered(oname) )
            mserver.unregisterMBean(oname);

    
static voiddestroyMBean(org.apache.catalina.Host host)
Deregister the MBean for this Host object.

param
host The Host to be managed
exception
Exception if an MBean cannot be deregistered


        String mname = createManagedName(host);
        ManagedBean managed = registry.findManagedBean(mname);
        if (managed == null) {
            return;
        }
        String domain = managed.getDomain();
        if (domain == null)
            domain = mserver.getDefaultDomain();
        ObjectName oname = createObjectName(domain, host);
        if( mserver.isRegistered(oname) )
            mserver.unregisterMBean(oname);

    
static voiddestroyMBean(org.apache.catalina.Loader loader)
Deregister the MBean for this Loader object.

param
loader The Loader to be managed
exception
Exception if an MBean cannot be deregistered


        String mname = createManagedName(loader);
        ManagedBean managed = registry.findManagedBean(mname);
        if (managed == null) {
            return;
        }
        String domain = managed.getDomain();
        if (domain == null)
            domain = mserver.getDefaultDomain();
        ObjectName oname = createObjectName(domain, loader);
        if( mserver.isRegistered(oname) )
            mserver.unregisterMBean(oname);

    
static voiddestroyMBean(org.apache.catalina.Manager manager)
Deregister the MBean for this Manager object.

param
manager The Manager to be managed
exception
Exception if an MBean cannot be deregistered


        String mname = createManagedName(manager);
        ManagedBean managed = registry.findManagedBean(mname);
        if (managed == null) {
            return;
        }
        String domain = managed.getDomain();
        if (domain == null)
            domain = mserver.getDefaultDomain();
        ObjectName oname = createObjectName(domain, manager);
        if( mserver.isRegistered(oname) )
            mserver.unregisterMBean(oname);

    
static voiddestroyMBean(org.apache.catalina.deploy.NamingResources resources)
Deregister the MBean for this NamingResources object.

param
resources The NamingResources to be managed
exception
Exception if an MBean cannot be deregistered


        String mname = createManagedName(resources);
        ManagedBean managed = registry.findManagedBean(mname);
        if (managed == null) {
            return;
        }
        String domain = managed.getDomain();
        if (domain == null)
            domain = mserver.getDefaultDomain();
        ObjectName oname = createObjectName(domain, resources);
       if( mserver.isRegistered(oname) )
            mserver.unregisterMBean(oname);

    
static voiddestroyMBean(org.apache.catalina.Realm realm)
Deregister the MBean for this Realm object.

param
realm The Realm to be managed
exception
Exception if an MBean cannot be deregistered


        String mname = createManagedName(realm);
        ManagedBean managed = registry.findManagedBean(mname);
        if (managed == null) {
            return;
        }
        String domain = managed.getDomain();
        if (domain == null)
            domain = mserver.getDefaultDomain();
        ObjectName oname = createObjectName(domain, realm);
        if( mserver.isRegistered(oname) )
            mserver.unregisterMBean(oname);

    
static voiddestroyMBean(org.apache.catalina.Role role)
Deregister the MBean for this Role object.

param
role The Role to be managed
exception
Exception if an MBean cannot be deregistered


        String mname = createManagedName(role);
        ManagedBean managed = registry.findManagedBean(mname);
        if (managed == null) {
            return;
        }
        String domain = managed.getDomain();
        if (domain == null)
            domain = mserver.getDefaultDomain();
        ObjectName oname = createObjectName(domain, role);
        if( mserver.isRegistered(oname) )
            mserver.unregisterMBean(oname);

    
static voiddestroyMBean(org.apache.catalina.Server server)
Deregister the MBean for this Server object.

param
server The Server to be managed
exception
Exception if an MBean cannot be deregistered


        String mname = createManagedName(server);
        ManagedBean managed = registry.findManagedBean(mname);
        if (managed == null) {
            return;
        }
        String domain = managed.getDomain();
        if (domain == null)
            domain = mserver.getDefaultDomain();
        ObjectName oname = createObjectName(domain, server);
        if( mserver.isRegistered(oname) )
            mserver.unregisterMBean(oname);

    
static voiddestroyMBean(org.apache.catalina.Service service)
Deregister the MBean for this Service object.

param
service The Service to be managed
exception
Exception if an MBean cannot be deregistered


        String mname = createManagedName(service);
        ManagedBean managed = registry.findManagedBean(mname);
        if (managed == null) {
            return;
        }
        String domain = managed.getDomain();
        if (domain == null)
            domain = mserver.getDefaultDomain();
        ObjectName oname = createObjectName(domain, service);
        if( mserver.isRegistered(oname) )
            mserver.unregisterMBean(oname);

    
static voiddestroyMBean(org.apache.catalina.User user)
Deregister the MBean for this User object.

param
user The User to be managed
exception
Exception if an MBean cannot be deregistered


        String mname = createManagedName(user);
        ManagedBean managed = registry.findManagedBean(mname);
        if (managed == null) {
            return;
        }
        String domain = managed.getDomain();
        if (domain == null)
            domain = mserver.getDefaultDomain();
        ObjectName oname = createObjectName(domain, user);
        if( mserver.isRegistered(oname) )
            mserver.unregisterMBean(oname);

    
static voiddestroyMBean(org.apache.catalina.UserDatabase userDatabase)
Deregister the MBean for this UserDatabase object.

param
userDatabase The UserDatabase to be managed
exception
Exception if an MBean cannot be deregistered


        String mname = createManagedName(userDatabase);
        ManagedBean managed = registry.findManagedBean(mname);
        if (managed == null) {
            return;
        }
        String domain = managed.getDomain();
        if (domain == null)
            domain = mserver.getDefaultDomain();
        ObjectName oname = createObjectName(domain, userDatabase);
        if( mserver.isRegistered(oname) )
            mserver.unregisterMBean(oname);

    
static voiddestroyMBean(org.apache.catalina.Valve valve, org.apache.catalina.Container container)
Deregister the MBean for this Valve object.

param
valve The Valve to be managed
exception
Exception if an MBean cannot be deregistered


        ((Contained)valve).setContainer(container);
        String mname = createManagedName(valve);
        ManagedBean managed = registry.findManagedBean(mname);
        if (managed == null) {
            return;
        }
        String domain = managed.getDomain();
        if (domain == null)
            domain = mserver.getDefaultDomain();
        ObjectName oname = createObjectName(domain, valve);
        try {
            ((Contained)valve).setContainer(null);
        } catch (Throwable t) {
        ;
        }
        if( mserver.isRegistered(oname) ) {
            mserver.unregisterMBean(oname);
        }

    
static intgetSeq(java.lang.String key)

          
        int i[]=(int [])seq.get( key );
        if (i == null ) {
            i=new int[1];
            i[0]=0;
            seq.put( key, i);
        } else {
            i[0]++;
        }
        return i[0];