net.jinx.db
Class SimpleHierarchy

java.lang.Object
  extended by net.jinx.db.Hierarchy
      extended by net.jinx.db.SimpleHierarchy
All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
MemoryHierarchy

public class SimpleHierarchy
extends Hierarchy

Lightning-fast, memory resident Hierarchy implementation. The close(), commit() and rollback() methods do nothing.

API Stability: Alpha.

See Also:
Serialized Form

Constructor Summary
SimpleHierarchy()
          Constructs a SimpleHierarchy object.
SimpleHierarchy(java.io.File file)
          Utility constructor to read in the contents of an XML File.
 
Method Summary
 java.util.Iterator attributes()
          Provides an Iterator for the attributes that are stored in this Hierarchy, but not any of it's sub-nodes.
 void clearAttributes()
          Clears all attributes from this Hierarchy.
 void clearNodes()
          Clears all sub-nodes from this hierarchy.
 void close()
          Does nothing.
 void commit()
          Does nothing.
 Hierarchy createNode(java.lang.String name)
          Creates a new node with the given name.
 void deleteNode(java.lang.String name)
          Removes the node with the given name.
protected  java.lang.Object getAttributeObject(java.lang.String name)
          Gets the attribute's value Object.
 Hierarchy getNode(java.lang.String name)
          Provides the Hierarchy for the given node name.
 boolean hasAttribute(java.lang.String name)
           
 java.util.Iterator nodes()
          Provides an Iterator for the sub-nodes that are direct sub-nodes of this Hierarchy.
 java.lang.Object removeAttribute(java.lang.String name)
          Remove the value for the given attribute name, returning the previous value.
 void rollback()
          Does nothing.
protected  java.lang.Object setAttributeObject(java.lang.String name, java.lang.Object obj)
          Sets an attribute's value Object.
 
Methods inherited from class net.jinx.db.Hierarchy
addListener, clear, copyTo, getAttribute, getAttribute, getAttribute, getAttribute, getAttribute, getAttribute, getAttribute, getAttribute, getAttribute, getAttribute, getAttribute, getAttribute, getAttribute, getAttribute, getAttribute, getAttribute, getAttribute, getAttribute, getAttribute, getAttribute, getAttribute, getAttribute, getAttribute, getAttribute, getAttribute, parseFromProperties, parseFromXML, propertyChanged, removeListener, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, storeToProperties, storeToXML
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SimpleHierarchy

public SimpleHierarchy()
Constructs a SimpleHierarchy object.


SimpleHierarchy

public SimpleHierarchy(java.io.File file)
Utility constructor to read in the contents of an XML File.

Parameters:
file - the File object pointing to the file to parse.
Throws:
HierarchyException - if an error occurs while reading the file.
Method Detail

close

public void close()
Does nothing.

Overrides:
close in class Hierarchy

commit

public void commit()
Does nothing.

Overrides:
commit in class Hierarchy

rollback

public void rollback()
Does nothing.

Overrides:
rollback in class Hierarchy

clearAttributes

public void clearAttributes()
Description copied from class: Hierarchy
Clears all attributes from this Hierarchy. Does not affect any of the sub-nodes.

Specified by:
clearAttributes in class Hierarchy

clearNodes

public void clearNodes()
Description copied from class: Hierarchy
Clears all sub-nodes from this hierarchy. Depending on the implementation, this may take quite some time to complete, as it will most likely have to recursively delete all the sub-nodes and their attributes from the backing store.

Specified by:
clearNodes in class Hierarchy

attributes

public java.util.Iterator attributes()
Description copied from class: Hierarchy
Provides an Iterator for the attributes that are stored in this Hierarchy, but not any of it's sub-nodes. The remove() method, while it may be functional, should NEVER be used. It is not guaranteed to function properly. For example, JDBMHierarchy's Iterator has a remove() method that will seem to function, but will in fact only work on the in-memory copy of the java.util.HashMap that backs it's Iterator.

To put it more plainly, the Iterator returned from this method is for informational purposes only! If multiple threads manipulate the Hierarchy concurrently (something that is not part of this design), then the Iterator's results could be wrong.

Specified by:
attributes in class Hierarchy
Returns:
a java.util.Iterator.

nodes

public java.util.Iterator nodes()
Description copied from class: Hierarchy
Provides an Iterator for the sub-nodes that are direct sub-nodes of this Hierarchy. The remove() method, while it may be functional, should NEVER be used. It is not guaranteed to function properly. For example, JDBMHierarchy's Iterator has a remove() method that will seem to function, but will in fact only work on the in-memory copy of the java.util.HashMap that backs it's Iterator.

To put it more plainly, the Iterator returned from this method is for informational purposes only! If multiple threads manipulate the Hierarchy concurrently (something that is not part of this design), then the Iterator's results could be wrong.

Specified by:
nodes in class Hierarchy
Returns:
a java.util.Iterator.

getAttributeObject

protected java.lang.Object getAttributeObject(java.lang.String name)
Description copied from class: Hierarchy
Gets the attribute's value Object.

Specified by:
getAttributeObject in class Hierarchy
Parameters:
name - the name of the attribute to access.
Returns:
the value object, or null if the attribute didn't exist.

setAttributeObject

protected java.lang.Object setAttributeObject(java.lang.String name,
                                              java.lang.Object obj)
Description copied from class: Hierarchy
Sets an attribute's value Object. This should not be used to store any type of Object. It should only be used by the methods in this class to store Strings and Objects that wrap primitives (Boolean, Byte, Short, Int, Long, Float, Double, etc.).

Specified by:
setAttributeObject in class Hierarchy
Parameters:
name - the name of the attribute to access.
Returns:
the previous value object, or null if the attribute didn't exist.

removeAttribute

public java.lang.Object removeAttribute(java.lang.String name)
Description copied from class: Hierarchy
Remove the value for the given attribute name, returning the previous value.

Specified by:
removeAttribute in class Hierarchy
Parameters:
name - the name of the attribute to access.
Returns:
the attribute's previous value or null if it didn't exist.

hasAttribute

public boolean hasAttribute(java.lang.String name)
Specified by:
hasAttribute in class Hierarchy
Returns:
true if and only if there is an attribute for the given name.

createNode

public Hierarchy createNode(java.lang.String name)
Description copied from class: Hierarchy
Creates a new node with the given name.

Specified by:
createNode in class Hierarchy
Parameters:
name - the name of the node.
Returns:
the new node's Hierarchy object.

deleteNode

public void deleteNode(java.lang.String name)
Description copied from class: Hierarchy
Removes the node with the given name.

Specified by:
deleteNode in class Hierarchy
Parameters:
name - the name of the node.

getNode

public Hierarchy getNode(java.lang.String name)
Description copied from class: Hierarchy
Provides the Hierarchy for the given node name.

Specified by:
getNode in class Hierarchy
Parameters:
name - the name of the node to access.
Returns:
the Hierarchy object for the node. This will be null if it doesn't exist.