commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject svn commit: r397546 - in /jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/util/introspection: ClassMap.java Info.java IntrospectorBase.java
Date Thu, 27 Apr 2006 14:01:52 GMT
Author: dion
Date: Thu Apr 27 07:01:48 2006
New Revision: 397546

URL: http://svn.apache.org/viewcvs?rev=397546&view=rev
Log:
More checkstyle

Modified:
    jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/util/introspection/ClassMap.java
    jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/util/introspection/Info.java
    jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/util/introspection/IntrospectorBase.java

Modified: jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/util/introspection/ClassMap.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/util/introspection/ClassMap.java?rev=397546&r1=397545&r2=397546&view=diff
==============================================================================
--- jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/util/introspection/ClassMap.java
(original)
+++ jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/util/introspection/ClassMap.java
Thu Apr 27 07:01:48 2006
@@ -1,6 +1,6 @@
 /*
  * Copyright 2001-2002,2004 The Apache Software Foundation.
- * 
+ *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
@@ -22,12 +22,12 @@
 import java.util.Map;
 
 /**
- *  Taken from the Velocity tree so we can be self-sufficient
- *
- * A cache of introspection information for a specific class instance.
- * Keys {@link java.lang.Method} objects by a concatenation of the
- * method name and the names of classes that make up the parameters.
- *
+ * Taken from the Velocity tree so we can be self-sufficient
+ * 
+ * A cache of introspection information for a specific class instance. Keys
+ * {@link java.lang.Method} objects by a concatenation of the method name and
+ * the names of classes that make up the parameters.
+ * 
  * @since 1.0
  * @author <a href="mailto:jvanzyl@apache.org">Jason van Zyl</a>
  * @author <a href="mailto:bob@werken.com">Bob McWhirter</a>
@@ -35,22 +35,24 @@
  * @author <a href="mailto:geirm@optonline.net">Geir Magnusson Jr.</a>
  * @version $Id$
  */
-public class ClassMap
-{
-    private static final class CacheMiss { }
+public class ClassMap {
+    private static final class CacheMiss {
+    }
+
     private static final CacheMiss CACHE_MISS = new CacheMiss();
+
     private static final Object OBJECT = new Object();
 
-    /** 
-     * Class passed into the constructor used to as
-     * the basis for the Method map.
+    /**
+     * Class passed into the constructor used to as the basis for the Method
+     * map.
      */
 
     private Class clazz;
 
     /**
-     * Cache of Methods, or CACHE_MISS, keyed by method
-     * name and actual arguments used to find it.
+     * Cache of Methods, or CACHE_MISS, keyed by method name and actual
+     * arguments used to find it.
      */
     private final Map methodCache = new Hashtable();
 
@@ -59,93 +61,72 @@
     /**
      * Standard constructor
      */
-    public ClassMap( Class clazz)
-    {
+    public ClassMap(Class clazz) {
         this.clazz = clazz;
         populateMethodCache();
     }
 
-    private ClassMap()
-    {
+    private ClassMap() {
     }
 
     /**
      * @return the class object whose methods are cached by this map.
      */
-     Class getCachedClass()
-     {
-         return clazz;
-     }
-    
-    /**
-     * Find a Method using the methodKey
-     * provided.
-     *
-     * Look in the methodMap for an entry.  If found,
-     * it'll either be a CACHE_MISS, in which case we
-     * simply give up, or it'll be a Method, in which
-     * case, we return it.
-     *
-     * If nothing is found, then we must actually go
-     * and introspect the method from the MethodMap.
-     */
-    public Method findMethod(String name, Object[] params)
-        throws MethodMap.AmbiguousException
-    {
+    Class getCachedClass() {
+        return clazz;
+    }
+
+    /**
+     * Find a Method using the methodKey provided.
+     * 
+     * Look in the methodMap for an entry. If found, it'll either be a
+     * CACHE_MISS, in which case we simply give up, or it'll be a Method, in
+     * which case, we return it.
+     * 
+     * If nothing is found, then we must actually go and introspect the method
+     * from the MethodMap.
+     */
+    public Method findMethod(String name, Object[] params) throws MethodMap.AmbiguousException
{
         String methodKey = makeMethodKey(name, params);
-        Object cacheEntry = methodCache.get( methodKey );
+        Object cacheEntry = methodCache.get(methodKey);
 
-        if (cacheEntry == CACHE_MISS)
-        {
+        if (cacheEntry == CACHE_MISS) {
             return null;
         }
 
-        if (cacheEntry == null)
-        {
-            try
-            {
-                cacheEntry = methodMap.find( name,
-                                             params );
-            }
-            catch( MethodMap.AmbiguousException ae )
-            {
+        if (cacheEntry == null) {
+            try {
+                cacheEntry = methodMap.find(name, params);
+            } catch (MethodMap.AmbiguousException ae) {
                 /*
-                 *  that's a miss :)
+                 * that's a miss :)
                  */
 
-                methodCache.put( methodKey,
-                                 CACHE_MISS );
+                methodCache.put(methodKey, CACHE_MISS);
 
                 throw ae;
             }
 
-            if ( cacheEntry == null )
-            {
-                methodCache.put( methodKey,
-                                 CACHE_MISS );
-            }
-            else
-            {
-                methodCache.put( methodKey,
-                                 cacheEntry );
+            if (cacheEntry == null) {
+                methodCache.put(methodKey, CACHE_MISS);
+            } else {
+                methodCache.put(methodKey, cacheEntry);
             }
         }
 
         // Yes, this might just be null.
-        
+
         return (Method) cacheEntry;
     }
-    
+
     /**
-     * Populate the Map of direct hits. These
-     * are taken from all the public methods
-     * that our class provides.
+     * Populate the Map of direct hits. These are taken from all the public
+     * methods that our class provides.
      */
-    private void populateMethodCache()
-    {
+    private void populateMethodCache() {
 
         /*
-         *  get all publicly accessible methods
+         * get all publicly accessible methods
          */
 
         Method[] methods = getAccessibleMethods(clazz);
@@ -154,54 +135,48 @@
          * map and cache them
          */
 
-        for (int i = 0; i < methods.length; i++)
-        {
+        for (int i = 0; i < methods.length; i++) {
             Method method = methods[i];
 
             /*
-             *  now get the 'public method', the method declared by a 
-             *  public interface or class. (because the actual implementing
-             *  class may be a facade...
+             * now get the 'public method', the method declared by a public
+             * interface or class. (because the actual implementing class may be
+             * a facade...
              */
 
-            Method publicMethod = getPublicMethod( method );
+            Method publicMethod = getPublicMethod(method);
 
             /*
-             *  it is entirely possible that there is no public method for
-             *  the methods of this class (i.e. in the facade, a method
-             *  that isn't on any of the interfaces or superclass
-             *  in which case, ignore it.  Otherwise, map and cache
+             * it is entirely possible that there is no public method for the
+             * methods of this class (i.e. in the facade, a method that isn't on
+             * any of the interfaces or superclass in which case, ignore it.
+             * Otherwise, map and cache
              */
 
-            if ( publicMethod != null)
-            {
-                methodMap.add( publicMethod );
-                methodCache.put(  makeMethodKey( publicMethod), publicMethod);
+            if (publicMethod != null) {
+                methodMap.add(publicMethod);
+                methodCache.put(makeMethodKey(publicMethod), publicMethod);
             }
-        }            
+        }
     }
 
     /**
-     * Make a methodKey for the given method using
-     * the concatenation of the name and the
-     * types of the method parameters.
+     * Make a methodKey for the given method using the concatenation of the name
+     * and the types of the method parameters.
      */
-    private String makeMethodKey(Method method)
-    {
+    private String makeMethodKey(Method method) {
         Class[] parameterTypes = method.getParameterTypes();
-        
+
         StringBuffer methodKey = new StringBuffer(method.getName());
-        
-        for (int j = 0; j < parameterTypes.length; j++)
-        {
+
+        for (int j = 0; j < parameterTypes.length; j++) {
             /*
-             * If the argument type is primitive then we want
-             * to convert our primitive type signature to the 
-             * corresponding Object type so introspection for
-             * methods with primitive types will work correctly.
+             * If the argument type is primitive then we want to convert our
+             * primitive type signature to the corresponding Object type so
+             * introspection for methods with primitive types will work
+             * correctly.
              */
-            if (parameterTypes[j].isPrimitive())
-            {
+            if (parameterTypes[j].isPrimitive()) {
                 if (parameterTypes[j].equals(Boolean.TYPE))
                     methodKey.append("java.lang.Boolean");
                 else if (parameterTypes[j].equals(Byte.TYPE))
@@ -218,83 +193,72 @@
                     methodKey.append("java.lang.Long");
                 else if (parameterTypes[j].equals(Short.TYPE))
                     methodKey.append("java.lang.Short");
-            }                
-            else
-            {
+            } else {
                 methodKey.append(parameterTypes[j].getName());
             }
-        }            
-        
+        }
+
         return methodKey.toString();
     }
 
-    private static String makeMethodKey(String method, Object[] params)
-    {
+    private static String makeMethodKey(String method, Object[] params) {
         StringBuffer methodKey = new StringBuffer().append(method);
 
-        for (int j = 0; j < params.length; j++)
-        {
+        for (int j = 0; j < params.length; j++) {
             Object arg = params[j];
 
-            if (arg == null)
-            {
+            if (arg == null) {
                 arg = OBJECT;
             }
 
             methodKey.append(arg.getClass().getName());
         }
-        
+
         return methodKey.toString();
     }
 
     /**
-     * Retrieves public methods for a class. In case the class is not
-     * public, retrieves methods with same signature as its public methods
-     * from public superclasses and interfaces (if they exist). Basically
-     * upcasts every method to the nearest acccessible method.
+     * Retrieves public methods for a class. In case the class is not public,
+     * retrieves methods with same signature as its public methods from public
+     * superclasses and interfaces (if they exist). Basically upcasts every
+     * method to the nearest acccessible method.
      */
-    private static Method[] getAccessibleMethods(Class clazz)
-    {
+    private static Method[] getAccessibleMethods(Class clazz) {
         Method[] methods = clazz.getMethods();
-        
+
         /*
-         *  Short circuit for the (hopefully) majority of cases where the
-         *  clazz is public
+         * Short circuit for the (hopefully) majority of cases where the clazz
+         * is public
          */
-        
-        if (Modifier.isPublic(clazz.getModifiers()))
-        {
+
+        if (Modifier.isPublic(clazz.getModifiers())) {
             return methods;
         }
 
         /*
-         *  No luck - the class is not public, so we're going the longer way.
+         * No luck - the class is not public, so we're going the longer way.
          */
 
         MethodInfo[] methodInfos = new MethodInfo[methods.length];
 
-        for(int i = methods.length; i-- > 0; )
-        {
+        for (int i = methods.length; i-- > 0;) {
             methodInfos[i] = new MethodInfo(methods[i]);
         }
 
         int upcastCount = getAccessibleMethods(clazz, methodInfos, 0);
 
         /*
-         *  Reallocate array in case some method had no accessible counterpart.
+         * Reallocate array in case some method had no accessible counterpart.
          */
 
-        if(upcastCount < methods.length)
-        {
+        if (upcastCount < methods.length) {
             methods = new Method[upcastCount];
         }
 
         int j = 0;
-        for(int i = 0; i < methodInfos.length; ++i)
-        {
+        for (int i = 0; i < methodInfos.length; ++i) {
             MethodInfo methodInfo = methodInfos[i];
-            if(methodInfo.upcast)
-            {
+            if (methodInfo.upcast) {
                 methods[j++] = methodInfo.method;
             }
         }
@@ -302,123 +266,109 @@
     }
 
     /**
-     *  Recursively finds a match for each method, starting with the class, and then
-     *  searching the superclass and interfaces.
-     *
-     *  @param clazz Class to check
-     *  @param methodInfos array of methods we are searching to match
-     *  @param upcastCount current number of methods we have matched
-     *  @return count of matched methods
+     * Recursively finds a match for each method, starting with the class, and
+     * then searching the superclass and interfaces.
+     * 
+     * @param clazz Class to check
+     * @param methodInfos array of methods we are searching to match
+     * @param upcastCount current number of methods we have matched
+     * @return count of matched methods
      */
-    private static int getAccessibleMethods( Class clazz, MethodInfo[] methodInfos, int upcastCount)
-    {
+    private static int getAccessibleMethods(Class clazz, MethodInfo[] methodInfos, int upcastCount)
{
         int l = methodInfos.length;
-        
+
         /*
-         *  if this class is public, then check each of the currently
-         *  'non-upcasted' methods to see if we have a match
+         * if this class is public, then check each of the currently
+         * 'non-upcasted' methods to see if we have a match
          */
 
-        if( Modifier.isPublic(clazz.getModifiers()) )
-        {
-            for(int i = 0; i < l && upcastCount < l; ++i)
-            {
-                try
-                {
+        if (Modifier.isPublic(clazz.getModifiers())) {
+            for (int i = 0; i < l && upcastCount < l; ++i) {
+                try {
                     MethodInfo methodInfo = methodInfos[i];
 
-                    if(!methodInfo.upcast)
-                    {
+                    if (!methodInfo.upcast) {
                         methodInfo.tryUpcasting(clazz);
                         upcastCount++;
                     }
-                }
-                catch(NoSuchMethodException e)
-                {
+                } catch (NoSuchMethodException e) {
                     /*
-                     *  Intentionally ignored - it means
-                     *  it wasn't found in the current class
+                     * Intentionally ignored - it means it wasn't found in the
+                     * current class
                      */
                 }
             }
 
             /*
-             *  Short circuit if all methods were upcast
+             * Short circuit if all methods were upcast
              */
 
-            if(upcastCount == l)
-            {
+            if (upcastCount == l) {
                 return upcastCount;
             }
         }
 
         /*
-         *   Examine superclass
+         * Examine superclass
          */
 
         Class superclazz = clazz.getSuperclass();
 
-        if(superclazz != null)
-        {
-            upcastCount = getAccessibleMethods(superclazz , methodInfos, upcastCount);
+        if (superclazz != null) {
+            upcastCount = getAccessibleMethods(superclazz, methodInfos, upcastCount);
 
             /*
-             *  Short circuit if all methods were upcast
+             * Short circuit if all methods were upcast
              */
 
-            if(upcastCount == l)
-            {
+            if (upcastCount == l) {
                 return upcastCount;
             }
         }
 
         /*
-         *  Examine interfaces. Note we do it even if superclazz == null.
-         *  This is redundant as currently java.lang.Object does not implement
-         *  any interfaces, however nothing guarantees it will not in future.
+         * Examine interfaces. Note we do it even if superclazz == null. This is
+         * redundant as currently java.lang.Object does not implement any
+         * interfaces, however nothing guarantees it will not in future.
          */
 
         Class[] interfaces = clazz.getInterfaces();
 
-        for(int i = interfaces.length; i-- > 0; )
-        {
+        for (int i = interfaces.length; i-- > 0;) {
             upcastCount = getAccessibleMethods(interfaces[i], methodInfos, upcastCount);
 
             /*
-             *  Short circuit if all methods were upcast
+             * Short circuit if all methods were upcast
              */
 
-            if(upcastCount == l)
-            {
+            if (upcastCount == l) {
                 return upcastCount;
             }
         }
 
         return upcastCount;
     }
-    
+
     /**
-     *  For a given method, retrieves its publicly accessible counterpart. 
-     *  This method will look for a method with same name
-     *  and signature declared in a public superclass or implemented interface of this 
-     *  method's declaring class. This counterpart method is publicly callable.
-     *
-     *  @param method a method whose publicly callable counterpart is requested.
-     *  @return the publicly callable counterpart method. Note that if the parameter
-     *  method is itself declared by a public class, this method is an identity
-     *  function.
+     * For a given method, retrieves its publicly accessible counterpart. This
+     * method will look for a method with same name and signature declared in a
+     * public superclass or implemented interface of this method's declaring
+     * class. This counterpart method is publicly callable.
+     * 
+     * @param method a method whose publicly callable counterpart is requested.
+     * @return the publicly callable counterpart method. Note that if the
+     *         parameter method is itself declared by a public class, this
+     *         method is an identity function.
      */
-    public static Method getPublicMethod(Method method)
-    {
+    public static Method getPublicMethod(Method method) {
         Class clazz = method.getDeclaringClass();
-        
+
         /*
-         *   Short circuit for (hopefully the majority of) cases where the declaring
-         *   class is public.
+         * Short circuit for (hopefully the majority of) cases where the
+         * declaring class is public.
          */
 
-        if((clazz.getModifiers() & Modifier.PUBLIC) != 0)
-        {
+        if ((clazz.getModifiers() & Modifier.PUBLIC) != 0) {
             return method;
         }
 
@@ -426,65 +376,55 @@
     }
 
     /**
-     *  Looks up the method with specified name and signature in the first public
-     *  superclass or implemented interface of the class. 
+     * Looks up the method with specified name and signature in the first public
+     * superclass or implemented interface of the class.
      * 
-     *  @param class the class whose method is sought
-     *  @param name the name of the method
-     *  @param paramTypes the classes of method parameters
+     * @param class the class whose method is sought
+     * @param name the name of the method
+     * @param paramTypes the classes of method parameters
      */
-    private static Method getPublicMethod(Class clazz, String name, Class[] paramTypes)
-    {
+    private static Method getPublicMethod(Class clazz, String name, Class[] paramTypes) {
         /*
-         *  if this class is public, then try to get it
+         * if this class is public, then try to get it
          */
 
-        if((clazz.getModifiers() & Modifier.PUBLIC) != 0)
-        {
-            try
-            {
+        if ((clazz.getModifiers() & Modifier.PUBLIC) != 0) {
+            try {
                 return clazz.getMethod(name, paramTypes);
-            }
-            catch(NoSuchMethodException e)
-            {
+            } catch (NoSuchMethodException e) {
                 /*
-                 *  If the class does not have the method, then neither its
-                 *  superclass nor any of its interfaces has it so quickly return
-                 *  null.
+                 * If the class does not have the method, then neither its
+                 * superclass nor any of its interfaces has it so quickly return
+                 * null.
                  */
-                 return null;
+                return null;
             }
         }
 
         /*
-         *  try the superclass
+         * try the superclass
          */
 
- 
         Class superclazz = clazz.getSuperclass();
 
-        if ( superclazz != null )
-        {
+        if (superclazz != null) {
             Method superclazzMethod = getPublicMethod(superclazz, name, paramTypes);
-            
-            if(superclazzMethod != null)
-            {
+
+            if (superclazzMethod != null) {
                 return superclazzMethod;
             }
         }
 
         /*
-         *  and interfaces
+         * and interfaces
          */
 
         Class[] interfaces = clazz.getInterfaces();
 
-        for(int i = 0; i < interfaces.length; ++i)
-        {
+        for (int i = 0; i < interfaces.length; ++i) {
             Method interfaceMethod = getPublicMethod(interfaces[i], name, paramTypes);
-            
-            if(interfaceMethod != null)
-            {
+
+            if (interfaceMethod != null) {
                 return interfaceMethod;
             }
         }
@@ -493,26 +433,25 @@
     }
 
     /**
-     *  Used for the iterative discovery process for public methods.
+     * Used for the iterative discovery process for public methods.
      */
-    private static final class MethodInfo
-    {
+    private static final class MethodInfo {
         Method method;
+
         String name;
+
         Class[] parameterTypes;
+
         boolean upcast;
-        
-        MethodInfo(Method method)
-        {
+
+        MethodInfo(Method method) {
             this.method = null;
             name = method.getName();
             parameterTypes = method.getParameterTypes();
             upcast = false;
         }
-        
-        void tryUpcasting(Class clazz)
-            throws NoSuchMethodException
-        {
+
+        void tryUpcasting(Class clazz) throws NoSuchMethodException {
             method = clazz.getMethod(name, parameterTypes);
             name = null;
             parameterTypes = null;

Modified: jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/util/introspection/Info.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/util/introspection/Info.java?rev=397546&r1=397545&r2=397546&view=diff
==============================================================================
--- jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/util/introspection/Info.java
(original)
+++ jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/util/introspection/Info.java
Thu Apr 27 07:01:48 2006
@@ -1,12 +1,12 @@
 /*
- * Copyright 2002,2004 The Apache Software Foundation.
- * 
+ * Copyright 2002-2006 The Apache Software Foundation.
+ *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
- * 
+ *
  *      http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -16,44 +16,40 @@
 package org.apache.commons.jexl.util.introspection;
 
 /**
- *  Little class to carry in info such as template name, line and column
- *  for information error reporting from the uberspector implementations
- *
- *  Taken from velocity for self-sufficiency.
- *
+ * Little class to carry in info such as template name, line and column for
+ * information error reporting from the uberspector implementations
+ * 
+ * Taken from velocity for self-sufficiency.
+ * 
  * @since 1.0
  * @author <a href="mailto:geirm@optonline.net">Geir Magnusson Jr.</a>
  * @version $Id$
  */
-public class Info
-{
+public class Info {
     private int line;
+
     private int column;
+
     private String templateName;
 
-    public Info(String tn, int l, int c)
-    {
+    public Info(String tn, int l, int c) {
         templateName = tn;
         line = l;
         column = c;
     }
 
-    private Info()
-    {
+    private Info() {
     }
 
-    public String getTemplateName()
-    {
+    public String getTemplateName() {
         return templateName;
     }
 
-    public int getLine()
-    {
+    public int getLine() {
         return line;
     }
 
-    public int getColumn()
-    {
+    public int getColumn() {
         return column;
     }
 }

Modified: jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/util/introspection/IntrospectorBase.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/util/introspection/IntrospectorBase.java?rev=397546&r1=397545&r2=397546&view=diff
==============================================================================
--- jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/util/introspection/IntrospectorBase.java
(original)
+++ jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/util/introspection/IntrospectorBase.java
Thu Apr 27 07:01:48 2006
@@ -1,12 +1,12 @@
 /*
  * Copyright 2001,2004 The Apache Software Foundation.
- * 
+ *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
- * 
+ *
  *      http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -16,7 +16,6 @@
 
 package org.apache.commons.jexl.util.introspection;
 
-
 import java.util.Map;
 import java.util.Set;
 import java.util.HashMap;
@@ -25,27 +24,25 @@
 import java.lang.reflect.Method;
 
 /**
- * This basic function of this class is to return a Method
- * object for a particular class given the name of a method
- * and the parameters to the method in the form of an Object[]
- *
- * The first time the Introspector sees a 
- * class it creates a class method map for the
- * class in question. Basically the class method map
- * is a Hastable where Method objects are keyed by a
- * concatenation of the method name and the names of
- * classes that make up the parameters.
- *
+ * This basic function of this class is to return a Method object for a
+ * particular class given the name of a method and the parameters to the method
+ * in the form of an Object[]
+ * 
+ * The first time the Introspector sees a class it creates a class method map
+ * for the class in question. Basically the class method map is a Hastable where
+ * Method objects are keyed by a concatenation of the method name and the names
+ * of classes that make up the parameters.
+ * 
  * For example, a method with the following signature:
- *
+ * 
  * public void method(String a, StringBuffer b)
- *
+ * 
  * would be mapped by the key:
- *
+ * 
  * "method" + "java.lang.String" + "java.lang.StringBuffer"
- *
- * This mapping is performed for all the methods in a class
- * and stored for 
+ * 
+ * This mapping is performed for all the methods in a class and stored for
+ * 
  * @since 1.0
  * @author <a href="mailto:jvanzyl@apache.org">Jason van Zyl</a>
  * @author <a href="mailto:bob@werken.com">Bob McWhirter</a>
@@ -53,101 +50,87 @@
  * @author <a href="mailto:paulo.gaspar@krankikom.de">Paulo Gaspar</a>
  * @version $Id$
  */
-public class IntrospectorBase
-{   
+public class IntrospectorBase {
     /**
-     * Holds the method maps for the classes we know about, keyed by
-     * Class object.
-     */ 
-    protected  Map classMethodMaps = new HashMap();
-    
+     * Holds the method maps for the classes we know about, keyed by Class
+     * object.
+     */
+    protected Map classMethodMaps = new HashMap();
+
     /**
-     * Holds the qualified class names for the classes
-     * we hold in the classMethodMaps hash
+     * Holds the qualified class names for the classes we hold in the
+     * classMethodMaps hash.
      */
     protected Set cachedClassNames = new HashSet();
-   
+
     /**
-     * Gets the method defined by <code>name</code> and
-     * <code>params</code> for the Class <code>c</code>.
-     *
+     * Gets the method defined by <code>name</code> and <code>params</code>
+     * for the Class <code>c</code>.
+     * 
      * @param c Class in which the method search is taking place
      * @param name Name of the method being searched for
-     * @param params An array of Objects (not Classes) that describe the
-     *               the parameters
-     *
+     * @param params An array of Objects (not Classes) that describe the the
+     *            parameters
+     * 
      * @return The desired Method object.
      */
-    public Method getMethod(Class c, String name, Object[] params)
-        throws Exception
-    {
-        if (c == null)
-        {
-            throw new Exception ( 
-                "Introspector.getMethod(): Class method key was null: " + name );
-        }                
+    public Method getMethod(Class c, String name, Object[] params) throws Exception {
+        if (c == null) {
+            throw new Exception("Introspector.getMethod(): Class method key was null: " +
name);
+        }
 
         ClassMap classMap = null;
-        
-        synchronized(classMethodMaps)
-        {
-            classMap = (ClassMap)classMethodMaps.get(c);
-          
+
+        synchronized (classMethodMaps) {
+            classMap = (ClassMap) classMethodMaps.get(c);
+
             /*
-             *  if we don't have this, check to see if we have it
-             *  by name.  if so, then we have a classloader change
-             *  so dump our caches.
+             * if we don't have this, check to see if we have it by name. if so,
+             * then we have a classloader change so dump our caches.
              */
-             
-            if (classMap == null)
-            {                
-                if ( cachedClassNames.contains( c.getName() ))
-                {
+
+            if (classMap == null) {
+                if (cachedClassNames.contains(c.getName())) {
                     /*
-                     * we have a map for a class with same name, but not
-                     * this class we are looking at.  This implies a 
-                     * classloader change, so dump
+                     * we have a map for a class with same name, but not this
+                     * class we are looking at. This implies a classloader
+                     * change, so dump
                      */
-                    clearCache();                    
+                    clearCache();
                 }
-                 
+
                 classMap = createClassMap(c);
             }
         }
-        
+
         return classMap.findMethod(name, params);
     }
 
     /**
-     * Creates a class map for specific class and registers it in the
-     * cache.  Also adds the qualified name to the name->class map
-     * for later Classloader change detection.
+     * Creates a class map for specific class and registers it in the cache.
+     * Also adds the qualified name to the name->class map for later Classloader
+     * change detection.
      */
-    protected ClassMap createClassMap(Class c)
-    {        
-        ClassMap classMap = new ClassMap( c );        
+    protected ClassMap createClassMap(Class c) {
+        ClassMap classMap = new ClassMap(c);
         classMethodMaps.put(c, classMap);
-        cachedClassNames.add( c.getName() );
+        cachedClassNames.add(c.getName());
 
         return classMap;
     }
 
     /**
-     * Clears the classmap and classname
-     * caches
+     * Clears the classmap and classname caches
      */
-    protected void clearCache()
-    {
+    protected void clearCache() {
         /*
-         *  since we are synchronizing on this
-         *  object, we have to clear it rather than
-         *  just dump it.
-         */            
+         * since we are synchronizing on this object, we have to clear it rather
+         * than just dump it.
+         */
         classMethodMaps.clear();
-        
+
         /*
-         * for speed, we can just make a new one
-         * and let the old one be GC'd
+         * for speed, we can just make a new one and let the old one be GC'd
          */
         cachedClassNames = new HashSet();
     }



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


Mime
View raw message