pulse - the web application framework Get pulse at SourceForge.net. Fast, secure and Free Open Source software downloads Ohloh project report for pulse-java

org.torweg.pulse.util.entity
Class Node

java.lang.Object
  extended by org.torweg.pulse.util.entity.AbstractBasicEntity
      extended by org.torweg.pulse.util.entity.Node
All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
AbstractAttribute, AbstractRegistryNode, AbstractTreeElement, SitemapNode

@Entity
@Indexed
public class Node
extends AbstractBasicEntity

is a base entity to build bi-directional tree entities with positionable children lists.

The EJB 3.0 persistence inheritance type of Node is "JOINED".

Note: The FetchType of the children is FetchType.LAZY!

if you want to delete a child, you have to update the parent in HibernateTM!

Version:
$Revision: 2003 $
Author:
Thomas Weber, Daniel Dietz
See Also:
Serialized Form

Constructor Summary
Node()
          builds a new Node.
 
Method Summary
 void addChild(int pos, Node n)
          adds a new Node at a given position to the list childrenSet of this Node.
 void addChild(Node n)
          adds a new Node to the childrenSet of this Node .
 Node getChild(int pos)
          gets the child Node which is at the given position in the child list.
 int getChildIndex(Node node)
          gets the child Node which is at the given position in the child list.
 java.util.List<Node> getChildren()
           
 Node getParent()
           
 boolean hasChildren()
          Returns true, if the Node has children.
 boolean removeChild(Node c)
          removes a Node from the list of child Nodes.
<E extends Node>
void
setChildren(java.util.List<E> c)
          sets the childrenSet of the Node.
 net.sf.json.JSONObject toJSON()
          returns a JSONObject representation of the Node .
 
Methods inherited from class org.torweg.pulse.util.entity.AbstractBasicEntity
compareTo, equals, getFullQualifiedClassNameJAXB, getId, hashCode
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Node

public Node()
builds a new Node.

Method Detail

getParent

public final Node getParent()
Returns:
returns the parent Node of the Node or null, if the Node has no parent.

getChildren

public java.util.List<Node> getChildren()
Returns:
the child nodes of the Node.

getChild

public Node getChild(int pos)
gets the child Node which is at the given position in the child list.

Parameters:
pos - the position
Returns:
the child Node or null, if no such Node exists.

getChildIndex

public int getChildIndex(Node node)
gets the child Node which is at the given position in the child list.

Parameters:
node - the Node to get the index for
Returns:
the Node's index as int in it's parents list of children or -1, if no such Node exists.

addChild

public void addChild(Node n)
adds a new Node to the childrenSet of this Node .

Parameters:
n - the Node to become a child of this Node.

addChild

public void addChild(int pos, Node n)
adds a new Node at a given position to the list childrenSet of this Node.

Parameters:
pos - the position in the list of childrenSet
n - the Node to become a child of this Node.

setChildren

public <E extends Node> void setChildren(java.util.List<E> c)
sets the childrenSet of the Node.

Type Parameters:
E - a Node or a subclass of Node
Parameters:
c - the list of child &lt;E extends Node&gt;s

removeChild

public final boolean removeChild(Node c)
removes a Node from the list of child Nodes.

Parameters:
c - the Node to be removed
Returns:
true, if the removal was successful. Otherwise false.

hasChildren

public final boolean hasChildren()
Returns true, if the Node has children. Otherwise false.

Since the children are fetched lazily, this can be used to quickly check, if the Node contains children without actually loading them.

Returns:
true, if the Node has children. Otherwise false.

toJSON

public net.sf.json.JSONObject toJSON()
returns a JSONObject representation of the Node .

Returns:
a JSONObject representation of the Node