Rename __fullname__ internal HopObject property to __path__, fill in/trim some comments.

This commit is contained in:
hns 2009-09-18 20:40:36 +00:00
parent 85586a0d0f
commit ec3f04cab3
3 changed files with 91 additions and 265 deletions

View file

@ -27,364 +27,234 @@ import java.util.*;
*/ */
public interface INode extends INodeState, IPathElement { public interface INode extends INodeState, IPathElement {
/** /**
* id-related methods * Get the node's ID.
*/ */
public String getID(); public String getID();
/** /**
* * Get the node's name.
*
* @return ...
*/ */
public String getName(); public String getName();
/** /**
* * Set the node's {@link DbMapping}.
*
* @param dbmap ...
*/ */
public void setDbMapping(DbMapping dbmap); public void setDbMapping(DbMapping dbmap);
/** /**
* * Get the node's {@link DbMapping}.
*
* @return ...
*/ */
public DbMapping getDbMapping(); public DbMapping getDbMapping();
/** /**
* * Get the node's state flag.
* * @return one of the constants defined in the {@link INodeState} interface.
* @return ...
*/ */
public int getState(); public int getState();
/** /**
* * Set the node's state flag.
* * @param s one of the constants defined in the {@link INodeState} interface.
* @param s ...
*/ */
public void setState(int s); public void setState(int s);
/** /**
* * Set the node's name.
*
* @param name ...
*/ */
public void setName(String name); public void setName(String name);
/** /**
* * Get the node's last modification timestamp.
*
* @return ...
*/ */
public long lastModified(); public long lastModified();
/** /**
* * Get the node's creation timestamp.
*
* @return ...
*/ */
public long created(); public long created();
/** /**
* * Returns true if this node is an unnamed node.
*
* @return ...
*/ */
public boolean isAnonymous(); // is this a named node, or an anonymous node in a collection? public boolean isAnonymous();
/** /**
* * Return the node's prototype name.
*
* @return ...
*/ */
public String getPrototype(); public String getPrototype();
/** /**
* * Set the node's prototype name.
*
* @param prototype ...
*/ */
public void setPrototype(String prototype); public void setPrototype(String prototype);
/** /**
* * Get the cache node associated with this node.
*
* @return ...
*/ */
public INode getCacheNode(); public INode getCacheNode();
/** /**
* * Clear the cache node associated with this node.
*/ */
public void clearCacheNode(); public void clearCacheNode();
/** /**
* * Get the node's path.
*
* @return ...
*/ */
public String getFullName(); public String getPath();
/** /**
* * Get the node's parent node.
*
* @param root ...
*
* @return ...
*/
public String getFullName(INode root);
/**
* node-related methods
*/ */
public INode getParent(); public INode getParent();
/** /**
* * Set an explicit select clause for the node's subnodes
*
* @param rel ...
*/ */
public void setSubnodeRelation(String rel); public void setSubnodeRelation(String clause);
/** /**
* * Get the node's explicit subnode select clause if one was set, or null
*
* @return ...
*/ */
public String getSubnodeRelation(); public String getSubnodeRelation();
/** /**
* * Get the number the node's direct child nodes.
*
* @return ...
*/ */
public int numberOfNodes(); public int numberOfNodes();
/** /**
* * Add a child node to this node.
*
* @param node ...
*
* @return ...
*/ */
public INode addNode(INode node); public INode addNode(INode node);
/** /**
* * Add a child node to this node at the given position
*
* @param node ...
* @param where ...
*
* @return ...
*/ */
public INode addNode(INode node, int where); public INode addNode(INode node, int where);
/** /**
* * Create a new named property with a node value
*
* @param name ...
*
* @return ...
*/ */
public INode createNode(String name); public INode createNode(String name);
/** /**
* * Create a new unnamed child node at the given position.
*
* @param name ...
* @param where ...
*
* @return ...
*/ */
public INode createNode(String name, int where); public INode createNode(String name, int where);
/** /**
* * Get an enumeration of this node's unnamed child nodes
*
* @return ...
*/ */
public Enumeration getSubnodes(); public Enumeration getSubnodes();
/** /**
* * Get a named child node with the given name or id.
*
* @param name ...
*
* @return ...
*/ */
public INode getSubnode(String name); public INode getSubnode(String name);
/** /**
* * GEt an unnamed child node at the given position
*
* @param index ...
*
* @return ...
*/ */
public INode getSubnodeAt(int index); public INode getSubnodeAt(int index);
/** /**
* * Returns the position of the child or -1.
*
* @param node ...
*
* @return ...
*/ */
public int contains(INode node); public int contains(INode node);
/** /**
* * Remove this node from the database.
*
* @return ...
*/ */
public boolean remove(); public boolean remove();
/** /**
* * Remove the given node from this node's child nodes.
*
* @param node ...
*/ */
public void removeNode(INode node); public void removeNode(INode node);
/** /**
* property-related methods * Get an enumeration over the node's properties.
*/ */
public Enumeration properties(); public Enumeration properties();
/** /**
* * Get a property with the given name.
*
* @param name ...
*
* @return ...
*/ */
public IProperty get(String name); public IProperty get(String name);
/** /**
* * Get a string property with the given name.
*
* @param name ...
*
* @return ...
*/ */
public String getString(String name); public String getString(String name);
/** /**
* * Get a boolean property with the given name.
*
* @param name ...
*
* @return ...
*/ */
public boolean getBoolean(String name); public boolean getBoolean(String name);
/** /**
* * Get a date property with the given name.
*
* @param name ...
*
* @return ...
*/ */
public Date getDate(String name); public Date getDate(String name);
/** /**
* * Get an integer property with the given name.
*
* @param name ...
*
* @return ...
*/ */
public long getInteger(String name); public long getInteger(String name);
/** /**
* * Get a float property with the given name.
*
* @param name ...
*
* @return ...
*/ */
public double getFloat(String name); public double getFloat(String name);
/** /**
* * Get a node property with the given name.
*
* @param name ...
*
* @return ...
*/ */
public INode getNode(String name); public INode getNode(String name);
/** /**
* * Get a Java object property with the given name.
*
* @param name ...
*
* @return ...
*/ */
public Object getJavaObject(String name); public Object getJavaObject(String name);
/** /**
* * Set the property with the given name to the given string value.
*
* @param name ...
* @param value ...
*/ */
public void setString(String name, String value); public void setString(String name, String value);
/** /**
* * Set the property with the given name to the given boolean value.
*
* @param name ...
* @param value ...
*/ */
public void setBoolean(String name, boolean value); public void setBoolean(String name, boolean value);
/** /**
* * Set the property with the given name to the given date value.
*
* @param name ...
* @param value ...
*/ */
public void setDate(String name, Date value); public void setDate(String name, Date value);
/** /**
* * Set the property with the given name to the given integer value.
*
* @param name ...
* @param value ...
*/ */
public void setInteger(String name, long value); public void setInteger(String name, long value);
/** /**
* * Set the property with the given name to the given float value.
*
* @param name ...
* @param value ...
*/ */
public void setFloat(String name, double value); public void setFloat(String name, double value);
/** /**
* * Set the property with the given name to the given node value.
*
* @param name ...
* @param value ...
*/ */
public void setNode(String name, INode value); public void setNode(String name, INode value);
/** /**
* * Set the property with the given name to the given Java object value.
*
* @param name ...
* @param value ...
*/ */
public void setJavaObject(String name, Object value); public void setJavaObject(String name, Object value);
/** /**
* * Unset the property with the given name..
*
* @param name ...
*/ */
public void unset(String name); public void unset(String name);
} }

View file

@ -108,7 +108,7 @@ public class TransientNode implements INode, Serializable {
// state always is TRANSIENT on this kind of node // state always is TRANSIENT on this kind of node
} }
public String getFullName() { public String getPath() {
return getFullName(null); return getFullName(null);
} }
@ -159,7 +159,7 @@ public class TransientNode implements INode, Serializable {
} }
public void setSubnodeRelation(String rel) { public void setSubnodeRelation(String rel) {
throw new RuntimeException("Can't set subnode relation for non-persistent Node."); throw new UnsupportedOperationException("Can't set subnode relation for non-persistent Node.");
} }
public String getSubnodeRelation() { public String getSubnodeRelation() {

View file

@ -439,28 +439,15 @@ public final class Node implements INode {
} }
/** /**
* * Get the node's path
*
* @return ...
*/ */
public String getFullName() { public String getPath() {
return getFullName(null);
}
/**
*
*
* @param root ...
*
* @return ...
*/
public String getFullName(INode root) {
String divider = null; String divider = null;
StringBuffer b = new StringBuffer(); StringBuffer b = new StringBuffer();
INode p = this; INode p = this;
int loopWatch = 0; int loopWatch = 0;
while ((p != null) && (p.getParent() != null) && (p != root)) { while (p != null && p.getParent() != null) {
if (divider != null) { if (divider != null) {
b.insert(0, divider); b.insert(0, divider);
} else { } else {
@ -478,14 +465,11 @@ public final class Node implements INode {
break; break;
} }
} }
return b.toString(); return b.toString();
} }
/** /**
* * Return the node's prototype name.
*
* @return ...
*/ */
public String getPrototype() { public String getPrototype() {
// if prototype is null, it's a vanilla HopObject. // if prototype is null, it's a vanilla HopObject.
@ -497,9 +481,7 @@ public final class Node implements INode {
} }
/** /**
* * Set the node's prototype name.
*
* @param proto ...
*/ */
public void setPrototype(String proto) { public void setPrototype(String proto) {
this.prototype = proto; this.prototype = proto;
@ -509,27 +491,21 @@ public final class Node implements INode {
} }
/** /**
* * Set the node's {@link DbMapping}.
*
* @param dbmap ...
*/ */
public void setDbMapping(DbMapping dbmap) { public void setDbMapping(DbMapping dbmap) {
this.dbmap = dbmap; this.dbmap = dbmap;
} }
/** /**
* * Get the node's {@link DbMapping}.
*
* @return ...
*/ */
public DbMapping getDbMapping() { public DbMapping getDbMapping() {
return dbmap; return dbmap;
} }
/** /**
* * Get the node's key.
*
* @return ...
*/ */
public Key getKey() { public Key getKey() {
if (primaryKey == null && state == TRANSIENT) { if (primaryKey == null && state == TRANSIENT) {
@ -548,22 +524,17 @@ public final class Node implements INode {
} }
/** /**
* * Get the node's handle.
*
* @return ...
*/ */
public NodeHandle getHandle() { public NodeHandle getHandle() {
if (handle == null) { if (handle == null) {
handle = new NodeHandle(this); handle = new NodeHandle(this);
} }
return handle; return handle;
} }
/** /**
* * Set an explicit select clause for the node's subnodes
*
* @param rel ...
*/ */
public synchronized void setSubnodeRelation(String rel) { public synchronized void setSubnodeRelation(String rel) {
if ((rel == null && this.subnodeRelation == null) || if ((rel == null && this.subnodeRelation == null) ||
@ -582,18 +553,14 @@ public final class Node implements INode {
} }
/** /**
* * Get the node's explicit subnode select clause if one was set, or null
*
* @return ...
*/ */
public synchronized String getSubnodeRelation() { public synchronized String getSubnodeRelation() {
return subnodeRelation; return subnodeRelation;
} }
/** /**
* * Set the node's name.
*
* @param name ...
*/ */
public void setName(String name) { public void setName(String name) {
if ((name == null) || (name.length() == 0)) { if ((name == null) || (name.length() == 0)) {
@ -1025,11 +992,7 @@ public final class Node implements INode {
} }
/** /**
* * Get a named child node with the given id.
*
* @param subid ...
*
* @return ...
*/ */
public INode getSubnode(String subid) { public INode getSubnode(String subid) {
if (subid == null || subid.length() == 0) { if (subid == null || subid.length() == 0) {
@ -1037,46 +1000,39 @@ public final class Node implements INode {
} }
Node retval = null; Node retval = null;
if (subid != null) {
loadNodes(); loadNodes();
if (subnodes == null || subnodes.size() == 0) {
if ((subnodes == null) || (subnodes.size() == 0)) {
return null; return null;
} }
NodeHandle nhandle = null; NodeHandle nhandle = null;
int l = subnodes.size(); int l = subnodes.size();
for (int i = 0; i < l; i++) for (int i = 0; i < l; i++) {
try { try {
NodeHandle shandle = subnodes.get(i); NodeHandle shandle = subnodes.get(i);
if (subid.equals(shandle.getID())) { if (subid.equals(shandle.getID())) {
// System.err.println ("FOUND SUBNODE: "+shandle);
nhandle = shandle; nhandle = shandle;
break; break;
} }
} catch (Exception x) { } catch (Exception x) {
break; break;
} }
}
if (nhandle != null) { if (nhandle != null) {
retval = nhandle.getNode(nmgr); retval = nhandle.getNode(nmgr);
} }
// This would be an alternative way to do it, without loading the subnodes, // This would be a better way to do it, without loading the subnodes,
// but it currently isn't supported by NodeManager. // but it currently isn't supported by NodeManager.
// 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 && !nmgr.isRootNode(retval)) {
!nmgr.isRootNode(retval)) {
retval.setParent(this); retval.setParent(this);
retval.anonymous = true; retval.anonymous = true;
} }
}
return retval; return retval;
} }