* Implement negative result caching in getPrototypeName(Object).
This commit is contained in:
parent
2b7e92d9f6
commit
4494d0bff5
1 changed files with 34 additions and 33 deletions
|
@ -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,41 +1317,40 @@ 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
|
Class clazz = obj.getClass();
|
||||||
if (obj instanceof IPathElement) {
|
String className = clazz.getName();
|
||||||
// e implements the getPrototype() method
|
String protoName = classMapping.getProperty(className);
|
||||||
return ((IPathElement) obj).getPrototype();
|
if (protoName != null) {
|
||||||
} else {
|
return protoName == CLASS_NOT_MAPPED ? null : protoName;
|
||||||
// look up prototype name by java class name
|
|
||||||
Class clazz = obj.getClass();
|
|
||||||
String protoname = classMapping.getProperty(clazz.getName());
|
|
||||||
if (protoname != null) {
|
|
||||||
return protoname;
|
|
||||||
}
|
|
||||||
// walk down superclass path
|
|
||||||
while ((clazz = clazz.getSuperclass()) != null) {
|
|
||||||
protoname = classMapping.getProperty(clazz.getName());
|
|
||||||
if (protoname != null) {
|
|
||||||
// cache the class name for the object so we run faster next time
|
|
||||||
classMapping.setProperty(obj.getClass().getName(), protoname);
|
|
||||||
return protoname;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// check interfaces, too
|
|
||||||
Class[] classes = obj.getClass().getInterfaces();
|
|
||||||
for (int i = 0; i < classes.length; i++) {
|
|
||||||
protoname = classMapping.getProperty(classes[i].getName());
|
|
||||||
if (protoname != null) {
|
|
||||||
// cache the class name for the object so we run faster next time
|
|
||||||
classMapping.setProperty(obj.getClass().getName(), protoname);
|
|
||||||
return protoname;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// nada
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// walk down superclass path
|
||||||
|
while ((clazz = clazz.getSuperclass()) != null) {
|
||||||
|
protoName = classMapping.getProperty(clazz.getName());
|
||||||
|
if (protoName != null) {
|
||||||
|
// cache the class name for the object so we run faster next time
|
||||||
|
classMapping.setProperty(className, protoName);
|
||||||
|
return protoName;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// check interfaces, too
|
||||||
|
Class[] classes = obj.getClass().getInterfaces();
|
||||||
|
for (int i = 0; i < classes.length; i++) {
|
||||||
|
protoName = classMapping.getProperty(classes[i].getName());
|
||||||
|
if (protoName != null) {
|
||||||
|
// cache the class name for the object so we run faster next time
|
||||||
|
classMapping.setProperty(className, protoName);
|
||||||
|
return protoName;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// not mapped - cache negative result
|
||||||
|
classMapping.setProperty(className, CLASS_NOT_MAPPED);
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DocApplication getDoc() {
|
public DocApplication getDoc() {
|
||||||
|
|
Loading…
Add table
Reference in a new issue