org.apache.jackrabbit.commons.flat
Class ItemSequence

java.lang.Object
  extended by org.apache.jackrabbit.commons.flat.ItemSequence
Direct Known Subclasses:
ItemSequence.NodeSequenceImpl, ItemSequence.PropertySequenceImpl

public abstract class ItemSequence
extends Object

This class serves as main entry point for obtaining sequences of Node s and Propertys. It provides factory methods for creating NodeSequences and PropertySequences.

NodeSequence and PropertySequence instances provide a flat representation of a JCR hierarchy rooted at a certain node. They allow iterating over all items, retrieving items by key, checking whether a given key is mapped, adding new items and removing existing items.

The specifics of the mapping from the flat representation to the JCR hierarchy are delegated to a TreeManager. Particularly the TreeManager specifies the order of the items when retrieved as sequence and when and how to add and remove intermediate nodes when new items are inserted or removed.

An TreeTraverser.ErrorHandler is used to handle exceptions which occur while traversing the hierarchy.

See Also:
TreeTraverser, NodeSequence, PropertySequence, TreeManager

Nested Class Summary
protected static class ItemSequence.NodeSequenceImpl
           
protected static class ItemSequence.PropertySequenceImpl
           
 
Field Summary
protected  boolean autoSave
           
protected  TreeTraverser.ErrorHandler errorHandler
          The TreeTraverser.ErrorHandler instance used for handling exceptions occurring while traversing the hierarchy.
protected  Comparator<String> order
           
protected  Node root
           
protected  TreeManager treeManager
          The TreeManager instance managing the mapping between the sequence view and the JCR hierarchy.
 
Constructor Summary
protected ItemSequence(TreeManager treeManager, TreeTraverser.ErrorHandler errorHandler)
          Create a new ItemSequence instance.
 
Method Summary
static NodeSequence createNodeSequence(TreeManager treeManager)
          Create a new NodeSequence instance.
static NodeSequence createNodeSequence(TreeManager treeManager, TreeTraverser.ErrorHandler errorHandler)
          Create a new NodeSequence instance.
static PropertySequence createPropertySequence(TreeManager treeManager)
          Create a new PropertySequence instance.
static PropertySequence createPropertySequence(TreeManager treeManager, TreeTraverser.ErrorHandler errorHandler)
          Create a new PropertySequence instance.
protected  Node getMinimal()
          Returns the node with the minimal key wrt.
protected  Node getMinimal(Node node)
          Returns the node amongst the child nodes of node whose key is minimal wrt.
 NodeSequence getNodeSequence()
          Create a new NodeSequence instance with the same parameterization as this instance.
protected abstract  Node getParent(String key)
          Returns the parent node for the given key.
protected  Node getPredecessor(Node node, String key)
          Returns the direct predecessor of key amongst node's child nodes wrt. to TreeManager.getOrder().
protected  Node getPredecessor(String key)
          Returns the predecessor node for the given key.
 PropertySequence getPropertySequence()
          Create a new PropertySequence instance with the same parametrization as this instance.
protected  Node getSuccessor(Node node, String key)
          Returns the successor node for the given key.
protected  void renamePath(Node node, String key)
          Rename the path of the node with the minimal key.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

treeManager

protected final TreeManager treeManager
The TreeManager instance managing the mapping between the sequence view and the JCR hierarchy.


errorHandler

protected final TreeTraverser.ErrorHandler errorHandler
The TreeTraverser.ErrorHandler instance used for handling exceptions occurring while traversing the hierarchy.


root

protected final Node root
See Also:
TreeManager.getRoot()

order

protected final Comparator<String> order
See Also:
TreeManager.getOrder()

autoSave

protected final boolean autoSave
See Also:
TreeManager.getAutoSave()
Constructor Detail

ItemSequence

protected ItemSequence(TreeManager treeManager,
                       TreeTraverser.ErrorHandler errorHandler)
Create a new ItemSequence instance.

Parameters:
treeManager - The TreeManager for managing the mapping between the sequence view and the JCR hierarchy.
errorHandler - The TreeTraverser.ErrorHandler for handling exceptions occurring while traversing the hierarchy.
Throws:
IllegalArgumentException - If either treeManager is null or TreeManager.getRoot() return null or TreeManager.getOrder() return null.
Method Detail

createNodeSequence

public static NodeSequence createNodeSequence(TreeManager treeManager,
                                              TreeTraverser.ErrorHandler errorHandler)
Create a new NodeSequence instance.

Parameters:
treeManager - The TreeManager for managing the mapping between the sequence view and the JCR hierarchy.
errorHandler - The TreeTraverser.ErrorHandler for handling exceptions occurring while
Returns:

createNodeSequence

public static NodeSequence createNodeSequence(TreeManager treeManager)
Create a new NodeSequence instance.

Parameters:
treeManager - The TreeManager for managing the mapping between the sequence view and the JCR hierarchy.
Returns:

createPropertySequence

public static PropertySequence createPropertySequence(TreeManager treeManager,
                                                      TreeTraverser.ErrorHandler errorHandler)
Create a new PropertySequence instance.

Parameters:
treeManager - The TreeManager for managing the mapping between the sequence view and the JCR hierarchy.
errorHandler - The TreeTraverser.ErrorHandler for handling exceptions occurring while
Returns:

createPropertySequence

public static PropertySequence createPropertySequence(TreeManager treeManager)
Create a new PropertySequence instance.

Parameters:
treeManager - The TreeManager for managing the mapping between the sequence view and the JCR hierarchy.
Returns:

getNodeSequence

public NodeSequence getNodeSequence()
Create a new NodeSequence instance with the same parameterization as this instance.

Returns:

getPropertySequence

public PropertySequence getPropertySequence()
Create a new PropertySequence instance with the same parametrization as this instance.

Returns:

getParent

protected abstract Node getParent(String key)
                           throws RepositoryException
Returns the parent node for the given key. When the key is not present in this sequence already, the returned node is the node that would contain that key if it where present.

Throws:
RepositoryException

getPredecessor

protected final Node getPredecessor(String key)
                             throws RepositoryException
Returns the predecessor node for the given key. That is the node whose key directly precedes the passed key in the order determined by TreeManager.getOrder(). There are two cases:
  • A node with the given key is mapped: then that node is returned.
  • A node with the given key is not mapped: the the node where that would contain that key if present is returned.

Throws:
RepositoryException

getPredecessor

protected final Node getPredecessor(Node node,
                                    String key)
                             throws RepositoryException
Returns the direct predecessor of key amongst node's child nodes wrt. to TreeManager.getOrder(). Returns null if either node has no child nodes or node is a leaf (see TreeManager.isLeaf(Node)) or key is smaller than all the keys of all child nodes of node.

Throws:
RepositoryException

getSuccessor

protected final Node getSuccessor(Node node,
                                  String key)
                           throws RepositoryException
Returns the successor node for the given key. That is the node whose key directly succeeds the passed key in the order determined by TreeManager.getOrder(). There are two cases:
  • A node with the given key is mapped: then that node is returned.
  • A node with the given key is not mapped: the the node where that would contain that key if present is returned.

Throws:
RepositoryException

getMinimal

protected final Node getMinimal()
                         throws RepositoryException
Returns the node with the minimal key wrt. TreeManager.getOrder(). For the empty sequence this is TreeManager.getRoot().

Throws:
RepositoryException

getMinimal

protected final Node getMinimal(Node node)
                         throws RepositoryException
Returns the node amongst the child nodes of node whose key is minimal wrt. TreeManager.getOrder(). Returns null id either node has no child nodes or node is a leaf (see TreeManager.isLeaf(Node)).

Throws:
RepositoryException

renamePath

protected final void renamePath(Node node,
                                String key)
                         throws RepositoryException
Rename the path of the node with the minimal key. That is, assuming node is the node with the minimal key (see getMinimal()), this method renames every segment of the path of node up to TreeManager.getRoot() to key . Note: If node is not the node with the minimal key, the behavior of this method is not specified.

Throws:
RepositoryException


Copyright © 2004-2010 The Apache Software Foundation. All Rights Reserved.