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
This commit is contained in:
parent
022bc2a2d8
commit
4def8eed1e
3 changed files with 43 additions and 7 deletions
|
@ -740,8 +740,7 @@ public final class Node implements INode, Serializable {
|
||||||
|
|
||||||
// the parent of this node is the app's root node...
|
// the parent of this node is the app's root node...
|
||||||
if ((pn == null) && pinfo.isroot) {
|
if ((pn == null) && pinfo.isroot) {
|
||||||
pn = nmgr.getNode(nmgr.nmgr.app.getProperty("rootid", "0"),
|
pn = nmgr.getRootNode();
|
||||||
nmgr.getDbMapping("root"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// if we found a parent node, check if we ought to use a virtual or groupby node as parent
|
// 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
|
// avoid calling getParent() because it would return bogus results
|
||||||
// for the not-anymore transient node
|
// for the not-anymore transient node
|
||||||
Node nparent = (node.parentHandle == null) ? null
|
Node nparent = (node.parentHandle == null) ? null
|
||||||
|
@ -1146,7 +1145,7 @@ public final class Node implements INode, Serializable {
|
||||||
// if (dbmap != null && dbmap.getSubnodeRelation () != null)
|
// if (dbmap != null && dbmap.getSubnodeRelation () != null)
|
||||||
// retval = nmgr.getNode (this, subid, dbmap.getSubnodeRelation ());
|
// retval = nmgr.getNode (this, subid, dbmap.getSubnodeRelation ());
|
||||||
if ((retval != null) && (retval.parentHandle == null) &&
|
if ((retval != null) && (retval.parentHandle == null) &&
|
||||||
!"root".equalsIgnoreCase(retval.getPrototype())) {
|
!nmgr.isRootNode(retval)) {
|
||||||
retval.setParent(this);
|
retval.setParent(this);
|
||||||
retval.anonymous = true;
|
retval.anonymous = true;
|
||||||
}
|
}
|
||||||
|
@ -1176,7 +1175,7 @@ public final class Node implements INode, Serializable {
|
||||||
retval = ((NodeHandle) subnodes.get(index)).getNode(nmgr);
|
retval = ((NodeHandle) subnodes.get(index)).getNode(nmgr);
|
||||||
|
|
||||||
if ((retval != null) && (retval.parentHandle == null) &&
|
if ((retval != null) && (retval.parentHandle == null) &&
|
||||||
!"root".equalsIgnoreCase(retval.getPrototype())) {
|
!nmgr.isRootNode(retval)) {
|
||||||
retval.setParent(this);
|
retval.setParent(this);
|
||||||
retval.anonymous = true;
|
retval.anonymous = true;
|
||||||
}
|
}
|
||||||
|
@ -1731,7 +1730,7 @@ public final class Node implements INode, Serializable {
|
||||||
|
|
||||||
if (n != null) {
|
if (n != null) {
|
||||||
if ((n.parentHandle == null) &&
|
if ((n.parentHandle == null) &&
|
||||||
!"root".equalsIgnoreCase(n.getPrototype())) {
|
!nmgr.isRootNode(n)) {
|
||||||
n.setParent(this);
|
n.setParent(this);
|
||||||
n.name = propname;
|
n.name = propname;
|
||||||
n.anonymous = false;
|
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
|
// check if the main identity of this node is as a named property
|
||||||
// or as an anonymous node in a collection
|
// 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
|
// avoid calling getParent() because it would return bogus results
|
||||||
// for the not-anymore transient node
|
// for the not-anymore transient node
|
||||||
Node nparent = (n.parentHandle == null) ? null
|
Node nparent = (n.parentHandle == null) ? null
|
||||||
|
|
|
@ -97,6 +97,22 @@ public final class NodeManager {
|
||||||
db.init(dbHome, app);
|
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.
|
* app.properties file has been updated. Reread some settings.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -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
|
* Get an array of all objects in the object cache
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Add table
Reference in a new issue