amyroh      02/05/03 16:44:16

  Modified:    catalina/src/share/org/apache/catalina/mbeans
                        MBeanUtils.java
  Log:
  Add create, destroy, and createObjectName for NamingResources,
  ContextEnvironment, and ContextResource MBeans.
  
  Revision  Changes    Path
  1.35      +231 -4    
jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/mbeans/MBeanUtils.java
  
  Index: MBeanUtils.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/mbeans/MBeanUtils.java,v
  retrieving revision 1.34
  retrieving revision 1.35
  diff -u -r1.34 -r1.35
  --- MBeanUtils.java   18 Apr 2002 00:13:07 -0000      1.34
  +++ MBeanUtils.java   3 May 2002 23:44:15 -0000       1.35
  @@ -1,7 +1,7 @@
   /*
  - * $Header: 
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/mbeans/MBeanUtils.java,v
 1.34 2002/04/18 00:13:07 amyroh Exp $
  - * $Revision: 1.34 $
  - * $Date: 2002/04/18 00:13:07 $
  + * $Header: 
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/mbeans/MBeanUtils.java,v
 1.35 2002/05/03 23:44:15 amyroh Exp $
  + * $Revision: 1.35 $
  + * $Date: 2002/05/03 23:44:15 $
    *
    * ====================================================================
    *
  @@ -99,6 +99,10 @@
   import org.apache.catalina.Valve;
   import org.apache.catalina.connector.http.HttpConnector;
   import org.apache.catalina.core.StandardService;
  +import org.apache.catalina.deploy.ContextEnvironment;
  +import org.apache.catalina.deploy.ContextResource;
  +import org.apache.catalina.deploy.NamingResources;
  +import org.apache.catalina.deploy.ResourceParams;
   import org.apache.catalina.valves.ValveBase;
   import org.apache.commons.beanutils.PropertyUtils;
   import org.apache.commons.modeler.ManagedBean;
  @@ -110,7 +114,7 @@
    *
    * @author Craig R. McClanahan
    * @author Amy Roh
  - * @version $Revision: 1.34 $ $Date: 2002/04/18 00:13:07 $
  + * @version $Revision: 1.35 $ $Date: 2002/05/03 23:44:15 $
    */
   
   public class MBeanUtils {
  @@ -245,9 +249,65 @@
   
       }
   
  +    
  +    /**
  +     * Create, register, and return an MBean for this
  +     * <code>ContextEnvironment</code> object.
  +     *
  +     * @param environment The ContextEnvironment to be managed
  +     *
  +     * @exception Exception if an MBean cannot be created or registered
  +     */
  +    public static ModelMBean createMBean(ContextEnvironment environment)
  +        throws Exception {
  +
  +        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();
  +        ModelMBean mbean = managed.createMBean(environment);
  +        ObjectName oname = createObjectName(domain, environment);
  +        mserver.registerMBean(mbean, oname);
  +        return (mbean);
  +
  +    }
  +
   
       /**
        * Create, register, and return an MBean for this
  +     * <code>ContextResource</code> object.
  +     *
  +     * @param resource The ContextResource to be managed
  +     *
  +     * @exception Exception if an MBean cannot be created or registered
  +     */
  +    public static ModelMBean createMBean(ContextResource resource)
  +        throws Exception {
  +
  +        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();
  +        ModelMBean mbean = managed.createMBean(resource);
  +        ObjectName oname = createObjectName(domain, resource);
  +        mserver.registerMBean(mbean, oname);
  +        return (mbean);
  +
  +    }
  +    
  +    
  +    /**
  +     * Create, register, and return an MBean for this
        * <code>DefaultContext</code> object.
        *
        * @param context The DefaultContext to be managed
  @@ -471,6 +531,34 @@
   
       /**
        * Create, register, and return an MBean for this
  +     * <code>NamingResources</code> object.
  +     *
  +     * @param resource The NamingResources to be managed
  +     *
  +     * @exception Exception if an MBean cannot be created or registered
  +     */
  +    public static ModelMBean createMBean(NamingResources resource)
  +        throws Exception {
  +
  +        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();
  +        ModelMBean mbean = managed.createMBean(resource);
  +        ObjectName oname = createObjectName(domain, resource);
  +        mserver.registerMBean(mbean, oname);
  +        return (mbean);
  +
  +    }
  +
  +    
  +    /**
  +     * Create, register, and return an MBean for this
        * <code>Realm</code> object.
        *
        * @param realm The Realm to be managed
  @@ -776,7 +864,50 @@
   
       }
   
  +    
  +    /**
  +     * Create an <code>ObjectName</code> for this
  +     * <code>Service</code> object.
  +     *
  +     * @param domain Domain in which this name is to be created
  +     * @param context The ContextEnvironment to be named
  +     *
  +     * @exception MalformedObjectNameException if a name cannot be created
  +     */
  +    public static ObjectName createObjectName(String domain,
  +                                              ContextEnvironment environment)
  +        throws MalformedObjectNameException {
  +
  +        ObjectName name = null;
  +        name = new ObjectName(domain + ":type=Environment,name=" +
  +                              environment.getName());
  +        return (name);
   
  +    }
  +    
  +    
  +    /**
  +     * Create an <code>ObjectName</code> for this
  +     * <code>Service</code> 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
  +     */
  +    public static ObjectName createObjectName(String domain,
  +                                              ContextResource resource)
  +        throws MalformedObjectNameException {
  +
  +        ObjectName name = null;
  +        name = new ObjectName(domain + ":type=Resource,class=" +
  +                              resource.getType()+",name=" +
  +                              resource.getName());
  +        return (name);
  +
  +    }
  +    
  +    
       /**
        * Create an <code>ObjectName</code> for this
        * <code>DefaultContext</code> object.
  @@ -1006,6 +1137,26 @@
           return (name);
   
       }
  +    
  +    
  +    /**
  +     * Create an <code>ObjectName</code> for this
  +     * <code>Server</code> object.
  +     *
  +     * @param domain Domain in which this name is to be created
  +     * @param resource The NamingResources to be named
  +     *
  +     * @exception MalformedObjectNameException if a name cannot be created
  +     */
  +    public static ObjectName createObjectName(String domain,
  +                                              NamingResources resource)
  +        throws MalformedObjectNameException {
  +
  +        ObjectName name = null;
  +        name = new ObjectName(domain + ":type=NamingResources");
  +        return (name);
  +
  +    }
   
   
       /**
  @@ -1321,7 +1472,57 @@
   
       }
   
  +    
  +    /**
  +     * Deregister the MBean for this
  +     * <code>ContextEnvironment</code> object.
  +     *
  +     * @param environment The ContextEnvironment to be managed
  +     *
  +     * @exception Exception if an MBean cannot be deregistered
  +     */
  +    public static void destroyMBean(ContextEnvironment environment)
  +        throws Exception {
  +
  +        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);
  +        mserver.unregisterMBean(oname);
  +
  +    }
  +    
  +    
  +    /**
  +     * Deregister the MBean for this
  +     * <code>ContextResource</code> object.
  +     *
  +     * @param resource The ContextResource to be managed
  +     *
  +     * @exception Exception if an MBean cannot be deregistered
  +     */
  +    public static void destroyMBean(ContextResource resource)
  +        throws Exception {
  +
  +        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);
  +        mserver.unregisterMBean(oname);
   
  +    }
  +    
  +    
       /**
        * Deregister the MBean for this
        * <code>DefaultContext</code> object.
  @@ -1495,7 +1696,33 @@
           mserver.unregisterMBean(oname);
   
       }
  +    
  +    
  +   /**
  +     * Deregister the MBean for this
  +     * <code>NamingResources</code> object.
  +     *
  +     * @param resource The NamingResources to be managed
  +     *
  +     * @exception Exception if an MBean cannot be deregistered
  +     */
  +    public static void destroyMBean(NamingResources resource)
  +        throws Exception {
  +
  +        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);
  +        mserver.unregisterMBean(oname);
   
  +    }
  +    
  +    
       /**
        * Deregister the MBean for this
        * <code>Realm</code> object.
  
  
  

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to