Build prototype-name to path objects mapping in path object from res.handlers rather than

finding out ourselves.
This commit is contained in:
hns 2003-07-28 15:18:51 +00:00
parent 294dc989dd
commit 1e16d82ba9

View file

@ -187,25 +187,33 @@ public class RhinoEngine implements ScriptingEngine {
Scriptable scriptable = null; Scriptable scriptable = null;
try { try {
// we do a lot of extra work to make access to global variables // we do some extra work with the path object: first, we create a native
// comfortable to EcmaScript coders, i.e. we use a lot of custom wrappers // JavaScript array, then we register objects by
// that expose properties and functions in a special way instead of just going // their prototype name, which we take from res.handlers.
// with the standard java object wrappers.
if ("path".equals(k)) { if ("path".equals(k)) {
Scriptable arr = context.newObject(global, "Array"); Scriptable arr = context.newObject(global, "Array");
List path = (List) v; List path = (List) v;
int length = path.size();
Scriptable[] wrapped = new Scriptable[length]
// register path elements with their prototype // Move through the path list and set the path array.
for (int j = 0; j < path.size(); j++) { for (int j = 0; j < length; j++) {
Object pathElem = path.get(j); Object pathElem = path.get(j);
Scriptable wrappedElement = Context.toObject(pathElem, global); Scriptable wrappedElement = Context.toObject(pathElem, global);
arr.put(j, arr, wrappedElement); arr.put(j, arr, wrappedElement);
wrapped[j] = wrappedElement;
}
String protoname = app.getPrototypeName(pathElem); // register path elements with their prototypes on the path array
ResponseTrans res = getResponse();
Map handlers = res.getMacroHandlers();
if (protoname != null) { if (handlers != null) {
arr.put(protoname, arr, wrappedElement); for (Iterator h = handlers.entrySet().iterator(); h.hasNext(); ) {
Map.Entry entry = (Map.Entry) h.next();
int idx = path.indexOf(entry.getValue());
arr.put(entry.getKey().toString(), arr, wrapped[idx]);
} }
} }