diff --git a/src/helma/objectmodel/db/OrderedSubnodeList.java b/src/helma/objectmodel/db/OrderedSubnodeList.java index 2876c93f..cb9a5d71 100644 --- a/src/helma/objectmodel/db/OrderedSubnodeList.java +++ b/src/helma/objectmodel/db/OrderedSubnodeList.java @@ -381,7 +381,7 @@ public class OrderedSubnodeList extends SubnodeList { return 0; } - public List getOrderedView (String order) { + public SubnodeList getOrderedView (String order) { if (origin != null) { return origin.getOrderedView(order); } else { diff --git a/src/helma/objectmodel/db/SubnodeList.java b/src/helma/objectmodel/db/SubnodeList.java index 7218386d..1de67312 100644 --- a/src/helma/objectmodel/db/SubnodeList.java +++ b/src/helma/objectmodel/db/SubnodeList.java @@ -104,7 +104,7 @@ public class SubnodeList extends ArrayList { } } - public List getOrderedView (String order) { + public SubnodeList getOrderedView (String order) { String key = order.trim().toLowerCase(); // long start = System.currentTimeMillis(); if (views == null) { diff --git a/src/helma/scripting/rhino/HopObject.java b/src/helma/scripting/rhino/HopObject.java index 8300e937..9b6319c7 100644 --- a/src/helma/scripting/rhino/HopObject.java +++ b/src/helma/scripting/rhino/HopObject.java @@ -20,6 +20,7 @@ import helma.framework.core.*; import helma.framework.repository.Resource; import helma.objectmodel.*; import helma.objectmodel.db.*; +import helma.objectmodel.db.Node; import org.mozilla.javascript.*; import java.lang.reflect.Method; @@ -170,13 +171,13 @@ public class HopObject extends ScriptableObject implements Wrapper, PropertyReco */ private void checkNode() { if (node != null && node.getState() == INode.INVALID) { - if (node instanceof helma.objectmodel.db.Node) { - NodeHandle handle = ((helma.objectmodel.db.Node) node).getHandle(); + if (node instanceof Node) { + NodeHandle handle = ((Node) node).getHandle(); node = handle.getNode(core.app.getWrappedNodeManager()); if (node == null) { // we probably have a deleted node. Replace with empty transient node // to avoid throwing an exception. - node = new helma.objectmodel.TransientNode(); + node = new TransientNode(); // throw new RuntimeException("Tried to access invalid/removed node " + handle + "."); } } @@ -455,14 +456,14 @@ public class HopObject extends ScriptableObject implements Wrapper, PropertyReco } private void prefetchChildren(int start, int length) { - if (!(node instanceof helma.objectmodel.db.Node)) { + if (!(node instanceof Node)) { return; } checkNode(); try { - ((helma.objectmodel.db.Node) node).prefetchChildren(start, length); + ((Node) node).prefetchChildren(start, length); } catch (Exception x) { core.app.logError("Error in HopObject.prefetchChildren: " + x, x); } @@ -638,8 +639,8 @@ public class HopObject extends ScriptableObject implements Wrapper, PropertyReco checkNode(); - if (node instanceof helma.objectmodel.db.Node) { - ((helma.objectmodel.db.Node) node).persist(); + if (node instanceof Node) { + ((Node) node).persist(); return node.getID(); } return null; @@ -649,19 +650,19 @@ public class HopObject extends ScriptableObject implements Wrapper, PropertyReco * Invalidate the node itself or a subnode */ public boolean jsFunction_invalidate(Object childId) { - if (childId != null && node instanceof helma.objectmodel.db.Node) { + if (childId != null && node instanceof Node) { if (childId == Undefined.instance) { if (node.getState() == INode.INVALID) { return true; } - ((helma.objectmodel.db.Node) node).invalidate(); + ((Node) node).invalidate(); } else { checkNode(); - ((helma.objectmodel.db.Node) node).invalidateNode(childId.toString()); + ((Node) node).invalidateNode(childId.toString()); } } @@ -675,7 +676,7 @@ public class HopObject extends ScriptableObject implements Wrapper, PropertyReco * @return true if the the wrapped Node has a valid database id. */ public boolean jsFunction_isPersistent() { - if (!(node instanceof helma.objectmodel.db.Node)) { + if (!(node instanceof Node)) { return false; } checkNode(); @@ -690,7 +691,7 @@ public class HopObject extends ScriptableObject implements Wrapper, PropertyReco * @return true if the the wrapped Node is not stored in a database. */ public boolean jsFunction_isTransient() { - if (!(node instanceof helma.objectmodel.db.Node)) { + if (!(node instanceof Node)) { return true; } checkNode(); @@ -1096,10 +1097,10 @@ public class HopObject extends ScriptableObject implements Wrapper, PropertyReco * do have a higher id than the last record loaded by this collection */ public int jsFunction_update() { - if (!(node instanceof helma.objectmodel.db.Node)) + if (!(node instanceof Node)) throw new RuntimeException ("update only callabel on persistent HopObjects"); checkNode(); - helma.objectmodel.db.Node n = (helma.objectmodel.db.Node) node; + Node n = (Node) node; return n.updateSubnodes(); } @@ -1111,18 +1112,19 @@ public class HopObject extends ScriptableObject implements Wrapper, PropertyReco * @return ListViewWrapper holding the information of the ordered view */ public Object jsFunction_getOrderedView(String expr) { - if (!(node instanceof helma.objectmodel.db.Node)) { + if (!(node instanceof Node)) { throw new RuntimeException ( "getOrderedView only callable on persistent HopObjects"); } - helma.objectmodel.db.Node n = (helma.objectmodel.db.Node) node; + Node n = (Node) node; n.loadNodes(); SubnodeList subnodes = n.getSubnodeList(); if (subnodes == null) { throw new RuntimeException ( "getOrderedView only callable on already existing subnode-collections"); } - return new ListViewWrapper (subnodes.getOrderedView(expr), - core, core.app.getWrappedNodeManager(), this); + Node subnode = new Node("OrderedView", "HopObject", core.app.getWrappedNodeManager()); + subnode.setSubnodes(subnodes.getOrderedView(expr)); + return new HopObject("HopObject", core, subnode, core.getPrototype("HopObject")); } } diff --git a/src/helma/scripting/rhino/ListViewWrapper.java b/src/helma/scripting/rhino/ListViewWrapper.java deleted file mode 100644 index 66e006de..00000000 --- a/src/helma/scripting/rhino/ListViewWrapper.java +++ /dev/null @@ -1,337 +0,0 @@ -/* - * Helma License Notice - * - * The contents of this file are subject to the Helma License - * Version 2.0 (the "License"). You may not use this file except in - * compliance with the License. A copy of the License is available at - * http://adele.helma.org/download/helma/license.txt - * - * Copyright 1998-2003 Helma Software. All Rights Reserved. - * - * $RCSfile$ - * $Author$ - * $Revision$ - * $Date$ - */ -package helma.scripting.rhino; - -import helma.objectmodel.INode; -import helma.objectmodel.db.Key; -import helma.objectmodel.db.NodeHandle; -import helma.objectmodel.db.OrderedSubnodeList; -import helma.objectmodel.db.WrappedNodeManager; - -import java.lang.reflect.Method; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - -import org.mozilla.javascript.Context; -import org.mozilla.javascript.EvaluatorException; -import org.mozilla.javascript.FunctionObject; -import org.mozilla.javascript.Scriptable; -import org.mozilla.javascript.ScriptableObject; -import org.mozilla.javascript.Undefined; -import org.mozilla.javascript.Wrapper; -import org.mozilla.javascript.ScriptRuntime; - - -public class ListViewWrapper extends ScriptableObject implements Wrapper, Scriptable { - final List list; - final RhinoCore core; - final WrappedNodeManager wnm; - final HopObject hObj; - INode node; - - static ListViewWrapper listViewProto; - - /** - * Private constructor used to create the object prototype. - */ - private ListViewWrapper() { - list = null; - core = null; - wnm = null; - node = null; - hObj = null; - } - - /** - * Create a JS wrapper around a subnode list. - * @param list - * @param core - * @param wnm - * @param hObj - */ - ListViewWrapper (List list, RhinoCore core, WrappedNodeManager wnm, HopObject hObj) { - if (list == null) { - throw new IllegalArgumentException ("ListWrapper unable to wrap null list."); - } - this.core = core; - this.list = list; - this.wnm = wnm; - this.hObj = hObj; - this.node = hObj.node; - if (listViewProto == null) { - listViewProto = new ListViewWrapper(); - listViewProto.init(); - } - setPrototype(listViewProto); - } - - /** - * Init JS functions from methods. - */ - void init() { - int attributes = DONTENUM | PERMANENT; - - Method[] methods = getClass().getDeclaredMethods(); - for (int i=0; i