From 294dc989dd8aa42078dfa5dd55f043ae67258cdd Mon Sep 17 00:00:00 2001 From: hns Date: Mon, 28 Jul 2003 15:16:38 +0000 Subject: [PATCH] Fix object by prototype-name mappings in res.handlers to have different priorities for direct and indirect prototypes. Direct prototypes always overrule indirect ones. --- src/helma/framework/core/Prototype.java | 17 +++++--- .../framework/core/RequestEvaluator.java | 40 ++++++++++++++----- 2 files changed, 40 insertions(+), 17 deletions(-) diff --git a/src/helma/framework/core/Prototype.java b/src/helma/framework/core/Prototype.java index 73541fa3..2d6fa701 100644 --- a/src/helma/framework/core/Prototype.java +++ b/src/helma/framework/core/Prototype.java @@ -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; + } } /** diff --git a/src/helma/framework/core/RequestEvaluator.java b/src/helma/framework/core/RequestEvaluator.java index 005201b8..c9186684 100644 --- a/src/helma/framework/core/RequestEvaluator.java +++ b/src/helma/framework/core/RequestEvaluator.java @@ -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=0; i--) { + if (protos[i] != null) { + protos[i].registerParents(macroHandlers, requestPath.get(i)); + } + } + ///////////////////////////////////////////////////////////////////////////// // end of path resolution section /////////////////////////////////////////////////////////////////////////////