Generics changes for o.a.t.util.modeler
authormarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Tue, 18 Nov 2008 00:47:36 +0000 (00:47 +0000)
committermarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Tue, 18 Nov 2008 00:47:36 +0000 (00:47 +0000)
These changes identified a bunch of issues, the most serious of which was the loadDescriptors() method that sometimes returned List<ObjectName> and sometimes List<ManagedBean>. Some callers expected this, some didn't.
There are comments in the code identifying this as an issue. The fix I applied aligns with some commented out code that may have been part of an intended fix. There are still some deprecated methods that need to be cleaned up.
With these changes Tomcat starts without error and JConsole shows all the mbeans I expect to see.
There is plenty of further clean-up required here but I'll do that separately after the generics.

git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@718452 13f79535-47bb-0310-9956-ffa450edef68

15 files changed:
java/org/apache/catalina/core/StandardEngine.java
java/org/apache/tomcat/util/modeler/BaseAttributeFilter.java
java/org/apache/tomcat/util/modeler/BaseModelMBean.java
java/org/apache/tomcat/util/modeler/BaseNotificationBroadcaster.java
java/org/apache/tomcat/util/modeler/FixedNotificationFilter.java
java/org/apache/tomcat/util/modeler/ManagedBean.java
java/org/apache/tomcat/util/modeler/Registry.java
java/org/apache/tomcat/util/modeler/RegistryMBean.java
java/org/apache/tomcat/util/modeler/modules/MbeansDescriptorsDOMSource.java
java/org/apache/tomcat/util/modeler/modules/MbeansDescriptorsDigesterSource.java
java/org/apache/tomcat/util/modeler/modules/MbeansDescriptorsIntrospectionSource.java
java/org/apache/tomcat/util/modeler/modules/MbeansDescriptorsSerSource.java
java/org/apache/tomcat/util/modeler/modules/MbeansSource.java
java/org/apache/tomcat/util/modeler/modules/MbeansSourceMBean.java
java/org/apache/tomcat/util/modeler/modules/ModelerSource.java

index e6f01a8..d4be838 100644 (file)
@@ -115,7 +115,7 @@ public class StandardEngine
     
     /** Mbeans loaded by the engine.  
      */ 
-    private List mbeans;
+    private List<ObjectName> mbeans;
     
 
     /**
@@ -382,7 +382,7 @@ public class StandardEngine
             try {
                 for( int i=0; i<mbeans.size() ; i++ ) {
                     Registry.getRegistry(null, null)
-                        .unregisterComponent((ObjectName)mbeans.get(i));
+                            .unregisterComponent(mbeans.get(i));
                 }
             } catch (Exception e) {
                 log.error(sm.getString("standardEngine.unregister.mbeans.failed", mbeansFile), e);
index a142c08..a2b9ce0 100644 (file)
@@ -65,7 +65,7 @@ public class BaseAttributeFilter implements NotificationFilter {
      * The set of attribute names that are accepted by this filter.  If this
      * list is empty, all attribute names are accepted.
      */
-    private HashSet names = new HashSet();
+    private HashSet<String> names = new HashSet<String>();
 
 
     // --------------------------------------------------------- Public Methods
@@ -106,7 +106,7 @@ public class BaseAttributeFilter implements NotificationFilter {
     public String[] getNames() {
 
         synchronized (names) {
-            return ((String[]) names.toArray(new String[names.size()]));
+            return names.toArray(new String[names.size()]);
         }
 
     }
index 924964e..e4192a0 100644 (file)
@@ -143,8 +143,8 @@ public class BaseModelMBean implements DynamicMBean, MBeanRegistration, ModelMBe
 
     // --------------------------------------------------- DynamicMBean Methods
     // TODO: move to ManagedBean
-    static final Object[] NO_ARGS_PARAM=new Object[0];
-    static final Class[] NO_ARGS_PARAM_SIG=new Class[0];
+    static final Object[] NO_ARGS_PARAM = new Object[0];
+    static final Class<?>[] NO_ARGS_PARAM_SIG = new Class[0];
     
     protected String resourceType = null;
 
@@ -180,7 +180,7 @@ public class BaseModelMBean implements DynamicMBean, MBeanRegistration, ModelMBe
         Method m=managedBean.getGetter(name, this, resource);
         Object result = null;
         try {
-            Class declaring=m.getDeclaringClass();
+            Class<?> declaring = m.getDeclaringClass();
             // workaround for catalina weird mbeans - the declaring class is BaseModelMBean.
             // but this is the catalina class.
             if( declaring.isAssignableFrom(this.getClass()) ) {
@@ -322,7 +322,7 @@ public class BaseModelMBean implements DynamicMBean, MBeanRegistration, ModelMBe
 
     }
 
-    static Class getAttributeClass(String signature)
+    static Class<?> getAttributeClass(String signature)
         throws ReflectionException
     {
         if (signature.equals(Boolean.TYPE.getName()))
@@ -467,7 +467,7 @@ public class BaseModelMBean implements DynamicMBean, MBeanRegistration, ModelMBe
         // Prepare and return our response, eating all exceptions
         String names[] = new String[attributes.size()];
         int n = 0;
-        Iterator items = attributes.iterator();
+        Iterator<?> items = attributes.iterator();
         while (items.hasNext()) {
             Attribute item = (Attribute) items.next();
             names[n++] = item.getName();
index 31b54a7..860e630 100644 (file)
@@ -53,7 +53,8 @@ public class BaseNotificationBroadcaster implements NotificationBroadcaster {
      * The set of registered <code>BaseNotificationBroadcasterEntry</code>
      * entries.
      */
-    protected ArrayList entries = new ArrayList();
+    protected ArrayList<BaseNotificationBroadcasterEntry> entries =
+        new ArrayList<BaseNotificationBroadcasterEntry>();
 
 
     // --------------------------------------------------------- Public Methods
@@ -80,10 +81,10 @@ public class BaseNotificationBroadcaster implements NotificationBroadcaster {
             // Optimization to coalesce attribute name filters
             if (filter instanceof BaseAttributeFilter) {
                 BaseAttributeFilter newFilter = (BaseAttributeFilter) filter;
-                Iterator items = entries.iterator();
+                Iterator<BaseNotificationBroadcasterEntry> items =
+                    entries.iterator();
                 while (items.hasNext()) {
-                    BaseNotificationBroadcasterEntry item =
-                        (BaseNotificationBroadcasterEntry) items.next();
+                    BaseNotificationBroadcasterEntry item = items.next();
                     if ((item.listener == listener) &&
                         (item.filter != null) &&
                         (item.filter instanceof BaseAttributeFilter) &&
@@ -137,10 +138,10 @@ public class BaseNotificationBroadcaster implements NotificationBroadcaster {
         throws ListenerNotFoundException {
 
         synchronized (entries) {
-            Iterator items = entries.iterator();
+            Iterator<BaseNotificationBroadcasterEntry> items =
+                entries.iterator();
             while (items.hasNext()) {
-                BaseNotificationBroadcasterEntry item =
-                    (BaseNotificationBroadcasterEntry) items.next();
+                BaseNotificationBroadcasterEntry item = items.next();
                 if (item.listener == listener)
                     items.remove();
             }
@@ -200,10 +201,10 @@ public class BaseNotificationBroadcaster implements NotificationBroadcaster {
     public void sendNotification(Notification notification) {
 
         synchronized (entries) {
-            Iterator items = entries.iterator();
+            Iterator<BaseNotificationBroadcasterEntry> items =
+                entries.iterator();
             while (items.hasNext()) {
-                BaseNotificationBroadcasterEntry item =
-                    (BaseNotificationBroadcasterEntry) items.next();
+                BaseNotificationBroadcasterEntry item = items.next();
                 if ((item.filter != null) &&
                     (!item.filter.isNotificationEnabled(notification)))
                     continue;
index a08806f..aecb640 100644 (file)
@@ -44,7 +44,7 @@ public class FixedNotificationFilter implements NotificationFilter {
      * The set of attribute names that are accepted by this filter.  If this
      * list is empty, all attribute names are accepted.
      */
-    private HashSet names = new HashSet();
+    private HashSet<String> names = new HashSet<String>();
     String namesA[]=null;
 
     /**
@@ -64,7 +64,7 @@ public class FixedNotificationFilter implements NotificationFilter {
      */
     public String[] getNames() {
         synchronized (names) {
-            return ((String[]) names.toArray(new String[names.size()]));
+            return names.toArray(new String[names.size()]);
         }
     }
 
index 575c152..05d3090 100644 (file)
@@ -50,8 +50,8 @@ public class ManagedBean implements java.io.Serializable
 {
     private static final String BASE_MBEAN = "org.apache.tomcat.util.modeler.BaseModelMBean";
     // ----------------------------------------------------- Instance Variables
-    static final Object[] NO_ARGS_PARAM=new Object[0];
-    static final Class[] NO_ARGS_PARAM_SIG=new Class[0];
+    static final Object[] NO_ARGS_PARAM = new Object[0];
+    static final Class<?>[] NO_ARGS_PARAM_SIG = new Class[0];
 
 
     /**
@@ -59,10 +59,12 @@ public class ManagedBean implements java.io.Serializable
      * to this <code>ManagedBean</code> instance.
      */
     transient MBeanInfo info = null;
-    // Map<AttributeInfo>
-    private Map attributes = new HashMap();
-    //Map<OperationInfo>
-    private Map operations = new HashMap();
+
+    private Map<String,AttributeInfo> attributes =
+        new HashMap<String,AttributeInfo>();
+
+    private Map<String,OperationInfo> operations =
+        new HashMap<String,OperationInfo>();
     
     protected String className = BASE_MBEAN;
     //protected ConstructorInfo constructors[] = new ConstructorInfo[0];
@@ -347,7 +349,7 @@ public class ManagedBean implements java.io.Serializable
             // Skip introspection
             mbean = new BaseModelMBean();
         } else {
-            Class clazz = null;
+            Class<?> clazz = null;
             Exception ex = null;
             try {
                 clazz = Class.forName(getClassName());
@@ -484,7 +486,7 @@ public class ManagedBean implements java.io.Serializable
         Method m=null; // (Method)getAttMap.get( name );
 
         if( m==null ) {
-            AttributeInfo attrInfo = (AttributeInfo)attributes.get(aname);
+            AttributeInfo attrInfo = attributes.get(aname);
             // Look up the actual operation to be used
             if (attrInfo == null)
                 throw new AttributeNotFoundException(" Cannot find attribute " + aname + " for " + resource);
@@ -526,7 +528,7 @@ public class ManagedBean implements java.io.Serializable
         Method m=null;//(Method)setAttMap.get( name );
 
         if( m==null ) {
-            AttributeInfo attrInfo = (AttributeInfo)attributes.get(aname);
+            AttributeInfo attrInfo = attributes.get(aname);
             if (attrInfo == null)
                 throw new AttributeNotFoundException(" Cannot find attribute " + aname);
 
@@ -537,7 +539,8 @@ public class ManagedBean implements java.io.Serializable
 
             String argType=attrInfo.getType();
 
-            Class signature[] = new Class[] { BaseModelMBean.getAttributeClass( argType ) };
+            Class<?> signature[] =
+                new Class[] { BaseModelMBean.getAttributeClass( argType ) };
 
             Object object = null;
             NoSuchMethodException exception = null;
@@ -582,7 +585,7 @@ public class ManagedBean implements java.io.Serializable
 
             // Acquire the ModelMBeanOperationInfo information for
             // the requested operation
-            OperationInfo opInfo = (OperationInfo)operations.get(aname);
+            OperationInfo opInfo = operations.get(aname);
             if (opInfo == null)
                 throw new MBeanException(new ServiceNotFoundException(
                         "Cannot find operation " + aname),
@@ -590,7 +593,7 @@ public class ManagedBean implements java.io.Serializable
 
             // Prepare the signature required by Java reflection APIs
             // FIXME - should we use the signature from opInfo?
-            Class types[] = new Class[signature.length];
+            Class<?> types[] = new Class[signature.length];
             for (int i = 0; i < signature.length; i++) {
                 types[i] = BaseModelMBean.getAttributeClass(signature[i]);
             }
index 5e95f1f..f04b91f 100644 (file)
@@ -82,7 +82,7 @@ public class Registry implements RegistryMBean, MBeanRegistration  {
     
     /** Will be used to isolate different apps and enhance security.
      */
-    private static HashMap perLoaderRegistries=null;
+    private static HashMap<Object,Registry> perLoaderRegistries = null;
 
     /**
      * The registry instance created by our factory method the first time
@@ -102,21 +102,24 @@ public class Registry implements RegistryMBean, MBeanRegistration  {
      * The set of ManagedBean instances for the beans this registry
      * knows about, keyed by name.
      */
-    private HashMap descriptors = new HashMap();
+    private HashMap<String,ManagedBean> descriptors =
+        new HashMap<String,ManagedBean>();
 
     /** List of managed byeans, keyed by class name
      */
-    private HashMap descriptorsByClass = new HashMap();
+    private HashMap<String,ManagedBean> descriptorsByClass =
+        new HashMap<String,ManagedBean>();
 
     // map to avoid duplicated searching or loading descriptors 
-    private HashMap searchedPaths=new HashMap();
+    private HashMap<String,URL> searchedPaths=new HashMap<String,URL>();
     
     private Object guard;
 
     // Id - small ints to use array access. No reset on stop()
     // Used for notifications
-    private Hashtable idDomains=new Hashtable();
-    private Hashtable ids=new Hashtable();
+    private Hashtable<String,Hashtable<String,Integer>> idDomains =
+        new Hashtable<String,Hashtable<String,Integer>>();
+    private Hashtable<String,int[]> ids = new Hashtable<String,int[]>();
 
     
     // ----------------------------------------------------------- Constructors
@@ -153,7 +156,7 @@ public class Registry implements RegistryMBean, MBeanRegistration  {
             if( key==null ) 
                 key=Thread.currentThread().getContextClassLoader();
             if( key != null ) {
-                localRegistry=(Registry)perLoaderRegistries.get(key);
+                localRegistry = perLoaderRegistries.get(key);
                 if( localRegistry == null ) {
                     localRegistry=new Registry();
 //                    localRegistry.key=key;
@@ -190,7 +193,7 @@ public class Registry implements RegistryMBean, MBeanRegistration  {
      */
     public static void setUseContextClassLoader( boolean enable ) {
         if( enable ) {
-            perLoaderRegistries=new HashMap();
+            perLoaderRegistries = new HashMap<Object,Registry>();
         }
     }
     
@@ -202,9 +205,9 @@ public class Registry implements RegistryMBean, MBeanRegistration  {
      * @since 1.1
      */ 
     public void stop() {
-        descriptorsByClass = new HashMap();
-        descriptors = new HashMap();
-        searchedPaths=new HashMap();
+        descriptorsByClass = new HashMap<String,ManagedBean>();
+        descriptors = new HashMap<String,ManagedBean>();
+        searchedPaths=new HashMap<String,URL>();
     }
     
     /** 
@@ -222,7 +225,7 @@ public class Registry implements RegistryMBean, MBeanRegistration  {
      * 
      * @since 1.1
      */ 
-    public List loadMBeans( Object source, ClassLoader cl )
+    public List<ObjectName> loadMBeans( Object source, ClassLoader cl )
             throws Exception
     {
         return load("MbeansSource", source, null );
@@ -303,30 +306,22 @@ public class Registry implements RegistryMBean, MBeanRegistration  {
      * @throws Exception
      * @since 1.1
      */
-    public void invoke( List mbeans, String operation, boolean failFirst )
-            throws Exception
-    {
+    public void invoke(List<ObjectName> mbeans, String operation,
+            boolean failFirst ) throws Exception {
         if( mbeans==null ) {
             return;
         }
-        Iterator itr=mbeans.iterator();
+        Iterator<ObjectName> itr = mbeans.iterator();
         while(itr.hasNext()) {
-            Object current=itr.next();
-            ObjectName oN=null;
+            ObjectName current = itr.next();
             try {
-                if( current instanceof ObjectName) {
-                    oN=(ObjectName)current;
-                }
-                if( current instanceof String ) {
-                    oN=new ObjectName( (String)current );
-                }
-                if( oN==null ) {
+                if(current == null) {
                     continue;
                 }
-                if( getMethodInfo(oN, operation) == null) {
+                if(getMethodInfo(current, operation) == null) {
                     continue;
                 }
-                getMBeanServer().invoke(oN, operation,
+                getMBeanServer().invoke(current, operation,
                         new Object[] {}, new String[] {});
 
             } catch( Exception t ) {
@@ -350,21 +345,21 @@ public class Registry implements RegistryMBean, MBeanRegistration  {
         if( domain==null) {
             domain="";
         }
-        Hashtable domainTable=(Hashtable)idDomains.get( domain );
+        Hashtable<String,Integer> domainTable = idDomains.get(domain);
         if( domainTable == null ) {
-            domainTable=new Hashtable();
+            domainTable = new Hashtable<String,Integer>();
             idDomains.put( domain, domainTable); 
         }
         if( name==null ) {
             name="";
         }
-        Integer i=(Integer)domainTable.get(name);
+        Integer i = domainTable.get(name);
         
         if( i!= null ) {
             return i.intValue();
         }
 
-        int id[]=(int [])ids.get( domain );
+        int id[] = ids.get(domain);
         if( id == null ) {
             id=new int[1];
             ids.put( domain, id); 
@@ -403,9 +398,9 @@ public class Registry implements RegistryMBean, MBeanRegistration  {
      */
     public ManagedBean findManagedBean(String name) {
         // XXX Group ?? Use Group + Type
-        ManagedBean mb=((ManagedBean) descriptors.get(name));
+        ManagedBean mb = descriptors.get(name);
         if( mb==null )
-            mb=(ManagedBean)descriptorsByClass.get(name);
+            mb = descriptorsByClass.get(name);
         return mb;
     }
     
@@ -416,7 +411,7 @@ public class Registry implements RegistryMBean, MBeanRegistration  {
      * @since 1.0
      */
     public String[] findManagedBeans() {
-        return ((String[]) descriptors.keySet().toArray(new String[0]));
+        return descriptors.keySet().toArray(new String[0]);
     }
 
 
@@ -430,10 +425,10 @@ public class Registry implements RegistryMBean, MBeanRegistration  {
      */
     public String[] findManagedBeans(String group) {
 
-        ArrayList results = new ArrayList();
-        Iterator items = descriptors.values().iterator();
+        ArrayList<String> results = new ArrayList<String>();
+        Iterator<ManagedBean> items = descriptors.values().iterator();
         while (items.hasNext()) {
-            ManagedBean item = (ManagedBean) items.next();
+            ManagedBean item = items.next();
             if ((group == null) && (item.getGroup() == null)) {
                 results.add(item.getName());
             } else if (group.equals(item.getGroup())) {
@@ -441,7 +436,7 @@ public class Registry implements RegistryMBean, MBeanRegistration  {
             }
         }
         String values[] = new String[results.size()];
-        return ((String[]) results.toArray(values));
+        return results.toArray(values);
 
     }
 
@@ -589,7 +584,8 @@ public class Registry implements RegistryMBean, MBeanRegistration  {
 
         if (server == null) {
             if( MBeanServerFactory.findMBeanServer(null).size() > 0 ) {
-                server=(MBeanServer)MBeanServerFactory.findMBeanServer(null).get(0);
+                server = (MBeanServer) MBeanServerFactory.findMBeanServer(
+                        null).get(0);
                 if( log.isDebugEnabled() ) {
                     log.debug("Using existing MBeanServer " + (System.currentTimeMillis() - t1 ));
                 }
@@ -605,9 +601,8 @@ public class Registry implements RegistryMBean, MBeanRegistration  {
 
     /** Find or load metadata. 
      */ 
-    public ManagedBean findManagedBean(Object bean, Class beanClass, String type)
-        throws Exception
-    {
+    public ManagedBean findManagedBean(Object bean, Class<?> beanClass,
+            String type) throws Exception {
         if( bean!=null && beanClass==null ) {
             beanClass=bean.getClass();
         }
@@ -707,9 +702,8 @@ public class Registry implements RegistryMBean, MBeanRegistration  {
      * @throws Exception
      * @deprecated bad interface, mixing of metadata and mbeans
      */
-    public List load( String sourceType, Object source, String param)
-        throws Exception
-    {
+    public List<ObjectName> load( String sourceType, Object source,
+            String param) throws Exception {
         if( log.isTraceEnabled()) {
             log.trace("load " + source );
         }
@@ -739,7 +733,7 @@ public class Registry implements RegistryMBean, MBeanRegistration  {
             type=param;
             inputsource=source;
         } else if( source instanceof Class ) {
-            location=((Class)source).getName();
+            location=((Class<?>)source).getName();
             type=param;
             inputsource=source;
             if( sourceType== null ) {
@@ -751,7 +745,8 @@ public class Registry implements RegistryMBean, MBeanRegistration  {
             sourceType="MbeansDescriptorsDigesterSource";
         }
         ModelerSource ds=getModelerSource(sourceType);
-        List mbeans=ds.loadDescriptors(this, location, type, inputsource);
+        List<ObjectName> mbeans =
+            ds.loadDescriptors(this, location, type, inputsource);
 
         return mbeans;
     }
@@ -852,7 +847,7 @@ public class Registry implements RegistryMBean, MBeanRegistration  {
         return;
     }
 
-    /** Experimental. Will become private, some code may still use it
+    /**Experimental. Will become private, some code may still use it
      *
      * @param sourceType
      * @param source
@@ -860,19 +855,9 @@ public class Registry implements RegistryMBean, MBeanRegistration  {
      * @throws Exception
      * @deprecated
      */
-    public void loadDescriptors( String sourceType, Object source, String param)
-        throws Exception
-    {
-        List mbeans=load( sourceType, source, param );
-        if( mbeans == null) return;
-
-        Iterator itr=mbeans.iterator();
-        while( itr.hasNext() ) {
-            Object mb=itr.next();
-            if( mb instanceof ManagedBean) {
-                addManagedBean((ManagedBean)mb);
-            }
-        }
+    public void loadDescriptors(String sourceType, Object source, String param)
+            throws Exception {
+        load(sourceType, source, param);
     }
 
     /** Lookup the component descriptor in the package and
@@ -881,7 +866,7 @@ public class Registry implements RegistryMBean, MBeanRegistration  {
      * @param beanClass
      * @param type
      */
-    private void findDescriptor( Class beanClass, String type ) {
+    private void findDescriptor(Class<?> beanClass, String type) {
         if( type==null ) {
             type=beanClass.getName();
         }
@@ -918,7 +903,7 @@ public class Registry implements RegistryMBean, MBeanRegistration  {
             type="org.apache.tomcat.util.modeler.modules." + type;
         }
 
-        Class c=Class.forName( type );
+        Class<?> c = Class.forName(type);
         ModelerSource ds=(ModelerSource)c.newInstance();
         return ds;
     }
@@ -957,7 +942,7 @@ public class Registry implements RegistryMBean, MBeanRegistration  {
         perLoaderRegistries.remove(loader);
     }
 
-    public ManagedBean findManagedBean(Class beanClass, String type)
+    public ManagedBean findManagedBean(Class<?> beanClass, String type)
         throws Exception
     {
         return findManagedBean(null, beanClass, type);        
index 4b135c7..37e74eb 100644 (file)
@@ -21,6 +21,8 @@ package org.apache.tomcat.util.modeler;
 
 import java.util.List;
 
+import javax.management.ObjectName;
+
 /**
  * Interface for modeler MBeans.
  * 
@@ -53,7 +55,8 @@ public interface RegistryMBean {
      * 
      * @since 1.1
      */ 
-    public List loadMBeans( Object source, ClassLoader cl ) throws Exception;
+    public List<ObjectName> loadMBeans( Object source, ClassLoader cl )
+            throws Exception;
 
     /** Invoke an operation on a set of mbeans. 
      * 
@@ -63,7 +66,7 @@ public interface RegistryMBean {
      *      errors
      * @throws Exception
      */ 
-    public void invoke( List mbeans, String operation, boolean failFirst )
+    public void invoke( List<ObjectName> mbeans, String operation, boolean failFirst )
             throws Exception;
 
     /** Register a bean by creating a modeler mbean and adding it to the 
index b58e5b3..f108d9f 100644 (file)
@@ -22,6 +22,8 @@ import java.io.InputStream;
 import java.util.ArrayList;
 import java.util.List;
 
+import javax.management.ObjectName;
+
 import org.apache.juli.logging.Log;
 import org.apache.juli.logging.LogFactory;
 import org.apache.tomcat.util.DomUtil;
@@ -43,7 +45,7 @@ public class MbeansDescriptorsDOMSource extends ModelerSource
     String location;
     String type;
     Object source;
-    List mbeans=new ArrayList();
+    List<ObjectName> mbeans=new ArrayList<ObjectName>();
 
     public void setRegistry(Registry reg) {
         this.registry=reg;
@@ -65,7 +67,7 @@ public class MbeansDescriptorsDOMSource extends ModelerSource
         this.source=source;
     }
 
-    public List loadDescriptors( Registry registry, String location,
+    public List<ObjectName> loadDescriptors( Registry registry, String location,
                                  String type, Object source)
             throws Exception
     {
@@ -289,9 +291,7 @@ public class MbeansDescriptorsDOMSource extends ModelerSource
                 }
 
                 // Add the completed managed bean info to the registry
-                //registry.addManagedBean(managed);
-                mbeans.add( managed );
-
+                registry.addManagedBean(managed);
             }
 
             long t2=System.currentTimeMillis();
index 8133029..3c0221e 100644 (file)
@@ -21,9 +21,13 @@ package org.apache.tomcat.util.modeler.modules;
 import java.io.InputStream;
 import java.net.URL;
 import java.util.ArrayList;
+import java.util.Iterator;
 import java.util.List;
 
+import javax.management.ObjectName;
+
 import org.apache.tomcat.util.digester.Digester;
+import org.apache.tomcat.util.modeler.ManagedBean;
 import org.apache.tomcat.util.modeler.Registry;
 import org.apache.juli.logging.Log;
 import org.apache.juli.logging.LogFactory;
@@ -37,7 +41,7 @@ public class MbeansDescriptorsDigesterSource extends ModelerSource
     String location;
     String type;
     Object source;
-    List mbeans=new ArrayList();
+    List<ObjectName> mbeans = new ArrayList<ObjectName>();
     protected static Digester digester = null;
     
     protected static Digester createDigester(Registry registry) {
@@ -200,10 +204,8 @@ public class MbeansDescriptorsDigesterSource extends ModelerSource
         this.source=source;
     }
 
-    public List loadDescriptors( Registry registry, String location,
-                                 String type, Object source)
-            throws Exception
-    {
+    public List<ObjectName> loadDescriptors( Registry registry, String location,
+            String type, Object source) throws Exception {
         setRegistry(registry);
         setLocation(location);
         setType(type);
@@ -222,13 +224,14 @@ public class MbeansDescriptorsDigesterSource extends ModelerSource
         if (digester == null) {
             digester = createDigester(registry);
         }
+        ArrayList<ManagedBean> loadedMbeans = new ArrayList<ManagedBean>();
         
         synchronized (digester) {
-
+            
             // Process the input file to configure our registry
             try {
                 // Push our registry object onto the stack
-                digester.push(mbeans);
+                digester.push(loadedMbeans);
                 digester.parse(stream);
             } catch (Exception e) {
                 log.error("Error digesting Registry data", e);
@@ -238,6 +241,9 @@ public class MbeansDescriptorsDigesterSource extends ModelerSource
             }
         
         }
-            
+        Iterator<ManagedBean> iter = loadedMbeans.iterator();
+        while (iter.hasNext()) {
+            registry.addManagedBean(iter.next());
+        }
     }
 }
index f9331b9..94ed10f 100644 (file)
@@ -44,7 +44,7 @@ public class MbeansDescriptorsIntrospectionSource extends ModelerSource
     String location;
     String type;
     Object source;
-    List mbeans=new ArrayList();
+    List<ObjectName> mbeans = new ArrayList<ObjectName>();
 
     public void setRegistry(Registry reg) {
         this.registry=reg;
@@ -66,10 +66,8 @@ public class MbeansDescriptorsIntrospectionSource extends ModelerSource
         this.source=source;
     }
 
-    public List loadDescriptors( Registry registry, String location,
-                                 String type, Object source)
-            throws Exception
-    {
+    public List<ObjectName> loadDescriptors( Registry registry, String location,
+            String type, Object source) throws Exception {
         setRegistry(registry);
         setLocation(location);
         setType(type);
@@ -81,11 +79,12 @@ public class MbeansDescriptorsIntrospectionSource extends ModelerSource
     public void execute() throws Exception {
         if( registry==null ) registry=Registry.getRegistry();
         try {
-            ManagedBean managed=createManagedBean(registry, null, (Class)source, type);
+            ManagedBean managed = createManagedBean(registry, null,
+                    (Class<?>)source, type);
             if( managed==null ) return;
             managed.setName( type );
 
-            mbeans.add(managed);
+            registry.addManagedBean(managed);
 
         } catch( Exception ex ) {
             log.error( "Error reading descriptors ", ex);
@@ -96,7 +95,8 @@ public class MbeansDescriptorsIntrospectionSource extends ModelerSource
 
     // ------------ Implementation for non-declared introspection classes
 
-    static Hashtable specialMethods=new Hashtable();
+    static Hashtable<String,String> specialMethods =
+        new Hashtable<String,String>();
     static {
         specialMethods.put( "preDeregister", "");
         specialMethods.put( "postDeregister", "");
@@ -106,7 +106,7 @@ public class MbeansDescriptorsIntrospectionSource extends ModelerSource
     private static ObjectName objNameArray[]=new ObjectName[0];
     // createMBean == registerClass + registerMBean
 
-    private static Class[] supportedTypes  = new Class[] {
+    private static Class<?>[] supportedTypes  = new Class[] {
         Boolean.class,
         Boolean.TYPE,
         Byte.class,
@@ -139,7 +139,7 @@ public class MbeansDescriptorsIntrospectionSource extends ModelerSource
      * @param ret The class to check
      * @return boolean True if class is supported
      */ 
-    private boolean supportedType(Class ret) {
+    private boolean supportedType(Class<?> ret) {
         for (int i = 0; i < supportedTypes.length; i++) {
             if (ret == supportedTypes[i]) {
                 return true;
@@ -158,7 +158,7 @@ public class MbeansDescriptorsIntrospectionSource extends ModelerSource
      * @param javaType The class to check
      * @return boolean True if the class is compatible.
      */
-    protected boolean isBeanCompatible(Class javaType) {
+    protected boolean isBeanCompatible(Class<?> javaType) {
         // Must be a non-primitive and non array
         if (javaType.isArray() || javaType.isPrimitive()) {
             return false;
@@ -178,7 +178,7 @@ public class MbeansDescriptorsIntrospectionSource extends ModelerSource
         }
 
         // Make sure superclass is compatible
-        Class superClass = javaType.getSuperclass();
+        Class<?> superClass = javaType.getSuperclass();
         if (superClass != null && 
             superClass != java.lang.Object.class && 
             superClass != java.lang.Exception.class && 
@@ -200,10 +200,12 @@ public class MbeansDescriptorsIntrospectionSource extends ModelerSource
      * @param setAttMap The settable attributes map
      * @param invokeAttMap The invokable attributes map
      */
-    private void initMethods(Class realClass,
+    private void initMethods(Class<?> realClass,
                              Method methods[],
-                             Hashtable attMap, Hashtable getAttMap,
-                             Hashtable setAttMap, Hashtable invokeAttMap)
+                             Hashtable<String,Method> attMap,
+                             Hashtable<String,Method> getAttMap,
+                             Hashtable<String,Method> setAttMap,
+                             Hashtable<String,Method> invokeAttMap)
     {
         for (int j = 0; j < methods.length; ++j) {
             String name=methods[j].getName();
@@ -217,10 +219,10 @@ public class MbeansDescriptorsIntrospectionSource extends ModelerSource
             }
             if( methods[j].getDeclaringClass() == Object.class )
                 continue;
-            Class params[]=methods[j].getParameterTypes();
+            Class<?> params[] = methods[j].getParameterTypes();
 
             if( name.startsWith( "get" ) && params.length==0) {
-                Class ret=methods[j].getReturnType();
+                Class<?> ret = methods[j].getReturnType();
                 if( ! supportedType( ret ) ) {
                     if( log.isDebugEnabled() )
                         log.debug("Unsupported type " + methods[j]);
@@ -232,7 +234,7 @@ public class MbeansDescriptorsIntrospectionSource extends ModelerSource
                 // just a marker, we don't use the value
                 attMap.put( name, methods[j] );
             } else if( name.startsWith( "is" ) && params.length==0) {
-                Class ret=methods[j].getReturnType();
+                Class<?> ret = methods[j].getReturnType();
                 if( Boolean.TYPE != ret  ) {
                     if( log.isDebugEnabled() )
                         log.debug("Unsupported type " + methods[j] + " " + ret );
@@ -287,19 +289,19 @@ public class MbeansDescriptorsIntrospectionSource extends ModelerSource
      * @return ManagedBean The create MBean
      */
     public ManagedBean createManagedBean(Registry registry, String domain,
-                                         Class realClass, String type)
+                                         Class<?> realClass, String type)
     {
         ManagedBean mbean= new ManagedBean();
 
         Method methods[]=null;
 
-        Hashtable attMap=new Hashtable();
+        Hashtable<String,Method> attMap = new Hashtable<String,Method>();
         // key: attribute val: getter method
-        Hashtable getAttMap=new Hashtable();
+        Hashtable<String,Method> getAttMap = new Hashtable<String,Method>();
         // key: attribute val: setter method
-        Hashtable setAttMap=new Hashtable();
+        Hashtable<String,Method> setAttMap = new Hashtable<String,Method>();
         // key: operation val: invoke method
-        Hashtable invokeAttMap=new Hashtable();
+        Hashtable<String,Method> invokeAttMap = new Hashtable<String,Method>();
 
         methods = realClass.getMethods();
 
@@ -307,23 +309,23 @@ public class MbeansDescriptorsIntrospectionSource extends ModelerSource
 
         try {
 
-            Enumeration en=attMap.keys();
+            Enumeration<String> en = attMap.keys();
             while( en.hasMoreElements() ) {
-                String name=(String)en.nextElement();
+                String name = en.nextElement();
                 AttributeInfo ai=new AttributeInfo();
                 ai.setName( name );
-                Method gm=(Method)getAttMap.get(name);
+                Method gm = getAttMap.get(name);
                 if( gm!=null ) {
                     //ai.setGetMethodObj( gm );
                     ai.setGetMethod( gm.getName());
-                    Class t=gm.getReturnType();
+                    Class<?> t=gm.getReturnType();
                     if( t!=null )
                         ai.setType( t.getName() );
                 }
-                Method sm=(Method)setAttMap.get(name);
+                Method sm = setAttMap.get(name);
                 if( sm!=null ) {
                     //ai.setSetMethodObj(sm);
-                    Class t=sm.getParameterTypes()[0];
+                    Class<?> t = sm.getParameterTypes()[0];
                     if( t!=null )
                         ai.setType( t.getName());
                     ai.setSetMethod( sm.getName());
@@ -341,14 +343,14 @@ public class MbeansDescriptorsIntrospectionSource extends ModelerSource
 
             en=invokeAttMap.keys();
             while( en.hasMoreElements() ) {
-                String name=(String)en.nextElement();
-                Method m=(Method)invokeAttMap.get(name);
+                String name = en.nextElement();
+                Method m = invokeAttMap.get(name);
                 if( m!=null && name != null ) {
                     OperationInfo op=new OperationInfo();
                     op.setName(name);
                     op.setReturnType(m.getReturnType().getName());
                     op.setDescription("Introspected operation " + name);
-                    Class parms[]=m.getParameterTypes();
+                    Class<?> parms[] = m.getParameterTypes();
                     for(int i=0; i<parms.length; i++ ) {
                         ParameterInfo pi=new ParameterInfo();
                         pi.setType(parms[i].getName());
index f67b627..53a302f 100644 (file)
@@ -22,6 +22,8 @@ import java.net.URL;
 import java.util.ArrayList;
 import java.util.List;
 
+import javax.management.ObjectName;
+
 import org.apache.juli.logging.Log;
 import org.apache.juli.logging.LogFactory;
 import org.apache.tomcat.util.modeler.ManagedBean;
@@ -35,7 +37,7 @@ public class MbeansDescriptorsSerSource extends ModelerSource
     String location;
     String type;
     Object source;
-    List mbeans=new ArrayList();
+    List<ObjectName> mbeans=new ArrayList<ObjectName>();
 
     public void setRegistry(Registry reg) {
         this.registry=reg;
@@ -57,10 +59,8 @@ public class MbeansDescriptorsSerSource extends ModelerSource
         this.source=source;
     }
 
-    public List loadDescriptors( Registry registry, String location,
-                                 String type, Object source)
-            throws Exception
-    {
+    public List<ObjectName> loadDescriptors( Registry registry, String location,
+            String type, Object source) throws Exception {
         setRegistry(registry);
         setLocation(location);
         setType(type);
@@ -90,7 +90,7 @@ public class MbeansDescriptorsSerSource extends ModelerSource
             ManagedBean beans[]=(ManagedBean[])obj;
             // after all are read without error
             for( int i=0; i<beans.length; i++ ) {
-                mbeans.add(beans[i]);
+                registry.addManagedBean(beans[i]);
             }
 
         } catch( Exception ex ) {
index f519b1c..7362006 100644 (file)
@@ -59,10 +59,11 @@ public class MbeansSource extends ModelerSource implements MbeansSourceMBean
 
     // true if we are during the original loading
     boolean loading=true;
-    List mbeans=new ArrayList();
+    List<ObjectName> mbeans = new ArrayList<ObjectName>();
     static boolean loaderLoaded=false;
     private Document document;
-    private HashMap object2Node = new HashMap();
+    private HashMap<ObjectName,Node> object2Node =
+        new HashMap<ObjectName,Node>();
 
     long lastUpdate;
     long updateInterval=10000; // 10s
@@ -98,14 +99,12 @@ public class MbeansSource extends ModelerSource implements MbeansSourceMBean
     /** Return the list of mbeans created by this source.
      *  It can be used to implement runtime services.
      */
-    public List getMBeans() {
+    public List<ObjectName> getMBeans() {
         return mbeans;
     }
 
-    public List loadDescriptors( Registry registry, String location,
-                                 String type, Object source)
-            throws Exception
-    {
+    public List<ObjectName> loadDescriptors(Registry registry, String location,
+            String type, Object source) throws Exception {
         setRegistry(registry);
         setLocation(location);
         setType(type);
@@ -161,7 +160,7 @@ public class MbeansSource extends ModelerSource implements MbeansSourceMBean
                 firstMbeanN=descriptorsN;
             }
 
-            MBeanServer server=(MBeanServer)Registry.getServer();
+            MBeanServer server = Registry.getServer();
 
             // XXX Not very clean...  Just a workaround
             if( ! loaderLoaded ) {
@@ -273,7 +272,7 @@ public class MbeansSource extends ModelerSource implements MbeansSourceMBean
         if( loading ) return;
         // nothing by default
         //log.info( "XXX UpdateField " + oname + " " + name + " " + value);
-        Node n=(Node)object2Node.get( oname );
+        Node n = object2Node.get(oname);
         if( n == null ) {
             log.info( "Node not found " + oname );
             return;
index 3883118..5f4fd81 100644 (file)
@@ -18,6 +18,8 @@ package org.apache.tomcat.util.modeler.modules;
 
 import java.util.List;
 
+import javax.management.ObjectName;
+
 
 /**
  * This mbean will load an extended mlet file ( similar in syntax with jboss ).
@@ -38,7 +40,7 @@ public interface MbeansSourceMBean
      * 
      * @return List of ObjectName
      */ 
-    public List getMBeans();
+    public List<ObjectName> getMBeans();
 
     /** Load the mbeans from the source. Called automatically on init() 
      * 
index 7c97030..77bada4 100644 (file)
@@ -42,10 +42,8 @@ public class ModelerSource {
      * @param source Introspected object or some other source
      * @throws Exception
      */ 
-    public List loadDescriptors( Registry registry, String location,
-                                 String type, Object source)
-            throws Exception
-    {
+    public List<ObjectName> loadDescriptors( Registry registry, String location,
+            String type, Object source) throws Exception {
         // TODO
         return null;
     }