ist.palcom.hmap
Class TreeNode

java.lang.Object
  extended by ist.palcom.hmap.TreeNode
All Implemented Interfaces:
Handler
Direct Known Subclasses:
Dir, Leaf

public abstract class TreeNode
extends Object
implements Handler


Field Summary
static String CMD_SETNAME
           
static String CMD_SETPARENT
           
protected  ArrayList listeners
          List of listeners of the node
protected  String name
          hmap node name
protected  Dir parent
          parent of the node
protected  String path
          Path of the node.
static int TET_DIR
           
static int TET_LEAF
           
static int TET_UNKNOWN
           
 
Constructor Summary
protected TreeNode(int treeNodeType, String name)
           
 
Method Summary
 void addListener(HmapListener listener)
           
 Dir asDir()
           
 Leaf asLeaf()
           
abstract  void computePath()
          computes the path of this node (relative to its hmap root)
protected  String firstOfPath(String path)
          Return the first part of a path separated by "/".
 String getName()
           
 Dir getParent()
           
 String getPath()
           
abstract  void invokeHandler(HmapEvent event)
          Invokes this node's handler
abstract  void invokeHandler(String path, HmapEvent event)
          Invokes a handler at a given path with a given payload
protected  void invokeListeners(HmapEvent event)
          Invokes this node's listeners with a given payload and this node's path
abstract  boolean isAncestorOf(TreeNode node)
          Returns true if this node is a direct ancestor of
 boolean isDir()
           
 boolean isLeaf()
           
protected  String printListeners()
           
protected  String printListeners(int indent)
           
 void removeListener(HmapListener listener)
           
abstract  void resetPath()
          Resets the path of the node.
protected  String restOfPath(String path)
          Returns the rest of a path separated by "/".
 void setName(String name)
          Sets the name of the node
 void setParent(Dir parent)
          Sets the parent of this node
abstract  String toString(int indent)
           
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, println, toString
 
Methods inherited from interface ist.palcom.hmap.Handler
handle
 

Field Detail

TET_UNKNOWN

public static final int TET_UNKNOWN
See Also:
Constant Field Values

TET_DIR

public static final int TET_DIR
See Also:
Constant Field Values

TET_LEAF

public static final int TET_LEAF
See Also:
Constant Field Values

CMD_SETNAME

public static final String CMD_SETNAME
See Also:
Constant Field Values

CMD_SETPARENT

public static final String CMD_SETPARENT
See Also:
Constant Field Values

name

protected String name
hmap node name


path

protected String path
Path of the node. Generated first time rquested. Nullified on moves


parent

protected Dir parent
parent of the node


listeners

protected ArrayList listeners
List of listeners of the node

Constructor Detail

TreeNode

protected TreeNode(int treeNodeType,
                   String name)
Parameters:
treeNodeType - the type of the treenode
name - the name of the treenode
Method Detail

computePath

public abstract void computePath()
computes the path of this node (relative to its hmap root)


invokeHandler

public abstract void invokeHandler(String path,
                                   HmapEvent event)
Invokes a handler at a given path with a given payload

Parameters:
path - The path to invoke
event - The payload to invoke the handler with

invokeHandler

public abstract void invokeHandler(HmapEvent event)
Invokes this node's handler

Parameters:
event - The payload to invoke the handler with

toString

public abstract String toString(int indent)
Parameters:
indent - prepend a number of whitespaces to the retured string
Returns:
a stringified version of this node

resetPath

public abstract void resetPath()
Resets the path of the node. This is used when getting moved around


isAncestorOf

public abstract boolean isAncestorOf(TreeNode node)
Returns true if this node is a direct ancestor of

Parameters:
node - The potential (grand)child node

addListener

public void addListener(HmapListener listener)
Parameters:
listener - The HmapListener to add to this node's listeners

removeListener

public void removeListener(HmapListener listener)
Parameters:
listener - The HmapListener to remove from this node's listeners

invokeListeners

protected void invokeListeners(HmapEvent event)
Invokes this node's listeners with a given payload and this node's path

Parameters:
payload - The payload the listeners gets invoked with

isDir

public boolean isDir()
Returns:
true if this node is a dir. False if not

isLeaf

public boolean isLeaf()
Returns:
true if this node is a leaf. False if not

asDir

public Dir asDir()
Returns:
this node as a dir - nul if it is not a dir

asLeaf

public Leaf asLeaf()
Returns:
this node as a leaf - null if it is not a leaf

setParent

public void setParent(Dir parent)
Sets the parent of this node

Parameters:
parent - new parent

getParent

public Dir getParent()
Returns:
the parent dir of this node (which is null if it has none)

getPath

public String getPath()
Returns:
The path of this node (relative to its hmap root)

setName

public void setName(String name)
Sets the name of the node

Parameters:
name - new name

getName

public String getName()
Returns:
the name of the node

firstOfPath

protected String firstOfPath(String path)
Return the first part of a path separated by "/". So eg. firstOfPath("a/b/c") == "a"


restOfPath

protected String restOfPath(String path)
Returns the rest of a path separated by "/". Eg. restOfPath("a/b/c") returns "b/c".


printListeners

protected String printListeners(int indent)
Parameters:
indent - start the returned string with a given number of whitespaces
Returns:
A string with the node's listeners printed in. Used when printing dirs and leaves

printListeners

protected String printListeners()
Returns:
A string with the node's listeners printed in. Used when printing dirs and leaves