Author: henning
Date: Sun Nov 19 02:06:21 2006
New Revision: 476785

URL: http://svn.apache.org/viewvc?view=rev&rev=476785
Log:
Clean up coding style a bit, make members private final and accessible
through getters.

Modified:
    
jakarta/velocity/engine/trunk/src/java/org/apache/velocity/util/introspection/Introspector.java
    
jakarta/velocity/engine/trunk/src/java/org/apache/velocity/util/introspection/IntrospectorBase.java
    
jakarta/velocity/engine/trunk/src/java/org/apache/velocity/util/introspection/MethodMap.java
    
jakarta/velocity/engine/trunk/src/java/org/apache/velocity/util/introspection/SecureIntrospectorImpl.java

Modified: 
jakarta/velocity/engine/trunk/src/java/org/apache/velocity/util/introspection/Introspector.java
URL: 
http://svn.apache.org/viewvc/jakarta/velocity/engine/trunk/src/java/org/apache/velocity/util/introspection/Introspector.java?view=diff&rev=476785&r1=476784&r2=476785
==============================================================================
--- 
jakarta/velocity/engine/trunk/src/java/org/apache/velocity/util/introspection/Introspector.java
 (original)
+++ 
jakarta/velocity/engine/trunk/src/java/org/apache/velocity/util/introspection/Introspector.java
 Sun Nov 19 02:06:21 2006
@@ -20,9 +20,10 @@
  */
 
 import java.lang.reflect.Method;
+
+import org.apache.velocity.runtime.RuntimeLogger;
 import org.apache.velocity.runtime.log.Log;
 import org.apache.velocity.runtime.log.RuntimeLoggerLog;
-import org.apache.velocity.runtime.RuntimeLogger;
 
 /**
  * This basic function of this class is to return a Method
@@ -50,6 +51,7 @@
  * @author <a href="mailto:[EMAIL PROTECTED]">Bob McWhirter</a>
  * @author <a href="mailto:[EMAIL PROTECTED]">Attila Szegedi</a>
  * @author <a href="mailto:[EMAIL PROTECTED]">Paulo Gaspar</a>
+ * @author <a href="mailto:[EMAIL PROTECTED]">Henning P. Schmiedehausen</a>
  * @version $Id$
  */
 public class Introspector extends IntrospectorBase
@@ -65,21 +67,21 @@
     /**
      * The Log we use
      */
-    protected Log log = null;
+    protected final Log log;
 
     /**
-     * @param log
+     * @param log A Log object to use for the introspector.
      */
-    public Introspector(Log log)
+    public Introspector(final Log log)
     {
         this.log = log;
     }
 
     /**
-     * @param logger
+     * @param logger A runtime logger object.
      * @deprecated RuntimeLogger is deprecated. Use Introspector(Log log).
      */
-    public Introspector(RuntimeLogger logger)
+    public Introspector(final RuntimeLogger logger)
     {
         this(new RuntimeLoggerLog(logger));
     }
@@ -94,10 +96,10 @@
      *               the parameters
      *
      * @return The desired Method object.
-     * @throws Exception
+     * @throws IllegalArgumentException When the parameters passed in can not 
be used for introspection.
      */
-    public Method getMethod(Class c, String name, Object[] params)
-        throws Exception
+    public Method getMethod(final Class c, final String name, final Object[] 
params)
+        throws IllegalArgumentException
     {
         /*
          *  just delegate to the base class
@@ -105,9 +107,9 @@
 
         try
         {
-            return super.getMethod( c, name, params );
+            return super.getMethod(c, name, params);
         }
-        catch( MethodMap.AmbiguousException ae )
+        catch(MethodMap.AmbiguousException ae)
         {
             /*
              *  whoops.  Ambiguous.  Make a nice log message and return null...
@@ -115,11 +117,11 @@
 
             StringBuffer msg = new StringBuffer("Introspection Error : 
Ambiguous method invocation ")
                     .append(name)
-                    .append("( ");
+                    .append("(");
 
             for (int i = 0; i < params.length; i++)
             {
-                if ( i > 0)
+                if (i > 0)
                 {
                     msg.append(", ");
                 }
@@ -137,7 +139,7 @@
             msg.append(") for class ")
                     .append(c);
 
-            log.error( msg.toString());
+            log.error(msg.toString());
         }
 
         return null;
@@ -150,6 +152,6 @@
     protected void clearCache()
     {
         super.clearCache();
-        log.info( CACHEDUMP_MSG );
+        log.info(CACHEDUMP_MSG);
     }
 }

Modified: 
jakarta/velocity/engine/trunk/src/java/org/apache/velocity/util/introspection/IntrospectorBase.java
URL: 
http://svn.apache.org/viewvc/jakarta/velocity/engine/trunk/src/java/org/apache/velocity/util/introspection/IntrospectorBase.java?view=diff&rev=476785&r1=476784&r2=476785
==============================================================================
--- 
jakarta/velocity/engine/trunk/src/java/org/apache/velocity/util/introspection/IntrospectorBase.java
 (original)
+++ 
jakarta/velocity/engine/trunk/src/java/org/apache/velocity/util/introspection/IntrospectorBase.java
 Sun Nov 19 02:06:21 2006
@@ -52,6 +52,7 @@
  * @author <a href="mailto:[EMAIL PROTECTED]">Bob McWhirter</a>
  * @author <a href="mailto:[EMAIL PROTECTED]">Attila Szegedi</a>
  * @author <a href="mailto:[EMAIL PROTECTED]">Paulo Gaspar</a>
+ * @author <a href="mailto:[EMAIL PROTECTED]">Henning P. Schmiedehausen</a>
  * @version $Id$
  */
 public class IntrospectorBase
@@ -60,13 +61,13 @@
      * Holds the method maps for the classes we know about, keyed by
      * Class object.
      */
-    protected  Map classMethodMaps = new HashMap();
+    private final Map classMethodMaps = new HashMap();
 
     /**
      * Holds the qualified class names for the classes
      * we hold in the classMethodMaps hash
      */
-    protected Set cachedClassNames = new HashSet();
+    private final Set cachedClassNames = new HashSet();
 
     /**
      * Gets the method defined by <code>name</code> and
@@ -78,15 +79,16 @@
      *               the parameters
      *
      * @return The desired Method object.
-     * @throws Exception
+     * @throws IllegalArgumentException When the parameters passed in can not 
be used for introspection.
+     * @throws MethodMap.AmbiguousException When the method map contains more 
than one match for the requested signature.
      */
-    public Method getMethod(Class c, String name, Object[] params)
-        throws Exception
+    public Method getMethod(final Class c, final String name, final Object[] 
params)
+            throws IllegalArgumentException,MethodMap.AmbiguousException
     {
         if (c == null)
         {
-            throw new Exception (
-                "Introspector.getMethod(): Class method key was null: " + name 
);
+            throw new IllegalArgumentException (
+                "Introspector.getMethod(): Class method key was null: " + 
name);
         }
 
         ClassMap classMap = null;
@@ -103,7 +105,7 @@
 
             if (classMap == null)
             {
-                if ( cachedClassNames.contains( c.getName() ))
+                if (cachedClassNames.contains(c.getName()))
                 {
                     /*
                      * we have a map for a class with same name, but not
@@ -122,37 +124,52 @@
 
     /**
      * Creates a class map for specific class and registers it in the
-     * cache.  Also adds the qualified name to the name->class map
+     * cache.  Also adds the qualified name to the name-&gt;class map
      * for later Classloader change detection.
-     * @param c
+     * @param c The class for which the class map gets generated.
      * @return A ClassMap object.
      */
-    protected ClassMap createClassMap(Class c)
+    protected ClassMap createClassMap(final Class c)
     {
-        ClassMap classMap = new ClassMap( 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()
     {
-        /*
-         *  since we are synchronizing on this
-         *  object, we have to clear it rather than
-         *  just dump it.
-         */
+       /*
+        * classes extending IntrospectorBase can request these objects through 
the
+        * protected getters. If we swap them out with new objects, the base 
class
+        * and the extended class can actually how two different objects. Don't 
do this.
+        * Make the members final and use clear() to reset the cache.
+        */
         classMethodMaps.clear();
+        cachedClassNames.clear();
+    }
 
-        /*
-         * for speed, we can just make a new one
-         * and let the old one be GC'd
-         */
-        cachedClassNames = new HashSet();
+    /**
+     * Access to the classMethodMaps map.
+     *
+     * @return The classMethodsMaps HashMap.
+     */
+    protected Map getClassMethodMaps()
+    {
+        return classMethodMaps;
+    }
+
+    /**
+     * Access to the list of cached class names.
+     *
+     * @return A set of names cached.
+     */
+    protected Set getCachedClassNames()
+    {
+        return cachedClassNames;
     }
 }

Modified: 
jakarta/velocity/engine/trunk/src/java/org/apache/velocity/util/introspection/MethodMap.java
URL: 
http://svn.apache.org/viewvc/jakarta/velocity/engine/trunk/src/java/org/apache/velocity/util/introspection/MethodMap.java?view=diff&rev=476785&r1=476784&r2=476785
==============================================================================
--- 
jakarta/velocity/engine/trunk/src/java/org/apache/velocity/util/introspection/MethodMap.java
 (original)
+++ 
jakarta/velocity/engine/trunk/src/java/org/apache/velocity/util/introspection/MethodMap.java
 Sun Nov 19 02:06:21 2006
@@ -140,12 +140,12 @@
      *  we run across ambiguous overloading.  Caught
      *  by the introspector.
      */
-    public static class AmbiguousException extends Exception
+    public static class AmbiguousException extends RuntimeException
     {
         /**
          * Version Id for serializable
          */
-        private static final long serialVersionUID = -2314636505414551662L;
+        private static final long serialVersionUID = -2314636505414551663L;
     }
 
 

Modified: 
jakarta/velocity/engine/trunk/src/java/org/apache/velocity/util/introspection/SecureIntrospectorImpl.java
URL: 
http://svn.apache.org/viewvc/jakarta/velocity/engine/trunk/src/java/org/apache/velocity/util/introspection/SecureIntrospectorImpl.java?view=diff&rev=476785&r1=476784&r2=476785
==============================================================================
--- 
jakarta/velocity/engine/trunk/src/java/org/apache/velocity/util/introspection/SecureIntrospectorImpl.java
 (original)
+++ 
jakarta/velocity/engine/trunk/src/java/org/apache/velocity/util/introspection/SecureIntrospectorImpl.java
 Sun Nov 19 02:06:21 2006
@@ -58,7 +58,7 @@
      * @return Method object retrieved by Introspector
      * @throws Exception 
      */
-    public Method getMethod(Class clazz, String methodName, Object[] params) 
throws Exception
+    public Method getMethod(Class clazz, String methodName, Object[] params) 
throws IllegalArgumentException
     {
         if (!checkObjectExecutePermission(clazz,methodName))
         {



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

Reply via email to