geirm 01/12/05 13:23:31
Modified: src/java/org/apache/velocity/util/introspection
ClassMap.java Introspector.java
Log:
Introspector.java : extends IntrospectorBase so it can use the Velocity
runtime services and keep IntrospectorBase.java free.
ClassMap : removed the dependency on rsvc and have it just throw the
ambiguity exception upwards...
Revision Changes Path
1.19 +9 -22
jakarta-velocity/src/java/org/apache/velocity/util/introspection/ClassMap.java
Index: ClassMap.java
===================================================================
RCS file:
/home/cvs/jakarta-velocity/src/java/org/apache/velocity/util/introspection/ClassMap.java,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -r1.18 -r1.19
--- ClassMap.java 2001/11/27 00:40:46 1.18
+++ ClassMap.java 2001/12/05 21:23:31 1.19
@@ -61,8 +61,6 @@
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
-import org.apache.velocity.runtime.RuntimeServices;
-
/**
* A cache of introspection information for a specific class instance.
* Keys {@link java.lang.Method} objects by a concatenation of the
@@ -72,12 +70,10 @@
* @author <a href="mailto:[EMAIL PROTECTED]">Bob McWhirter</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Attila Szegedi</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Geir Magnusson Jr.</a>
- * @version $Id: ClassMap.java,v 1.18 2001/11/27 00:40:46 geirm Exp $
+ * @version $Id: ClassMap.java,v 1.19 2001/12/05 21:23:31 geirm Exp $
*/
public class ClassMap
{
- private RuntimeServices rsvc = null;
-
private static final class CacheMiss { }
private static final CacheMiss CACHE_MISS = new CacheMiss();
private static final Object OBJECT = new Object();
@@ -100,10 +96,9 @@
/**
* Standard constructor
*/
- public ClassMap( RuntimeServices rsvc, Class clazz)
+ public ClassMap( Class clazz)
{
this.clazz = clazz;
- this.rsvc = rsvc;
populateMethodCache();
}
@@ -132,6 +127,7 @@
* 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 );
@@ -150,23 +146,14 @@
}
catch( MethodMap.AmbiguousException ae )
{
+ /*
+ * that's a miss :)
+ */
- String msg = "Introspection Error : Ambiguous method invocation "
- + name + "( ";
+ methodCache.put( methodKey,
+ CACHE_MISS );
- for (int i = 0; i < params.length; i++)
- {
- if ( i > 0)
- msg = msg + ", ";
-
- msg = msg + params[i].getClass().getName();
- }
-
- msg = msg + ") for class " + clazz;
-
- rsvc.error( msg );
-
- cacheEntry = null;
+ throw ae;
}
if ( cacheEntry == null )
1.19 +33 -71
jakarta-velocity/src/java/org/apache/velocity/util/introspection/Introspector.java
Index: Introspector.java
===================================================================
RCS file:
/home/cvs/jakarta-velocity/src/java/org/apache/velocity/util/introspection/Introspector.java,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -r1.18 -r1.19
--- Introspector.java 2001/11/26 16:01:14 1.18
+++ Introspector.java 2001/12/05 21:23:31 1.19
@@ -89,31 +89,22 @@
* @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>
- * @version $Id: Introspector.java,v 1.18 2001/11/26 16:01:14 geirm Exp $
+ * @version $Id: Introspector.java,v 1.19 2001/12/05 21:23:31 geirm Exp $
*/
-public class Introspector
+public class Introspector extends IntrospectorBase
{
- /*
+ /**
* define a public string so that it can be looked for
* if interested
*/
public final static String CACHEDUMP_MSG =
"Introspector : detected classloader change. Dumping cache.";
-
- private RuntimeServices rsvc = null;
- /**
- * Holds the method maps for the classes we know about, keyed by
- * Class object.
- */
- private final Map classMethodMaps = new HashMap();
-
/**
- * Holds the qualified class names for the classes
- * we hold in the classMethodMaps hash
+ * our engine runtime services
*/
- private Set cachedClassNames = new HashSet();
+ private RuntimeServices rsvc = null;
/**
* Recieves our RuntimeServices object
@@ -132,75 +123,46 @@
public Method getMethod(Class c, String name, Object[] params)
throws Exception
{
- if (c == null)
+ /*
+ * just delegate to the base class
+ */
+
+ try
{
- throw new Exception (
- "Introspector.getMethod(): Class method key was null: " + name );
- }
-
- ClassMap classMap = null;
-
- synchronized(classMethodMaps)
+ return super.getMethod( c, name, params );
+ }
+ catch( MethodMap.AmbiguousException ae )
{
- 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.
+ * whoops. Ambiguous. Make a nice log message and return null...
*/
-
- 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
- */
- clearCache();
- rsvc.info( CACHEDUMP_MSG );
- }
-
- classMap = createClassMap(c);
+
+ String msg = "Introspection Error : Ambiguous method invocation "
+ + name + "( ";
+
+ for (int i = 0; i < params.length; i++)
+ {
+ if ( i > 0)
+ msg = msg + ", ";
+
+ msg = msg + params[i].getClass().getName();
}
+
+ msg = msg + ") for class " + c;
+
+ rsvc.error( msg );
}
-
- 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.
- */
- private ClassMap createClassMap(Class c)
- {
- ClassMap classMap = new ClassMap( rsvc, c );
- classMethodMaps.put(c, classMap);
- cachedClassNames.add( c.getName() );
- return classMap;
+ return null;
}
/**
* Clears the classmap and classname
- * caches
+ * caches, and logs that we did so
*/
- private void clearCache()
+ protected void clearCache()
{
- /*
- * 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
- */
- cachedClassNames = new HashSet();
+ super.clearCache();
+ rsvc.info( CACHEDUMP_MSG );
}
}
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>