From 4def8eed1ea09037075674ad2a9de718ef78bad9 Mon Sep 17 00:00:00 2001 From: hns Date: Fri, 13 May 2005 14:45:42 +0000 Subject: [PATCH] Implement NodeManager.getRootNode() and NodeManager.isRootNode() that allow to get the app's root node and check if a node is the root node, respectively --- src/helma/objectmodel/db/Node.java | 13 ++++++------ src/helma/objectmodel/db/NodeManager.java | 16 ++++++++++++++ .../objectmodel/db/WrappedNodeManager.java | 21 +++++++++++++++++++ 3 files changed, 43 insertions(+), 7 deletions(-) diff --git a/src/helma/objectmodel/db/Node.java b/src/helma/objectmodel/db/Node.java index 82e0278e..1e6261d4 100644 --- a/src/helma/objectmodel/db/Node.java +++ b/src/helma/objectmodel/db/Node.java @@ -740,8 +740,7 @@ public final class Node implements INode, Serializable { // the parent of this node is the app's root node... if ((pn == null) && pinfo.isroot) { - pn = nmgr.getNode(nmgr.nmgr.app.getProperty("rootid", "0"), - nmgr.getDbMapping("root")); + pn = nmgr.getRootNode(); } // if we found a parent node, check if we ought to use a virtual or groupby node as parent @@ -943,7 +942,7 @@ public final class Node implements INode, Serializable { } } - if (node != this && !"root".equalsIgnoreCase(node.getPrototype())) { + if (node != this && !nmgr.isRootNode(node)) { // avoid calling getParent() because it would return bogus results // for the not-anymore transient node Node nparent = (node.parentHandle == null) ? null @@ -1146,7 +1145,7 @@ public final class Node implements INode, Serializable { // if (dbmap != null && dbmap.getSubnodeRelation () != null) // retval = nmgr.getNode (this, subid, dbmap.getSubnodeRelation ()); if ((retval != null) && (retval.parentHandle == null) && - !"root".equalsIgnoreCase(retval.getPrototype())) { + !nmgr.isRootNode(retval)) { retval.setParent(this); retval.anonymous = true; } @@ -1176,7 +1175,7 @@ public final class Node implements INode, Serializable { retval = ((NodeHandle) subnodes.get(index)).getNode(nmgr); if ((retval != null) && (retval.parentHandle == null) && - !"root".equalsIgnoreCase(retval.getPrototype())) { + !nmgr.isRootNode(retval)) { retval.setParent(this); retval.anonymous = true; } @@ -1731,7 +1730,7 @@ public final class Node implements INode, Serializable { if (n != null) { if ((n.parentHandle == null) && - !"root".equalsIgnoreCase(n.getPrototype())) { + !nmgr.isRootNode(n)) { n.setParent(this); n.name = propname; n.anonymous = false; @@ -2235,7 +2234,7 @@ public final class Node implements INode, Serializable { // check if the main identity of this node is as a named property // or as an anonymous node in a collection - if (n != this && !"root".equalsIgnoreCase(n.getPrototype())) { + if (n != this && !nmgr.isRootNode(n)) { // avoid calling getParent() because it would return bogus results // for the not-anymore transient node Node nparent = (n.parentHandle == null) ? null diff --git a/src/helma/objectmodel/db/NodeManager.java b/src/helma/objectmodel/db/NodeManager.java index 9e577dfe..d47dc24e 100644 --- a/src/helma/objectmodel/db/NodeManager.java +++ b/src/helma/objectmodel/db/NodeManager.java @@ -97,6 +97,22 @@ public final class NodeManager { db.init(dbHome, app); } + /** + * Gets the application's root node. + */ + public Node getRootNode() throws Exception { + DbMapping dbmap = getDbMapping(app.getRootPrototype()); + DbKey key = new DbKey(dbmap, app.getRootId()); + return getNode(key); + } + /** + * Checks if the given node is the application's root node. + */ + public boolean isRootNode(Node node) { + return app.getRootId().equals(node.getID()) && + app.getRootPrototype().equals(node.getPrototype()); + } + /** * app.properties file has been updated. Reread some settings. */ diff --git a/src/helma/objectmodel/db/WrappedNodeManager.java b/src/helma/objectmodel/db/WrappedNodeManager.java index a710fb85..513432b6 100644 --- a/src/helma/objectmodel/db/WrappedNodeManager.java +++ b/src/helma/objectmodel/db/WrappedNodeManager.java @@ -255,6 +255,27 @@ public final class WrappedNodeManager { } } + /** + * Gets the application's root node. + */ + public Node getRootNode() { + try { + return nmgr.getRootNode(); + } catch (Exception x) { + if (nmgr.app.debug()) { + x.printStackTrace(); + } + throw new RuntimeException(x.toString()); + } + } + + /** + * Checks if the given node is the application's root node. + */ + public boolean isRootNode(Node node) { + return nmgr.isRootNode(node); + } + /** * Get an array of all objects in the object cache */