Package helma.objectmodel.db

# Class Node

java.lang.Object
helma.objectmodel.db.Node

All Implemented Interfaces:
  `IPathElement`, `INode`, `INodeState`

public final class Node extends Object implements INode
An implementation of INode that can be stored in the internal database or an external relational database.

## Field Summary

Fields
Modifier and Type
Field
Description
`protected boolean`
`anonymous`
`protected long`
`created`
`protected long`
`lastmodified`
`protected NodeHandle`
`parentHandle`
`protected short`
`version`

### Fields inherited from interface helma.objectmodel.INodeState

`CLEAN, DELETED, INVALID, MODIFIED, NEW, TRANSIENT, VIRTUAL`

## Constructor Summary

Constructors
Modifier
Constructor
Description
`protected`
`Node(long timestamp)`
Creates an empty, uninitialized Node with the given create and modify time.
``
`Node(Node home, String propname, WrappedNodeManager nmgr, String prototype)`
Constructor used for virtual nodes.
`protected`
`Node(WrappedNodeManager nmgr)`
Creates an empty, uninitialized Node.
``
`Node(String name, String prototype, WrappedNodeManager nmgr)`
Creates a new Node with the given name.
``
`Node(String name, String id, String prototype, WrappedNodeManager nmgr)`
Creates a new Node with the given name.
``
`Node(String name, String id, String prototype, WrappedNodeManager nmgr, long created, long lastmodified)`
Constructor used to create a Node with a given name from a embedded database.

## Method Summary

Modifier and Type
Method
Description
`INode`
`addNode(INode elem)`
INode-related
`INode`
`addNode(INode elem, int where)`
Add a node to this Node's subnodes, making the added node persistent if it hasn't been before and this Node is already persistent.
`void`
`clearCacheNode()`
Reset the cache node for this node.
`int`
`contains(INode n)`
Check if the given node is contained in this node's child list.
`long`
`created()`
Get the node's creation timestamp.
`INode`
`createNode()`
`INode`
`createNode(int where)`
`INode`
`createNode(String nm)`
Create a new named property with a node value
`INode`
`createNode(String nm, int where)`
Create a new unnamed child node at the given position.
`SubnodeList`
`createSubnodeList()`
Create an empty subnode list.
`protected void`
`deepRemoveNode()`
Delete the node from the db.
`void`
`dump()`
`IProperty`
`get(String propname)`
Get a property with the given name.
`boolean`
`getBoolean(String propname)`
Get a boolean property with the given name.
`Node`
`getCachedParent()`
Get parent, using cached info if it exists.
`INode`
`getCacheNode()`
Get the cache node for this node.
`IPathElement`
`getChildElement(String name)`
This implements the getChildElement() method of the IPathElement interface
`Date`
`getDate(String propname)`
Get a date property with the given name.
`DbMapping`
`getDbMapping()`
Get the node's `DbMapping`.
`String`
`getElementName()`
Get something to identify this node within a URL.
`double`
`getFloat(String propname)`
Get a float property with the given name.
`protected Node`
`getGroupbySubnode(Node node, boolean create)`
Get or create a group name for a given content node.
`protected Node`
`getGroupbySubnode(String groupname, boolean create)`
Get or create a group name for a given group name.
`NodeHandle`
`getHandle()`
Get the node's handle.
`String`
`getID()`
Get the ID of this Node.
`long`
`getInteger(String propname)`
Get an integer property with the given name.
`Object`
`getJavaObject(String propname)`
Get a Java object property with the given name.
`Key`
`getKey()`
Get the node's key.
`String`
`getName()`
Return this node' name, which may or may not have some meaning
`INode`
`getNode(String propname)`
Get a node property with the given name.
`Node`
`getNonVirtualParent()`
This method walks down node path to the first non-virtual node and return it.
`INode`
`getParent()`
Get parent, retrieving it if necessary.
`IPathElement`
`getParentElement()`
This implements the getParentElement() method of the IPathElement interface
`String`
`getParentInfo()`
`String`
`getPath()`
Get the node's path
`protected Property`
`getProperty(String propname)`
`Hashtable`
`getPropMap()`
`String`
`getPrototype()`
Return the node's prototype name.
`int`
`getState()`
Gets this node's stateas defined in the INode interface
`String`
`getString(String propname)`
Get a string property with the given name.
`INode`
`getSubnode(String subid)`
Get a named child node with the given id.
`INode`
`getSubnodeAt(int index)`
Get a node at a given position.
`SubnodeList`
`getSubnodeList()`
Return this Node's subnode list
`String`
`getSubnodeRelation()`
Get the node's explicit subnode select clause if one was set, or null
`Enumeration`
`getSubnodes()`
Enumerate through the subnodes of this node.
`int`
`hashCode()`
We overwrite hashCode to make it dependant from the prototype.
`void`
`init(DbMapping dbm, String id, String name, String prototype, Hashtable propMap)`
Initializer used for nodes being instanced from an embedded or relational database.
`void`
`invalidate()`
Mark node as invalid so it is re-fetched from the database
`void`
`invalidateNode(String key)`
Check for a child mapping and evict the object specified by key from the cache
`boolean`
`isAnonymous()`
Returns true if this node is accessed by id from its aprent, false if it is accessed by name
`boolean`
`isNullNode()`
Instances of this class may be used to mark an entry in the object cache as null.
`boolean`
`isParentOf(Node n)`
Check if the given node is contained in this node's child list.
`boolean`
`isRelational()`
Tell whether this node is stored inside a relational db.
`long`
`lastModified()`
Get the node's last modification timestamp.
`void`
`loadNodes()`
Make sure the subnode index is loaded for subnodes stored in a relational data source.
`void`
`markSubnodesChanged()`
Called by the transactor on registered parent nodes to mark the child index as changed
`int`
`numberOfNodes()`
Count the subnodes of this node.
`void`
`persist()`
Public method to make a node persistent.
`void`
`prefetchChildren(int startIndex, int length)`
`Enumeration`
`properties()`
Get all properties of this node.
`protected void`
`releaseNode(Node node)`
"Locally" remove a subnode from the subnodes table.
`boolean`
`remove()`
Remove this node from the database.
`void`
`removeNode(INode node)`
Remove the given node from this node's child nodes.
`protected void`
`set(String propname, Object value, int type)`
Directly set a property on this node
`void`
`setBoolean(String propname, boolean value)`
Set the property with the given name to the given boolean value.
`void`
`setDate(String propname, Date value)`
Set the property with the given name to the given date value.
`void`
`setDbMapping(DbMapping dbmap)`
Set the node's `DbMapping`.
`void`
`setFloat(String propname, double value)`
Set the property with the given name to the given float value.
`void`
`setInteger(String propname, long value)`
Set the property with the given name to the given integer value.
`void`
`setJavaObject(String propname, Object value)`
Set the property with the given name to the given Java object value.
`void`
`setName(String name)`
Set the node's name.
`void`
`setNode(String propname, INode value)`
Set the property with the given name to the given node value.
`void`
`setParent(Node parent)`
Set this node's parent node.
`void`
`setParentHandle(NodeHandle parent)`
Set this node's parent node to the node referred to by the NodeHandle.
`void`
`setPropMap(Hashtable propMap)`
used by Xml deserialization
`void`
`setPrototype(String proto)`
Set the node's prototype name.
`void`
`setState(int s)`
Sets this node's state as defined in the INode interface
`void`
`setString(String propname, String value)`
Set the property with the given name to the given string value.
`void`
`setSubnodeRelation(String rel)`
Set an explicit select clause for the node's subnodes
`String`
`toString()`
Return a string representation for this node.
`void`
`unset(String propname)`
Remove a property.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, notify, notifyAll, wait, wait, wait`

## Field Details

### parentHandle

protected NodeHandle parentHandle

### created

protected long created

### lastmodified

protected long lastmodified

### anonymous

protected boolean anonymous

### version

protected short version

## Constructor Details

### Node

protected Node(long timestamp)
Creates an empty, uninitialized Node with the given create and modify time. This is used for null-node references in the node cache.

Parameters:
  `timestamp` -

### Node

protected Node(WrappedNodeManager nmgr)
Creates an empty, uninitialized Node. The init() method must be called on the Node before it can do anything useful.

### Node

public Node(String name, String id, String prototype, WrappedNodeManager nmgr)
Creates a new Node with the given name. Used by NodeManager for creating "root nodes" outside of a Transaction context, which is why we can immediately mark it as CLEAN. Also used by embedded database to re-create an existing Node.

### Node

public Node(String name, String id, String prototype, WrappedNodeManager nmgr, long created, long lastmodified)
Constructor used to create a Node with a given name from a embedded database.

### Node

public Node(Node home, String propname, WrappedNodeManager nmgr, String prototype)
Constructor used for virtual nodes.

### Node

public Node(String name, String prototype, WrappedNodeManager nmgr)
Creates a new Node with the given name. This is used for ordinary transient nodes.

## Method Details

### init

public void init(DbMapping dbm, String id, String name, String prototype, Hashtable propMap)
Initializer used for nodes being instanced from an embedded or relational database.

### setPropMap

public void setPropMap(Hashtable propMap)
used by Xml deserialization

### markSubnodesChanged

public void markSubnodesChanged()
Called by the transactor on registered parent nodes to mark the child index as changed

### getState

public int getState()
Gets this node's stateas defined in the INode interface

Specified by:
  `getState` in interface `INode`
Returns:
  this node's state

### setState

public void setState(int s)
Sets this node's state as defined in the INode interface

Specified by:
  `setState` in interface `INode`
Parameters:
  `s` - this node's new state

### invalidate

public void invalidate()
Mark node as invalid so it is re-fetched from the database

### invalidateNode

public void invalidateNode(String key)
Check for a child mapping and evict the object specified by key from the cache

### getID

public String getID()
Get the ID of this Node. This is the primary database key and used as part of the key for the internal node cache.

Specified by:
  `getID` in interface `INode`

### isAnonymous

public boolean isAnonymous()
Returns true if this node is accessed by id from its aprent, false if it is accessed by name

Specified by:
  `isAnonymous` in interface `INode`

### getName

public String getName()
Return this node' name, which may or may not have some meaning

Specified by:
  `getName` in interface `INode`

### getElementName

public String getElementName()
Get something to identify this node within a URL. This is the ID for anonymous nodes and a property value for named properties.

Specified by:
  `getElementName` in interface `IPathElement`

### getPath

public String getPath()
Get the node's path

Specified by:
  `getPath` in interface `INode`

### getPrototype

public String getPrototype()
Return the node's prototype name.

Specified by:
  `getPrototype` in interface `INode`
Specified by:
  `getPrototype` in interface `IPathElement`

### setPrototype

public void setPrototype(String proto)
Set the node's prototype name.

Specified by:
  `setPrototype` in interface `INode`

### setDbMapping

public void setDbMapping(DbMapping dbmap)
Set the node's `DbMapping`.

Specified by:
  `setDbMapping` in interface `INode`

### getDbMapping

public DbMapping getDbMapping()
Get the node's `DbMapping`.

Specified by:
  `getDbMapping` in interface `INode`

### getKey

public Key getKey()
Get the node's key.

### getHandle

public NodeHandle getHandle()
Get the node's handle.

### setSubnodeRelation

public void setSubnodeRelation(String rel)
Set an explicit select clause for the node's subnodes

Specified by:
  `setSubnodeRelation` in interface `INode`

### getSubnodeRelation

public String getSubnodeRelation()
Get the node's explicit subnode select clause if one was set, or null

Specified by:
  `getSubnodeRelation` in interface `INode`

### setName

public void setName(String name)
Set the node's name.

Specified by:
  `setName` in interface `INode`

### setParent

public void setParent(Node parent)
Set this node's parent node.

### setParentHandle

public void setParentHandle(NodeHandle parent)
Set this node's parent node to the node referred to by the NodeHandle.

### getParent

public INode getParent()
Get parent, retrieving it if necessary.

Specified by:
  `getParent` in interface `INode`

### getCachedParent

public Node getCachedParent()
Get parent, using cached info if it exists.

### addNode

public INode addNode(INode elem)
INode-related

Specified by:
  `addNode` in interface `INode`

### addNode

public INode addNode(INode elem, int where)
Add a node to this Node's subnodes, making the added node persistent if it hasn't been before and this Node is already persistent.

Specified by:
  `addNode` in interface `INode`
Parameters:
  `elem` - the node to add to this Nodes subnode-list
  `where` - the index-position where this node has to be added
Returns:
  the added node itselve

### createNode

public INode createNode()

Returns:
  ...

### createNode

public INode createNode(int where)

Parameters:
  `where` - ...
Returns:
  ...

### createNode

public INode createNode(String nm)
Description copied from interface: `INode`
Create a new named property with a node value

Specified by:
  `createNode` in interface `INode`
Parameters:
  `nm` - ...
Returns:
  ...

### createNode

public INode createNode(String nm, int where)
Description copied from interface: `INode`
Create a new unnamed child node at the given position.

Specified by:
  `createNode` in interface `INode`
Parameters:
  `nm` - ...
  `where` - ...
Returns:
  ...

### getChildElement

public IPathElement getChildElement(String name)
This implements the getChildElement() method of the IPathElement interface

Specified by:
  `getChildElement` in interface `IPathElement`

### getParentElement

public IPathElement getParentElement()
This implements the getParentElement() method of the IPathElement interface

Specified by:
  `getParentElement` in interface `IPathElement`

### getSubnode

public INode getSubnode(String subid)
Get a named child node with the given id.

Specified by:
  `getSubnode` in interface `INode`

### getSubnodeAt

public INode getSubnodeAt(int index)
Get a node at a given position. This causes the subnode list to be loaded in case it isn't up to date.

Specified by:
  `getSubnodeAt` in interface `INode`
Parameters:
  `index` - the subnode index
Returns:
  the node at the given index

### getGroupbySubnode

protected Node getGroupbySubnode(Node node, boolean create)
Get or create a group name for a given content node.

Parameters:
  `node` - the content node
  `create` - whether the node should be created if it doesn't exist
Returns:
  the group node, or null

### getGroupbySubnode

protected Node getGroupbySubnode(String groupname, boolean create)
Get or create a group name for a given group name.

Parameters:
  `groupname` - the group name
  `create` - whether the node should be created if it doesn't exist
Returns:
  the group node, or null

### remove

public boolean remove()
Description copied from interface: `INode`
Remove this node from the database.

Specified by:
  `remove` in interface `INode`
Returns:
  ...

### removeNode

public void removeNode(INode node)
Description copied from interface: `INode`
Remove the given node from this node's child nodes.

Specified by:
  `removeNode` in interface `INode`
Parameters:
  `node` - ...

### releaseNode

protected void releaseNode(Node node)
"Locally" remove a subnode from the subnodes table. The logical stuff necessary for keeping data consistent is done in `removeNode(INode)`.

### deepRemoveNode

protected void deepRemoveNode()
Delete the node from the db. This mainly tries to notify all nodes referring to this that it's going away. For nodes from the embedded db it also does a cascading delete, since it can tell which nodes are actual children and which are just linked in.

### contains

public int contains(INode n)
Check if the given node is contained in this node's child list. If it is contained return its index in the list, otherwise return -1.

Specified by:
  `contains` in interface `INode`
Parameters:
  `n` - a node
Returns:
  the node's index position in the child list, or -1

### isParentOf

public boolean isParentOf(Node n)
Check if the given node is contained in this node's child list. This is similar to `contains(INode)` but does not load the child index for relational nodes.

Parameters:
  `n` - a node
Returns:
  true if the given node is contained in this node's child list

### numberOfNodes

public int numberOfNodes()
Count the subnodes of this node. If they're stored in a relational data source, we may actually load their IDs in order to do this.

Specified by:
  `numberOfNodes` in interface `INode`

### loadNodes

public void loadNodes()
Make sure the subnode index is loaded for subnodes stored in a relational data source. Depending on the subnode.loadmode specified in the type.properties, we'll load just the ID index or the actual nodes.

### createSubnodeList

public SubnodeList createSubnodeList()
Create an empty subnode list.

Returns:
  List an empty List of the type used by this Node

### prefetchChildren

public void prefetchChildren(int startIndex, int length)

Parameters:
  `startIndex` - ...
  `length` - ...
Throws:
  `Exception` - ...

### getSubnodes

public Enumeration getSubnodes()
Enumerate through the subnodes of this node.

Specified by:
  `getSubnodes` in interface `INode`
Returns:
  an enumeration of this node's subnodes

### getSubnodeList

public SubnodeList getSubnodeList()
Return this Node's subnode list

Returns:
  the subnode list

### properties

public Enumeration properties()
Get all properties of this node.

Specified by:
  `properties` in interface `INode`

### getPropMap

public Hashtable getPropMap()

Returns:
  ...

### get

public IProperty get(String propname)
Description copied from interface: `INode`
Get a property with the given name.

Specified by:
  `get` in interface `INode`
Parameters:
  `propname` - ...
Returns:
  ...

### getParentInfo

public String getParentInfo()

Returns:
  ...

### getProperty

protected Property getProperty(String propname)

Parameters:
  `propname` - ...
Returns:
  ...

### getString

public String getString(String propname)
Description copied from interface: `INode`
Get a string property with the given name.

Specified by:
  `getString` in interface `INode`
Parameters:
  `propname` - ...
Returns:
  ...

### getInteger

public long getInteger(String propname)
Description copied from interface: `INode`
Get an integer property with the given name.

Specified by:
  `getInteger` in interface `INode`
Parameters:
  `propname` - ...
Returns:
  ...

### getFloat

public double getFloat(String propname)
Description copied from interface: `INode`
Get a float property with the given name.

Specified by:
  `getFloat` in interface `INode`
Parameters:
  `propname` - ...
Returns:
  ...

### getDate

public Date getDate(String propname)
Description copied from interface: `INode`
Get a date property with the given name.

Specified by:
  `getDate` in interface `INode`
Parameters:
  `propname` - ...
Returns:
  ...

### getBoolean

public boolean getBoolean(String propname)
Description copied from interface: `INode`
Get a boolean property with the given name.

Specified by:
  `getBoolean` in interface `INode`
Parameters:
  `propname` - ...
Returns:
  ...

### getNode

public INode getNode(String propname)
Description copied from interface: `INode`
Get a node property with the given name.

Specified by:
  `getNode` in interface `INode`
Parameters:
  `propname` - ...
Returns:
  ...

### getJavaObject

public Object getJavaObject(String propname)
Description copied from interface: `INode`
Get a Java object property with the given name.

Specified by:
  `getJavaObject` in interface `INode`
Parameters:
  `propname` - ...
Returns:
  ...

### set

protected void set(String propname, Object value, int type)
Directly set a property on this node

Parameters:
  `propname` - ...
  `value` - ...

### setString

public void setString(String propname, String value)
Description copied from interface: `INode`
Set the property with the given name to the given string value.

Specified by:
  `setString` in interface `INode`
Parameters:
  `propname` - ...
  `value` - ...

### setInteger

public void setInteger(String propname, long value)
Description copied from interface: `INode`
Set the property with the given name to the given integer value.

Specified by:
  `setInteger` in interface `INode`
Parameters:
  `propname` - ...
  `value` - ...

### setFloat

public void setFloat(String propname, double value)
Description copied from interface: `INode`
Set the property with the given name to the given float value.

Specified by:
  `setFloat` in interface `INode`
Parameters:
  `propname` - ...
  `value` - ...

### setBoolean

public void setBoolean(String propname, boolean value)
Description copied from interface: `INode`
Set the property with the given name to the given boolean value.

Specified by:
  `setBoolean` in interface `INode`
Parameters:
  `propname` - ...
  `value` - ...

### setDate

public void setDate(String propname, Date value)
Description copied from interface: `INode`
Set the property with the given name to the given date value.

Specified by:
  `setDate` in interface `INode`
Parameters:
  `propname` - ...
  `value` - ...

### setJavaObject

public void setJavaObject(String propname, Object value)
Description copied from interface: `INode`
Set the property with the given name to the given Java object value.

Specified by:
  `setJavaObject` in interface `INode`
Parameters:
  `propname` - ...
  `value` - ...

### setNode

public void setNode(String propname, INode value)
Description copied from interface: `INode`
Set the property with the given name to the given node value.

Specified by:
  `setNode` in interface `INode`
Parameters:
  `propname` - ...
  `value` - ...

### unset

public void unset(String propname)
Remove a property. Note that this works only for explicitly set properties, not for those specified via property relation.

Specified by:
  `unset` in interface `INode`

### lastModified

public long lastModified()
Description copied from interface: `INode`
Get the node's last modification timestamp.

Specified by:
  `lastModified` in interface `INode`
Returns:
  ...

### created

public long created()
Description copied from interface: `INode`
Get the node's creation timestamp.

Specified by:
  `created` in interface `INode`
Returns:
  ...

### toString

public String toString()
Return a string representation for this node. This tries to call the javascript implemented toString() if it is defined.

Overrides:
  `toString` in class `Object`
Returns:
  a string representing this node.

### isRelational

public boolean isRelational()
Tell whether this node is stored inside a relational db. This doesn't mean it actually is stored in a relational db, just that it would be, if the node was persistent

### persist

public void persist()
Public method to make a node persistent.

### getCacheNode

public INode getCacheNode()
Get the cache node for this node. This can be used to store transient cache data per node from Javascript.

Specified by:
  `getCacheNode` in interface `INode`

### clearCacheNode

public void clearCacheNode()
Reset the cache node for this node.

Specified by:
  `clearCacheNode` in interface `INode`

### getNonVirtualParent

public Node getNonVirtualParent()
This method walks down node path to the first non-virtual node and return it. limit max depth to 5, since there shouldn't be more then 2 layers of virtual nodes.

### isNullNode

public boolean isNullNode()
Instances of this class may be used to mark an entry in the object cache as null. This method tells the caller whether this is the case.

### hashCode

public int hashCode()
We overwrite hashCode to make it dependant from the prototype. That way, when the prototype changes, the node will automatically get a new ESNode wrapper, since they're cached in a hashtable. You gotta love these hash code tricks ;-)

Overrides:
  `hashCode` in class `Object`

### dump

public void dump()