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 2008/11/18 01:47:36 UTC

svn commit: r718452 - in /tomcat/trunk/java/org/apache: catalina/core/ tomcat/util/modeler/ tomcat/util/modeler/modules/

Author: markt
Date: Mon Nov 17 16:47:36 2008
New Revision: 718452

URL: http://svn.apache.org/viewvc?rev=718452&view=rev
Log:
Generics changes for o.a.t.util.modeler
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.

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

Modified: tomcat/trunk/java/org/apache/catalina/core/StandardEngine.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/core/StandardEngine.java?rev=718452&r1=718451&r2=718452&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/core/StandardEngine.java (original)
+++ tomcat/trunk/java/org/apache/catalina/core/StandardEngine.java Mon Nov 17 16:47:36 2008
@@ -115,7 +115,7 @@
     
     /** Mbeans loaded by the engine.  
      */ 
-    private List mbeans;
+    private List<ObjectName> mbeans;
     
 
     /**
@@ -382,7 +382,7 @@
             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);

Modified: tomcat/trunk/java/org/apache/tomcat/util/modeler/BaseAttributeFilter.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/modeler/BaseAttributeFilter.java?rev=718452&r1=718451&r2=718452&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/modeler/BaseAttributeFilter.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/util/modeler/BaseAttributeFilter.java Mon Nov 17 16:47:36 2008
@@ -65,7 +65,7 @@
      * 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 String[] getNames() {
 
         synchronized (names) {
-            return ((String[]) names.toArray(new String[names.size()]));
+            return names.toArray(new String[names.size()]);
         }
 
     }

Modified: tomcat/trunk/java/org/apache/tomcat/util/modeler/BaseModelMBean.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/modeler/BaseModelMBean.java?rev=718452&r1=718451&r2=718452&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/modeler/BaseModelMBean.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/util/modeler/BaseModelMBean.java Mon Nov 17 16:47:36 2008
@@ -143,8 +143,8 @@
 
     // --------------------------------------------------- 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 @@
         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 @@
 
     }
 
-    static Class getAttributeClass(String signature)
+    static Class<?> getAttributeClass(String signature)
         throws ReflectionException
     {
         if (signature.equals(Boolean.TYPE.getName()))
@@ -467,7 +467,7 @@
         // 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();

Modified: tomcat/trunk/java/org/apache/tomcat/util/modeler/BaseNotificationBroadcaster.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/modeler/BaseNotificationBroadcaster.java?rev=718452&r1=718451&r2=718452&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/modeler/BaseNotificationBroadcaster.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/util/modeler/BaseNotificationBroadcaster.java Mon Nov 17 16:47:36 2008
@@ -53,7 +53,8 @@
      * 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 @@
             // 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 @@
         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 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;

Modified: tomcat/trunk/java/org/apache/tomcat/util/modeler/FixedNotificationFilter.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/modeler/FixedNotificationFilter.java?rev=718452&r1=718451&r2=718452&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/modeler/FixedNotificationFilter.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/util/modeler/FixedNotificationFilter.java Mon Nov 17 16:47:36 2008
@@ -44,7 +44,7 @@
      * 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 String[] getNames() {
         synchronized (names) {
-            return ((String[]) names.toArray(new String[names.size()]));
+            return names.toArray(new String[names.size()]);
         }
     }
 

Modified: tomcat/trunk/java/org/apache/tomcat/util/modeler/ManagedBean.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/modeler/ManagedBean.java?rev=718452&r1=718451&r2=718452&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/modeler/ManagedBean.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/util/modeler/ManagedBean.java Mon Nov 17 16:47:36 2008
@@ -50,8 +50,8 @@
 {
     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 @@
      * 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 @@
             // Skip introspection
             mbean = new BaseModelMBean();
         } else {
-            Class clazz = null;
+            Class<?> clazz = null;
             Exception ex = null;
             try {
                 clazz = Class.forName(getClassName());
@@ -484,7 +486,7 @@
         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 @@
         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 @@
 
             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 @@
 
             // 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 @@
 
             // 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]);
             }

Modified: tomcat/trunk/java/org/apache/tomcat/util/modeler/Registry.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/modeler/Registry.java?rev=718452&r1=718451&r2=718452&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/modeler/Registry.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/util/modeler/Registry.java Mon Nov 17 16:47:36 2008
@@ -82,7 +82,7 @@
     
     /** 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 @@
      * 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 @@
             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 static void setUseContextClassLoader( boolean enable ) {
         if( enable ) {
-            perLoaderRegistries=new HashMap();
+            perLoaderRegistries = new HashMap<Object,Registry>();
         }
     }
     
@@ -202,9 +205,9 @@
      * @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 @@
      * 
      * @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 @@
      * @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 @@
         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 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 @@
      * @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 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 @@
             }
         }
         String values[] = new String[results.size()];
-        return ((String[]) results.toArray(values));
+        return results.toArray(values);
 
     }
 
@@ -589,7 +584,8 @@
 
         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 @@
 
     /** 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 @@
      * @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 @@
             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 @@
             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 @@
         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 @@
      * @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 @@
      * @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 @@
             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 @@
         perLoaderRegistries.remove(loader);
     }
 
-    public ManagedBean findManagedBean(Class beanClass, String type)
+    public ManagedBean findManagedBean(Class<?> beanClass, String type)
         throws Exception
     {
         return findManagedBean(null, beanClass, type);        

Modified: tomcat/trunk/java/org/apache/tomcat/util/modeler/RegistryMBean.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/modeler/RegistryMBean.java?rev=718452&r1=718451&r2=718452&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/modeler/RegistryMBean.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/util/modeler/RegistryMBean.java Mon Nov 17 16:47:36 2008
@@ -21,6 +21,8 @@
 
 import java.util.List;
 
+import javax.management.ObjectName;
+
 /**
  * Interface for modeler MBeans.
  * 
@@ -53,7 +55,8 @@
      * 
      * @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 @@
      *      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 

Modified: tomcat/trunk/java/org/apache/tomcat/util/modeler/modules/MbeansDescriptorsDOMSource.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/modeler/modules/MbeansDescriptorsDOMSource.java?rev=718452&r1=718451&r2=718452&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/modeler/modules/MbeansDescriptorsDOMSource.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/util/modeler/modules/MbeansDescriptorsDOMSource.java Mon Nov 17 16:47:36 2008
@@ -22,6 +22,8 @@
 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 @@
     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 @@
         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 @@
                 }
 
                 // Add the completed managed bean info to the registry
-                //registry.addManagedBean(managed);
-                mbeans.add( managed );
-
+                registry.addManagedBean(managed);
             }
 
             long t2=System.currentTimeMillis();

Modified: tomcat/trunk/java/org/apache/tomcat/util/modeler/modules/MbeansDescriptorsDigesterSource.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/modeler/modules/MbeansDescriptorsDigesterSource.java?rev=718452&r1=718451&r2=718452&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/modeler/modules/MbeansDescriptorsDigesterSource.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/util/modeler/modules/MbeansDescriptorsDigesterSource.java Mon Nov 17 16:47:36 2008
@@ -21,9 +21,13 @@
 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 @@
     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 @@
         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 @@
         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 @@
             }
         
         }
-            
+        Iterator<ManagedBean> iter = loadedMbeans.iterator();
+        while (iter.hasNext()) {
+            registry.addManagedBean(iter.next());
+        }
     }
 }

Modified: tomcat/trunk/java/org/apache/tomcat/util/modeler/modules/MbeansDescriptorsIntrospectionSource.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/modeler/modules/MbeansDescriptorsIntrospectionSource.java?rev=718452&r1=718451&r2=718452&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/modeler/modules/MbeansDescriptorsIntrospectionSource.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/util/modeler/modules/MbeansDescriptorsIntrospectionSource.java Mon Nov 17 16:47:36 2008
@@ -44,7 +44,7 @@
     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 @@
         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 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 @@
 
     // ------------ 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 @@
     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 @@
      * @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 @@
      * @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 @@
         }
 
         // 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 @@
      * @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 @@
             }
             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 @@
                 // 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 @@
      * @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 @@
 
         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 @@
 
             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());

Modified: tomcat/trunk/java/org/apache/tomcat/util/modeler/modules/MbeansDescriptorsSerSource.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/modeler/modules/MbeansDescriptorsSerSource.java?rev=718452&r1=718451&r2=718452&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/modeler/modules/MbeansDescriptorsSerSource.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/util/modeler/modules/MbeansDescriptorsSerSource.java Mon Nov 17 16:47:36 2008
@@ -22,6 +22,8 @@
 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 @@
     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 @@
         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 @@
             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 ) {

Modified: tomcat/trunk/java/org/apache/tomcat/util/modeler/modules/MbeansSource.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/modeler/modules/MbeansSource.java?rev=718452&r1=718451&r2=718452&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/modeler/modules/MbeansSource.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/util/modeler/modules/MbeansSource.java Mon Nov 17 16:47:36 2008
@@ -59,10 +59,11 @@
 
     // 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 @@
     /** 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 @@
                 firstMbeanN=descriptorsN;
             }
 
-            MBeanServer server=(MBeanServer)Registry.getServer();
+            MBeanServer server = Registry.getServer();
 
             // XXX Not very clean...  Just a workaround
             if( ! loaderLoaded ) {
@@ -273,7 +272,7 @@
         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;

Modified: tomcat/trunk/java/org/apache/tomcat/util/modeler/modules/MbeansSourceMBean.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/modeler/modules/MbeansSourceMBean.java?rev=718452&r1=718451&r2=718452&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/modeler/modules/MbeansSourceMBean.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/util/modeler/modules/MbeansSourceMBean.java Mon Nov 17 16:47:36 2008
@@ -18,6 +18,8 @@
 
 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 @@
      * 
      * @return List of ObjectName
      */ 
-    public List getMBeans();
+    public List<ObjectName> getMBeans();
 
     /** Load the mbeans from the source. Called automatically on init() 
      * 

Modified: tomcat/trunk/java/org/apache/tomcat/util/modeler/modules/ModelerSource.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/modeler/modules/ModelerSource.java?rev=718452&r1=718451&r2=718452&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/modeler/modules/ModelerSource.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/util/modeler/modules/ModelerSource.java Mon Nov 17 16:47:36 2008
@@ -42,10 +42,8 @@
      * @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;
     }



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