Added JavaScript function stub to Node.prefetchChildren().

This commit is contained in:
hns 2002-09-13 16:15:40 +00:00
parent abd0b867b3
commit b6f8c5edb3
2 changed files with 60 additions and 1 deletions

View file

@ -189,6 +189,36 @@ public class ESNode extends ObjectPrototype {
return -1;
}
/**
* Prefetch child objects from (relational) database.
*/
public void prefetchChildren (ESValue args[]) throws Exception {
checkNode ();
if (!(node instanceof Node))
return;
int start = 0, length = 0;
try {
if (args.length == 0) {
start = 0;
length = 1000;
} else if (args.length == 2) {
if (args[0].isNumberValue ())
start = args[0].toInt32 ();
else
throw new RuntimeException ("Illegal argument in prefetchChildren: "+args[0]);
if (args[1].isNumberValue ())
length = args[1].toInt32 ();
else
throw new RuntimeException ("Illegal argument in prefetchChildren: "+args[1]);
} else {
throw new RuntimeException ("Wrong number of arguments in prefetchChildren");
}
} catch (Exception x) {
throw new IllegalArgumentException (x.getMessage());
}
((Node) node).prefetchChildren (start, length);
}
/**
* This used to be different from add(), it isn't anymore. It's left here for
* compatibility.

View file

@ -82,6 +82,7 @@ public final class HopExtension {
esNodePrototype.putHiddenProperty ("href", new NodeHref ("href", evaluator, fp));
esNodePrototype.putHiddenProperty ("setParent", new NodeSetParent ("setParent", evaluator, fp));
esNodePrototype.putHiddenProperty ("invalidate", new NodeInvalidate ("invalidate", evaluator, fp));
esNodePrototype.putHiddenProperty ("prefetchChildren", new NodePrefetch ("prefetchChildren", evaluator, fp));
esNodePrototype.putHiddenProperty ("renderSkin", new RenderSkin ("renderSkin", evaluator, fp, false, false));
esNodePrototype.putHiddenProperty ("renderSkinAsString", new RenderSkin ("renderSkinAsString", evaluator, fp, false, true));
esNodePrototype.putHiddenProperty ("clearCache", new NodeClearCache ("clearCache", evaluator, fp));
@ -244,6 +245,24 @@ public final class HopExtension {
}
}
class NodePrefetch extends BuiltinFunctionObject {
NodePrefetch (String name, Evaluator evaluator, FunctionPrototype fp) {
super (fp, evaluator, name, 0);
}
public ESValue callFunction (ESObject thisObject, ESValue[] arguments) throws EcmaScriptException {
try {
ESNode esn = (ESNode) thisObject;
esn.prefetchChildren (arguments);
} catch (IllegalArgumentException illarg) {
throw illarg;
} catch (Exception x) {
// swallow exceptions in prefetchChildren
}
return ESNull.theNull;
}
}
class NodeEditor extends BuiltinFunctionObject {
@ -718,6 +737,7 @@ public final class HopExtension {
String tmpname = arguments.length == 0 ? "" : arguments[0].toString ();
String basicHref =app.getNodeHref (elem, tmpname);
String hrefSkin = app.getProperty ("hrefSkin", null);
// FIXME: we should actually walk down the path from the object we called href() on
// instead we move down the URL path.
if (hrefSkin != null) {
@ -725,10 +745,19 @@ public final class HopExtension {
// first, look in the object href was called on.
Object skinElem = elem;
Skin skin = null;
// ResponseTrans res = fesi.getResponse();
// Object[] skinpath = res.getSkinpath ();
while (skin == null && skinElem != null) {
Prototype proto = app.getPrototype (skinElem);
if (proto != null)
if (proto != null) {
skin = proto.getSkin (hrefSkin);
/* String skinid = proto.getName()+"/"+hrefSkin;
skin = res.getCachedSkin (skinid);
if (skin == null) {
skin = app.getSkin (skinElem, hrefSkin, skinpath);
res.cacheSkin (skinid, skin);
} */
}
if (skin == null)
skinElem = app.getParentElement (skinElem);
}