* Implement negative result caching in getPrototypeName(Object).

This commit is contained in:
hns 2007-03-15 16:21:00 +00:00
parent 2b7e92d9f6
commit 4494d0bff5

View file

@ -168,9 +168,11 @@ public final class Application implements Runnable {
Hashtable customCronJobs = null; Hashtable customCronJobs = null;
private ResourceComparator resourceComparator; private ResourceComparator resourceComparator;
private Resource currentCodeResource; private Resource currentCodeResource;
// Field to cache unmapped java classes
private final static String CLASS_NOT_MAPPED = "(unmapped)";
/** /**
* Simple constructor for dead application instances. * Simple constructor for dead application instances.
*/ */
@ -1315,42 +1317,41 @@ public final class Application implements Runnable {
public String getPrototypeName(Object obj) { public String getPrototypeName(Object obj) {
if (obj == null) { if (obj == null) {
return "global"; return "global";
} else if (obj instanceof IPathElement) {
// check if e implements the IPathElement interface
return ((IPathElement) obj).getPrototype();
} }
// check if e implements the IPathElement interface
if (obj instanceof IPathElement) {
// e implements the getPrototype() method
return ((IPathElement) obj).getPrototype();
} else {
// look up prototype name by java class name
Class clazz = obj.getClass(); Class clazz = obj.getClass();
String protoname = classMapping.getProperty(clazz.getName()); String className = clazz.getName();
if (protoname != null) { String protoName = classMapping.getProperty(className);
return protoname; if (protoName != null) {
return protoName == CLASS_NOT_MAPPED ? null : protoName;
} }
// walk down superclass path // walk down superclass path
while ((clazz = clazz.getSuperclass()) != null) { while ((clazz = clazz.getSuperclass()) != null) {
protoname = classMapping.getProperty(clazz.getName()); protoName = classMapping.getProperty(clazz.getName());
if (protoname != null) { if (protoName != null) {
// cache the class name for the object so we run faster next time // cache the class name for the object so we run faster next time
classMapping.setProperty(obj.getClass().getName(), protoname); classMapping.setProperty(className, protoName);
return protoname; return protoName;
} }
} }
// check interfaces, too // check interfaces, too
Class[] classes = obj.getClass().getInterfaces(); Class[] classes = obj.getClass().getInterfaces();
for (int i = 0; i < classes.length; i++) { for (int i = 0; i < classes.length; i++) {
protoname = classMapping.getProperty(classes[i].getName()); protoName = classMapping.getProperty(classes[i].getName());
if (protoname != null) { if (protoName != null) {
// cache the class name for the object so we run faster next time // cache the class name for the object so we run faster next time
classMapping.setProperty(obj.getClass().getName(), protoname); classMapping.setProperty(className, protoName);
return protoname; return protoName;
} }
} }
// nada // not mapped - cache negative result
classMapping.setProperty(className, CLASS_NOT_MAPPED);
return null; return null;
} }
}
public DocApplication getDoc() { public DocApplication getDoc() {
RequestEvaluator eval = null; RequestEvaluator eval = null;