Fix object by prototype-name mappings in res.handlers to have different priorities

for direct and indirect prototypes. Direct prototypes always overrule indirect ones.
This commit is contained in:
hns 2003-07-28 15:16:38 +00:00
parent 5045727f11
commit 294dc989dd
2 changed files with 40 additions and 17 deletions

View file

@ -179,14 +179,19 @@ public final class Prototype {
}
/**
* Register an object as handler for this prototype and all our parent prototypes.
* Register an object as handler for all our parent prototypes.
*/
public final void addToHandlerMap(Map handlers, Object obj) {
if ((parent != null) && !"hopobject".equalsIgnoreCase(parent.getName())) {
parent.addToHandlerMap(handlers, obj);
}
public final void registerParents(Map handlers, Object obj) {
handlers.put(name, obj);
Prototype p = parent;
while ((p != null) && !"hopobject".equalsIgnoreCase(p.getName())) {
if (!handlers.containsKey(p.name)) {
handlers.put(p.name, obj);
}
p = p.parent;
}
}
/**

View file

@ -168,8 +168,6 @@ public final class RequestEvaluator implements Runnable {
session.message = null;
}
Map macroHandlers = res.getMacroHandlers();
try {
if (error != null) {
// there was an error in the previous loop, call error handler
@ -189,7 +187,7 @@ public final class RequestEvaluator implements Runnable {
"".equals(req.path.trim())) {
currentElement = root;
requestPath.add(currentElement);
macroHandlers.put("root", root);
action = getAction(currentElement, null);
if (action == null) {
@ -213,7 +211,7 @@ public final class RequestEvaluator implements Runnable {
currentElement = root;
requestPath.add(currentElement);
macroHandlers.put("root", root);
for (int i = 0; i < ntokens; i++) {
if (currentElement == null) {
@ -242,13 +240,6 @@ public final class RequestEvaluator implements Runnable {
if (currentElement != null) {
// add to requestPath array
requestPath.add(currentElement);
Prototype proto = app.getPrototype(currentElement);
if (proto != null) {
proto.addToHandlerMap(macroHandlers,
currentElement);
}
}
}
}
@ -288,6 +279,33 @@ public final class RequestEvaluator implements Runnable {
}
}
// register path objects with their prototype names in
// res.handlers
Map macroHandlers = res.getMacroHandlers();
int l = requestPath.size();
Prototype[] protos = new Prototype[l];
for (int i=0; i<l; i++) {
Object obj = requestPath.get(i);
protos[i] = app.getPrototype(obj);
// immediately register objects with their direct prototype name
if (protos[i] != null) {
macroHandlers.put(protos[i].getName(), obj);
}
}
// in a second pass, we register path objects with their indirect
// (i.e. parent prototype) names, starting at the end and only
// if the name isn't occupied yet.
for (int i=l-1; i>=0; i--) {
if (protos[i] != null) {
protos[i].registerParents(macroHandlers, requestPath.get(i));
}
}
/////////////////////////////////////////////////////////////////////////////
// end of path resolution section
/////////////////////////////////////////////////////////////////////////////