You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2019/11/14 21:25:25 UTC

[tomcat] branch 7.0.x updated: Align with 8.5.x/9.0.x

This is an automated email from the ASF dual-hosted git repository.

markt pushed a commit to branch 7.0.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git


The following commit(s) were added to refs/heads/7.0.x by this push:
     new f9a5b0d  Align with 8.5.x/9.0.x
f9a5b0d is described below

commit f9a5b0d41a25fc3ac454634049c7d7350c4e92d4
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Thu Nov 14 21:09:13 2019 +0000

    Align with 8.5.x/9.0.x
---
 java/org/apache/tomcat/util/modeler/Registry.java | 509 +++++++++++-----------
 1 file changed, 256 insertions(+), 253 deletions(-)

diff --git a/java/org/apache/tomcat/util/modeler/Registry.java b/java/org/apache/tomcat/util/modeler/Registry.java
index 829bc03..9b92a0c 100644
--- a/java/org/apache/tomcat/util/modeler/Registry.java
+++ b/java/org/apache/tomcat/util/modeler/Registry.java
@@ -14,11 +14,8 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-
-
 package org.apache.tomcat.util.modeler;
 
-
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.InputStream;
@@ -50,19 +47,15 @@ import org.apache.tomcat.util.modeler.modules.ModelerSource;
    - double check the interfaces
    - start removing the use of the experimental methods in tomcat, then remove
      the methods ( before 1.1 final )
-   - is the security enough to prevent Registry being used to avoid the permission
-    checks in the mbean server ?
+   - is the security enough to prevent Registry being used to avoid the
+     permission checks in the mbean server ?
 */
 
 /**
  * Registry for modeler MBeans.
  *
- * This is the main entry point into modeler. It provides methods to create
- * and manipulate model mbeans and simplify their use.
- *
- * Starting with version 1.1, this is no longer a singleton and the static
- * methods are strongly deprecated. In a container environment we can expect
- * different applications to use different registries.
+ * This is the main entry point into modeler. It provides methods to create and
+ * manipulate model mbeans and simplify their use.
  *
  * This class is itself an mbean.
  *
@@ -72,7 +65,8 @@ import org.apache.tomcat.util.modeler.modules.ModelerSource;
  * @author Craig R. McClanahan
  * @author Costin Manolache
  */
-public class Registry implements RegistryMBean, MBeanRegistration  {
+public class Registry implements RegistryMBean, MBeanRegistration {
+
     /**
      * The Log instance to which we will write our log messages.
      */
@@ -85,8 +79,8 @@ public class Registry implements RegistryMBean, MBeanRegistration  {
     private static HashMap<Object,Registry> perLoaderRegistries = null;
 
     /**
-     * The registry instance created by our factory method the first time
-     * it is called.
+     * The registry instance created by our factory method the first time it is
+     * called.
      */
     private static Registry registry = null;
 
@@ -99,11 +93,11 @@ public class Registry implements RegistryMBean, MBeanRegistration  {
     private MBeanServer server = null;
 
     /**
-     * The set of ManagedBean instances for the beans this registry
-     * knows about, keyed by name.
+     * The set of ManagedBean instances for the beans this registry knows about,
+     * keyed by name.
      */
     private HashMap<String,ManagedBean> descriptors =
-        new HashMap<String,ManagedBean>();
+           new HashMap<String,ManagedBean>();
 
     /** List of managed beans, keyed by class name
      */
@@ -124,8 +118,6 @@ public class Registry implements RegistryMBean, MBeanRegistration  {
 
     // ----------------------------------------------------------- Constructors
 
-    /**
-     */
      public Registry() {
         super();
     }
@@ -176,11 +168,10 @@ public class Registry implements RegistryMBean, MBeanRegistration  {
         if (registry == null) {
             registry = new Registry();
         }
-        if( registry.guard != null &&
-                registry.guard != guard ) {
+        if (registry.guard != null && registry.guard != guard) {
             return null;
         }
-        return (registry);
+        return registry;
     }
 
     /**
@@ -197,8 +188,6 @@ public class Registry implements RegistryMBean, MBeanRegistration  {
         }
     }
 
-    // -------------------- Generic methods  --------------------
-
     /** Lifecycle method - clean up the registry metadata.
      *  Called from resetMetadata().
      *
@@ -208,9 +197,10 @@ public class Registry implements RegistryMBean, MBeanRegistration  {
     public void stop() {
         descriptorsByClass = new HashMap<String,ManagedBean>();
         descriptors = new HashMap<String,ManagedBean>();
-        searchedPaths=new HashMap<String,URL>();
+        searchedPaths = new HashMap<String,URL>();
     }
 
+
     /**
      * Load an extended mlet file. The source can be an URL, File or
      * InputStream.
@@ -256,8 +246,9 @@ public class Registry implements RegistryMBean, MBeanRegistration  {
      * "mbeans-descriptors.ser" or "mbeans-descriptors.xml" in the same package
      * or parent.
      *
-     * If the bean is an instance of DynamicMBean. it's metadata will be converted
-     * to a model mbean and we'll wrap it - so modeler services will be supported
+     * If the bean is an instance of DynamicMBean. it's metadata will be
+     * converted to a model mbean and we'll wrap it - so modeler services will
+     * be supported
      *
      * If the metadata is still not found, introspection will be used to extract
      * it automatically.
@@ -265,35 +256,35 @@ public class Registry implements RegistryMBean, MBeanRegistration  {
      * If an mbean is already registered under this name, it'll be first
      * unregistered.
      *
-     * If the component implements MBeanRegistration, the methods will be called.
-     * If the method has a method "setRegistry" that takes a RegistryMBean as
-     * parameter, it'll be called with the current registry.
+     * If the component implements MBeanRegistration, the methods will be
+     * called. If the method has a method "setRegistry" that takes a
+     * RegistryMBean as parameter, it'll be called with the current registry.
      *
      *
      * @param bean Object to be registered
      * @param oname Name used for registration
      * @param type The type of the mbean, as declared in mbeans-descriptors. If
-     * null, the name of the class will be used. This can be used as a hint or
-     * by subclasses.
-     *
+     *            null, the name of the class will be used. This can be used as
+     *            a hint or by subclasses.
+     * @throws Exception if a registration error occurred
      * @since 1.1
      */
     @Override
-    public void registerComponent(Object bean, String oname, String type)
-           throws Exception
-    {
+    public void registerComponent(Object bean, String oname, String type) throws Exception {
         registerComponent(bean, new ObjectName(oname), type);
     }
 
-    /** Unregister a component. We'll first check if it is registered,
-     * and mask all errors. This is mostly a helper.
+
+    /**
+     * Unregister a component. We'll first check if it is registered, and mask
+     * all errors. This is mostly a helper.
      *
-     * @param oname
+     * @param oname Name used for unregistration
      *
      * @since 1.1
      */
     @Override
-    public void unregisterComponent( String oname ) {
+    public void unregisterComponent(String oname) {
         try {
             unregisterComponent(new ObjectName(oname));
         } catch (MalformedObjectNameException e) {
@@ -302,41 +293,42 @@ public class Registry implements RegistryMBean, MBeanRegistration  {
     }
 
 
-    /** Invoke a operation on a list of mbeans. Can be used to implement
+    /**
+     * Invoke a operation on a list of mbeans. Can be used to implement
      * lifecycle operations.
      *
      * @param mbeans list of ObjectName on which we'll invoke the operations
      * @param operation  Name of the operation ( init, start, stop, etc)
      * @param failFirst  If false, exceptions will be ignored
-     * @throws Exception
+     * @throws Exception Error invoking operation
      * @since 1.1
      */
     @Override
-    public void invoke(List<ObjectName> mbeans, String operation,
-            boolean failFirst ) throws Exception {
-        if( mbeans==null ) {
+    public void invoke(List<ObjectName> mbeans, String operation, boolean failFirst)
+            throws Exception {
+
+        if (mbeans == null) {
             return;
         }
-        Iterator<ObjectName> itr = mbeans.iterator();
-        while(itr.hasNext()) {
-            ObjectName current = itr.next();
+        for (ObjectName current : mbeans) {
             try {
-                if(current == null) {
+                if (current == null) {
                     continue;
                 }
-                if(getMethodInfo(current, operation) == null) {
+                if (getMethodInfo(current, operation) == null) {
                     continue;
                 }
-                getMBeanServer().invoke(current, operation,
-                        new Object[] {}, new String[] {});
+                getMBeanServer().invoke(current, operation, new Object[] {}, new String[] {});
 
-            } catch( Exception t ) {
-                if( failFirst ) throw t;
+            } catch (Exception t) {
+                if (failFirst)
+                    throw t;
                 log.info("Error initializing " + current + " " + t.toString());
             }
         }
     }
 
+
     // -------------------- ID registry --------------------
 
     /** Return an int ID for faster access. Will be used for notifications
@@ -348,40 +340,41 @@ public class Registry implements RegistryMBean, MBeanRegistration  {
      * @since 1.1
      */
     @Override
-    public synchronized int getId( String domain, String name) {
-        if( domain==null) {
-            domain="";
+    public synchronized int getId(String domain, String name) {
+        if (domain == null) {
+            domain = "";
         }
-        Hashtable<String,Integer> domainTable = idDomains.get(domain);
-        if( domainTable == null ) {
-            domainTable = new Hashtable<String,Integer>();
-            idDomains.put( domain, domainTable);
+        Hashtable<String, Integer> domainTable = idDomains.get(domain);
+        if (domainTable == null) {
+            domainTable = new Hashtable<String, Integer>();
+            idDomains.put(domain, domainTable);
         }
-        if( name==null ) {
-            name="";
+        if (name == null) {
+            name = "";
         }
         Integer i = domainTable.get(name);
 
-        if( i!= null ) {
+        if (i != null) {
             return i.intValue();
         }
 
         int id[] = ids.get(domain);
-        if( id == null ) {
-            id=new int[1];
-            ids.put( domain, id);
+        if (id == null) {
+            id = new int[1];
+            ids.put(domain, id);
         }
-        int code=id[0]++;
-        domainTable.put( name, Integer.valueOf( code ));
+        int code = id[0]++;
+        domainTable.put(name, Integer.valueOf(code));
         return code;
     }
 
-    // -------------------- Metadata   --------------------
+
+    // -------------------- Metadata --------------------
     // methods from 1.0
 
     /**
-     * Add a new bean metadata to the set of beans known to this registry.
-     * This is used by internal components.
+     * Add a new bean metadata to the set of beans known to this registry. This
+     * is used by internal components.
      *
      * @param bean The managed bean to be added
      * @since 1.0
@@ -389,24 +382,25 @@ public class Registry implements RegistryMBean, MBeanRegistration  {
     public void addManagedBean(ManagedBean bean) {
         // XXX Use group + name
         descriptors.put(bean.getName(), bean);
-        if( bean.getType() != null ) {
-            descriptorsByClass.put( bean.getType(), bean );
+        if (bean.getType() != null) {
+            descriptorsByClass.put(bean.getType(), bean);
         }
     }
 
 
     /**
-     * Find and return the managed bean definition for the specified
-     * bean name, if any; otherwise return <code>null</code>.
+     * Find and return the managed bean definition for the specified bean name,
+     * if any; otherwise return <code>null</code>.
      *
      * @param name Name of the managed bean to be returned. Since 1.1, both
-     *   short names or the full name of the class can be used.
+     *            short names or the full name of the class can be used.
+     * @return the managed bean
      * @since 1.0
      */
     public ManagedBean findManagedBean(String name) {
         // XXX Group ?? Use Group + Type
         ManagedBean mb = descriptors.get(name);
-        if( mb==null )
+        if (mb == null)
             mb = descriptorsByClass.get(name);
         return mb;
     }
@@ -422,6 +416,8 @@ public class Registry implements RegistryMBean, MBeanRegistration  {
     }
 
 
+    // -------------------- Helpers --------------------
+
     /**
      * Return the set of bean names for all managed beans known to
      * this registry that belong to the specified group.
@@ -471,10 +467,9 @@ public class Registry implements RegistryMBean, MBeanRegistration  {
      * @return null if metadata about the attribute is not found
      * @since 1.1
      */
-    public String getType( ObjectName oname, String attName )
-    {
-        String type=null;
-        MBeanInfo info=null;
+    public String getType(ObjectName oname, String attName) {
+        String type = null;
+        MBeanInfo info = null;
         try {
             info=server.getMBeanInfo(oname);
         } catch (Exception e) {
@@ -482,59 +477,64 @@ public class Registry implements RegistryMBean, MBeanRegistration  {
             return null;
         }
 
-        MBeanAttributeInfo attInfo[]=info.getAttributes();
-        for( int i=0; i<attInfo.length; i++ ) {
-            if( attName.equals(attInfo[i].getName())) {
-                type=attInfo[i].getType();
+        MBeanAttributeInfo attInfo[] = info.getAttributes();
+        for (int i = 0; i < attInfo.length; i++) {
+            if (attName.equals(attInfo[i].getName())) {
+                type = attInfo[i].getType();
                 return type;
             }
         }
         return null;
     }
 
-    /** Find the operation info for a method
+
+    /**
+     * Find the operation info for a method
      *
-     * @param oname
-     * @param opName
+     * @param oname The bean name
+     * @param opName The operation name
      * @return the operation info for the specified operation
      */
-    public MBeanOperationInfo getMethodInfo( ObjectName oname, String opName )
-    {
-        MBeanInfo info=null;
+    public MBeanOperationInfo getMethodInfo(ObjectName oname, String opName) {
+        MBeanInfo info = null;
         try {
-            info=server.getMBeanInfo(oname);
+            info = server.getMBeanInfo(oname);
         } catch (Exception e) {
             log.info( "Can't find metadata " + oname );
             return null;
         }
-        MBeanOperationInfo attInfo[]=info.getOperations();
-        for( int i=0; i<attInfo.length; i++ ) {
-            if( opName.equals(attInfo[i].getName())) {
+        MBeanOperationInfo attInfo[] = info.getOperations();
+        for (int i = 0; i < attInfo.length; i++) {
+            if (opName.equals(attInfo[i].getName())) {
                 return attInfo[i];
             }
         }
         return null;
     }
 
-    /** Unregister a component. This is just a helper that
-     * avoids exceptions by checking if the mbean is already registered
+
+    /**
+     * Unregister a component. This is just a helper that avoids exceptions by
+     * checking if the mbean is already registered
      *
-     * @param oname
+     * @param oname The bean name
      */
-    public void unregisterComponent( ObjectName oname ) {
+    public void unregisterComponent(ObjectName oname) {
         try {
-            if( getMBeanServer().isRegistered(oname)) {
+            if (oname != null && getMBeanServer().isRegistered(oname)) {
                 getMBeanServer().unregisterMBean(oname);
             }
-        } catch( Throwable t ) {
-            log.error( "Error unregistering mbean ", t);
+        } catch (Throwable t) {
+            log.error("Error unregistering mbean", t);
         }
     }
 
+
     /**
      * Factory method to create (if necessary) and return our
      * <code>MBeanServer</code> instance.
      *
+     * @return the MBean server
      */
     public synchronized MBeanServer getMBeanServer() {
         long t1=System.currentTimeMillis();
@@ -552,142 +552,146 @@ public class Registry implements RegistryMBean, MBeanRegistration  {
                 }
             }
         }
-        return (server);
+        return server;
     }
 
-    /** Find or load metadata.
+
+    /**
+     * Find or load metadata.
+     *
+     * @param bean The bean
+     * @param beanClass The bean class
+     * @param type The registry type
+     * @return the managed bean
+     * @throws Exception An error occurred
      */
-    public ManagedBean findManagedBean(Object bean, Class<?> beanClass,
-            String type) throws Exception {
-        if( bean!=null && beanClass==null ) {
-            beanClass=bean.getClass();
+    public ManagedBean findManagedBean(Object bean, Class<?> beanClass, String type)
+            throws Exception {
+
+        if (bean != null && beanClass == null) {
+            beanClass = bean.getClass();
         }
 
-        if( type==null ) {
-            type=beanClass.getName();
+        if (type == null) {
+            type = beanClass.getName();
         }
 
         // first look for existing descriptor
         ManagedBean managed = findManagedBean(type);
 
         // Search for a descriptor in the same package
-        if( managed==null ) {
+        if (managed == null) {
             // check package and parent packages
-            if( log.isDebugEnabled() ) {
-                log.debug( "Looking for descriptor ");
+            if (log.isDebugEnabled()) {
+                log.debug("Looking for descriptor ");
             }
-            findDescriptor( beanClass, type );
+            findDescriptor(beanClass, type);
 
-            managed=findManagedBean(type);
+            managed = findManagedBean(type);
         }
 
         // Still not found - use introspection
-        if( managed==null ) {
-            if( log.isDebugEnabled() ) {
-                log.debug( "Introspecting ");
+        if (managed == null) {
+            if (log.isDebugEnabled()) {
+                log.debug("Introspecting ");
             }
 
             // introspection
-            loadDescriptors("MbeansDescriptorsIntrospectionSource",
-                    beanClass, type);
+            load("MbeansDescriptorsIntrospectionSource", beanClass, type);
 
-            managed=findManagedBean(type);
-            if( managed==null ) {
+            managed = findManagedBean(type);
+            if (managed == null) {
                 log.warn( "No metadata found for " + type );
                 return null;
             }
-            managed.setName( type );
+            managed.setName(type);
             addManagedBean(managed);
         }
         return managed;
     }
 
 
-    /** EXPERIMENTAL Convert a string to object, based on type. Used by several
-     * components. We could provide some pluggability. It is here to keep
-     * things consistent and avoid duplication in other tasks
+    /**
+     * EXPERIMENTAL Convert a string to object, based on type. Used by several
+     * components. We could provide some pluggability. It is here to keep things
+     * consistent and avoid duplication in other tasks
      *
      * @param type Fully qualified class name of the resulting value
      * @param value String value to be converted
      * @return Converted value
      */
-    public Object convertValue(String type, String value)
-    {
-        Object objValue=value;
+    public Object convertValue(String type, String value) {
+        Object objValue = value;
 
-        if( type==null || "java.lang.String".equals( type )) {
+        if (type == null || "java.lang.String".equals(type)) {
             // string is default
-            objValue=value;
-        } else if( "javax.management.ObjectName".equals( type ) ||
-                "ObjectName".equals( type )) {
+            objValue = value;
+        } else if ("javax.management.ObjectName".equals(type) || "ObjectName".equals(type)) {
             try {
-                objValue=new ObjectName( value );
+                objValue = new ObjectName(value);
             } catch (MalformedObjectNameException e) {
                 return null;
             }
-        } else if( "java.lang.Integer".equals( type ) ||
-                "int".equals( type )) {
-            objValue=Integer.valueOf( value );
-        } else if( "java.lang.Long".equals( type ) ||
-                "long".equals( type )) {
-            objValue=Long.valueOf( value );
-        } else if( "java.lang.Boolean".equals( type ) ||
-                "boolean".equals( type )) {
-            objValue=Boolean.valueOf( value );
+        } else if ("java.lang.Integer".equals(type) || "int".equals(type)) {
+            objValue = Integer.valueOf(value);
+        } else if ("java.lang.Long".equals(type) || "long".equals(type)) {
+            objValue = Long.valueOf(value);
+        } else if ("java.lang.Boolean".equals(type) || "boolean".equals(type)) {
+            objValue = Boolean.valueOf(value);
         }
         return objValue;
     }
 
-    /** Experimental.
+
+    /**
+     * Experimental. Load descriptors.
      *
-     * @param sourceType
-     * @param source
-     * @param param
+     * @param sourceType The source type
+     * @param source The bean
+     * @param param A type to load
      * @return List of descriptors
-     * @throws Exception
-     */
-    public List<ObjectName> load( String sourceType, Object source,
-            String param) throws Exception {
-        if( log.isTraceEnabled()) {
-            log.trace("load " + source );
-        }
-        String location=null;
-        String type=null;
-        Object inputsource=null;
-
-        if( source instanceof URL ) {
-            URL url=(URL)source;
-            location=url.toString();
-            type=param;
-            inputsource=url.openStream();
-            if( sourceType == null ) {
+     * @throws Exception Error loading descriptors
+     */
+    public List<ObjectName> load(String sourceType, Object source, String param) throws Exception {
+        if (log.isTraceEnabled()) {
+            log.trace("load " + source);
+        }
+        String location = null;
+        String type = null;
+        Object inputsource = null;
+
+        if (source instanceof URL) {
+            URL url = (URL) source;
+            location = url.toString();
+            type = param;
+            inputsource = url.openStream();
+            if (sourceType == null)  {
                 sourceType = sourceTypeFromExt(location);
             }
-        } else if( source instanceof File ) {
-            location=((File)source).getAbsolutePath();
-            inputsource=new FileInputStream((File)source);
-            type=param;
-            if( sourceType == null ) {
+        } else if (source instanceof File) {
+            location = ((File) source).getAbsolutePath();
+            inputsource = new FileInputStream((File) source);
+            type = param;
+            if (sourceType == null) {
                 sourceType = sourceTypeFromExt(location);
             }
-        } else if( source instanceof InputStream ) {
-            type=param;
-            inputsource=source;
-        } else if( source instanceof Class<?> ) {
-            location=((Class<?>)source).getName();
-            type=param;
-            inputsource=source;
-            if( sourceType== null ) {
-                sourceType="MbeansDescriptorsIntrospectionSource";
+        } else if (source instanceof InputStream) {
+            type = param;
+            inputsource = source;
+        } else if (source instanceof Class<?>) {
+            location = ((Class<?>) source).getName();
+            type = param;
+            inputsource = source;
+            if (sourceType == null) {
+                sourceType = "MbeansDescriptorsIntrospectionSource";
             }
         }
 
-        if( sourceType==null ) {
-            sourceType="MbeansDescriptorsDigesterSource";
+        if (sourceType == null) {
+            sourceType = "MbeansDescriptorsDigesterSource";
         }
-        ModelerSource ds=getModelerSource(sourceType);
-        List<ObjectName> mbeans =
-            ds.loadDescriptors(this, type, inputsource);
+        ModelerSource ds = getModelerSource(sourceType);
+        List<ObjectName> mbeans = ds.loadDescriptors(this, type, inputsource);
 
         return mbeans;
     }
@@ -702,29 +706,27 @@ public class Registry implements RegistryMBean, MBeanRegistration  {
         return null;
     }
 
-    /** Register a component
-     * XXX make it private
+    /**
+     * Register a component
      *
-     * @param bean
-     * @param oname
-     * @param type
-     * @throws Exception
+     * @param bean The bean
+     * @param oname The object name
+     * @param type The registry type
+     * @throws Exception Error registering component
      */
-    public void registerComponent(Object bean, ObjectName oname, String type)
-           throws Exception
-    {
-        if( log.isDebugEnabled() ) {
-            log.debug( "Managed= "+ oname);
+    public void registerComponent(Object bean, ObjectName oname, String type) throws Exception {
+        if (log.isDebugEnabled()) {
+            log.debug("Managed= " + oname);
         }
 
-        if( bean ==null ) {
+        if (bean == null) {
             log.error("Null component " + oname );
             return;
         }
 
         try {
-            if( type==null ) {
-                type=bean.getClass().getName();
+            if (type == null) {
+                type = bean.getClass().getName();
             }
 
             ManagedBean managed = findManagedBean(bean.getClass(), type);
@@ -732,40 +734,43 @@ public class Registry implements RegistryMBean, MBeanRegistration  {
             // The real mbean is created and registered
             DynamicMBean mbean = managed.createMBean(bean);
 
-            if(  getMBeanServer().isRegistered( oname )) {
-                if( log.isDebugEnabled()) {
-                    log.debug("Unregistering existing component " + oname );
+            if (getMBeanServer().isRegistered(oname)) {
+                if (log.isDebugEnabled()) {
+                    log.debug("Unregistering existing component " + oname);
                 }
-                getMBeanServer().unregisterMBean( oname );
+                getMBeanServer().unregisterMBean(oname);
             }
 
-            getMBeanServer().registerMBean( mbean, oname);
-        } catch( Exception ex) {
+            getMBeanServer().registerMBean(mbean, oname);
+        } catch (Exception ex) {
             log.error("Error registering " + oname, ex );
             throw ex;
         }
     }
 
-    /** Lookup the component descriptor in the package and
-     * in the parent packages.
+
+    /**
+     * Lookup the component descriptor in the package and in the parent
+     * packages.
      *
-     * @param packageName
+     * @param packageName The package name
+     * @param classLoader The class loader
      */
-    public void loadDescriptors( String packageName, ClassLoader classLoader  ) {
-        String res=packageName.replace( '.', '/');
+    public void loadDescriptors(String packageName, ClassLoader classLoader) {
+        String res = packageName.replace('.', '/');
 
-        if( log.isTraceEnabled() ) {
-            log.trace("Finding descriptor " + res );
+        if (log.isTraceEnabled()) {
+            log.trace("Finding descriptor " + res);
         }
 
-        if( searchedPaths.get( packageName ) != null ) {
+        if (searchedPaths.get(packageName) != null) {
             return;
         }
-        String descriptors=res + "/mbeans-descriptors.ser";
 
-        URL dURL=classLoader.getResource( descriptors );
+        String descriptors = res + "/mbeans-descriptors.ser";
+        URL dURL = classLoader.getResource(descriptors);
 
-        if( dURL == null ) {
+        if (dURL == null) {
             descriptors=res + "/mbeans-descriptors.xml";
             dURL=classLoader.getResource( descriptors );
         }
@@ -773,10 +778,10 @@ public class Registry implements RegistryMBean, MBeanRegistration  {
             return;
         }
 
-        log.debug( "Found " + dURL);
-        searchedPaths.put( packageName,  dURL );
+        log.debug("Found " + dURL);
+        searchedPaths.put(packageName, dURL);
         try {
-            if( descriptors.endsWith(".xml" ))
+            if (descriptors.endsWith(".xml"))
                 loadDescriptors("MbeansDescriptorsDigesterSource", dURL, null);
             else
                 loadDescriptors("MbeansDescriptorsSerSource", dURL, null);
@@ -784,8 +789,6 @@ public class Registry implements RegistryMBean, MBeanRegistration  {
         } catch(Exception ex ) {
             log.error("Error loading " + dURL);
         }
-
-        return;
     }
 
     /**
@@ -800,73 +803,73 @@ public class Registry implements RegistryMBean, MBeanRegistration  {
         load(sourceType, source, param);
     }
 
-    /** Lookup the component descriptor in the package and
-     * in the parent packages.
-     *
-     * @param beanClass
-     * @param type
+
+    /**
+     * Lookup the component descriptor in the package and in the parent
+     * packages.
      */
     private void findDescriptor(Class<?> beanClass, String type) {
-        if( type==null ) {
-            type=beanClass.getName();
+        if (type == null) {
+            type = beanClass.getName();
         }
-        ClassLoader classLoader=null;
-        if( beanClass!=null ) {
-            classLoader=beanClass.getClassLoader();
+        ClassLoader classLoader = null;
+        if (beanClass != null) {
+            classLoader = beanClass.getClassLoader();
         }
-        if( classLoader==null ) {
-            classLoader=Thread.currentThread().getContextClassLoader();
+        if (classLoader == null) {
+            classLoader = Thread.currentThread().getContextClassLoader();
         }
-        if( classLoader==null ) {
-            classLoader=this.getClass().getClassLoader();
+        if (classLoader == null) {
+            classLoader = this.getClass().getClassLoader();
         }
 
-        String className=type;
-        String pkg=className;
-        while( pkg.indexOf( ".") > 0 ) {
-            int lastComp=pkg.lastIndexOf( ".");
-            if( lastComp <= 0 ) return;
-            pkg=pkg.substring(0, lastComp);
-            if( searchedPaths.get( pkg ) != null ) {
+        String className = type;
+        String pkg = className;
+        while (pkg.indexOf(".") > 0) {
+            int lastComp = pkg.lastIndexOf(".");
+            if (lastComp <= 0)
+                return;
+            pkg = pkg.substring(0, lastComp);
+            if (searchedPaths.get(pkg) != null) {
                 return;
             }
             loadDescriptors(pkg, classLoader);
         }
-        return;
     }
 
-    private ModelerSource getModelerSource( String type )
-            throws Exception
-    {
-        if( type==null ) type="MbeansDescriptorsDigesterSource";
-        if( type.indexOf( ".") < 0 ) {
-            type="org.apache.tomcat.util.modeler.modules." + type;
+
+    private ModelerSource getModelerSource(String type) throws Exception {
+        if (type == null)
+            type = "MbeansDescriptorsDigesterSource";
+        if (!type.contains(".")) {
+            type = "org.apache.tomcat.util.modeler.modules." + type;
         }
 
         Class<?> c = Class.forName(type);
-        ModelerSource ds=(ModelerSource)c.newInstance();
+        ModelerSource ds = (ModelerSource) c.getConstructor().newInstance();
         return ds;
     }
 
 
-    // -------------------- Registration  --------------------
+    // -------------------- Registration --------------------
 
     @Override
-    public ObjectName preRegister(MBeanServer server,
-                                  ObjectName name) throws Exception
-    {
+    public ObjectName preRegister(MBeanServer server, ObjectName name) throws Exception {
         this.server=server;
         return name;
     }
 
+
     @Override
     public void postRegister(Boolean registrationDone) {
     }
 
+
     @Override
     public void preDeregister() throws Exception {
     }
 
+
     @Override
     public void postDeregister() {
     }


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org