org.modeshape.graph.connector.base
Class PathWorkspace<NodeType extends PathNode>

java.lang.Object
  extended by org.modeshape.graph.connector.base.PathWorkspace<NodeType>
Type Parameters:
NodeType - the type of node
All Implemented Interfaces:
Workspace
Direct Known Subclasses:
SvnWorkspace

@NotThreadSafe
public abstract class PathWorkspace<NodeType extends PathNode>
extends Object
implements Workspace

The Workspace implementation that represents all nodes as PathNode objects and stores them in an internal data structure that allows for nodes to be accessed via a Path.

Subclasses are required to provide thread-safe access and modification of the state within the encapsulated data structure, since multiple Transaction implementations may be committing changes to the data structure at the same time. However, this class does not provide any thread-safety, since the nature of the thread-safety will almost certainly depend on the actual implementation. For example, a subclass may use a lock, or it may use a map implementation that provides the thread-safety.


Nested Class Summary
static interface PathWorkspace.ChangeCommand<NodeType extends PathNode>
          A specific operation that mutates the underlying persistent repository.
 
Constructor Summary
PathWorkspace(String name, PathWorkspace<NodeType> originalToClone)
          Create a new instance of the workspace.
PathWorkspace(String name, UUID rootNodeUuid)
          Create a new instance of the workspace.
 
Method Summary
 void commit(List<PathWorkspace.ChangeCommand<NodeType>> commands)
          Successively (and in order) apply the changes from the list of pending commands All validation for each of the objects (including validation of resource availability in the underlying persistent store) should be performed prior to invoking this method.
 PathWorkspace.ChangeCommand<NodeType> createMoveCommand(NodeType source, NodeType target)
          Create a change command that represents the movement of a node.
 PathWorkspace.ChangeCommand<NodeType> createPutCommand(NodeType oldNode, NodeType node)
          Create a change command for the required update to the given node
 PathWorkspace.ChangeCommand<NodeType> createRemoveCommand(Path path)
          Create a change command for the removal of the given node and its descendants
 String getName()
          Returns the name of the workspace.
abstract  NodeType getNode(Path path)
          Get the node with the supplied path.
abstract  NodeType getRootNode()
          Get the root node in this workspace.
protected  UUID getRootNodeUuid()
           
 NodeType moveNode(NodeType source, NodeType target)
          Move the node from it's previous location to the new location, overwriting any previous node at that location.
 NodeType putNode(NodeType node)
          Save this node into the workspace, overwriting any previous record of the node.
 void removeAll()
          Remove all of the nodes in this workspace, and make sure there is a single root node with no properties and no children.
 NodeType removeNode(Path path)
          Remove this node and its descendants from the workspace.
 String toString()
          
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

PathWorkspace

public PathWorkspace(String name,
                     UUID rootNodeUuid)
Create a new instance of the workspace.

Parameters:
name - the workspace name; may not be null
rootNodeUuid - the root node that is expected to already exist in the map

PathWorkspace

public PathWorkspace(String name,
                     PathWorkspace<NodeType> originalToClone)
Create a new instance of the workspace.

Parameters:
name - the workspace name; may not be null
originalToClone - the workspace that is to be cloned; may not be null
Method Detail

getName

public String getName()
Returns the name of the workspace. There can only be one workspace with a given name per repository.

Specified by:
getName in interface Workspace
Returns:
the name of the workspace
See Also:
Workspace.getName()

getRootNodeUuid

protected UUID getRootNodeUuid()

getRootNode

public abstract NodeType getRootNode()
Get the root node in this workspace.

Returns:
the root node; never null

getNode

public abstract NodeType getNode(Path path)
Get the node with the supplied path.

Parameters:
path - the path to the node
Returns:
the node state as known by this workspace, or null if no such node exists in this workspace

putNode

public NodeType putNode(NodeType node)
Save this node into the workspace, overwriting any previous record of the node. This method should be overridden by writable path workspace implementations that use the default PathWorkspace.ChangeCommand implementations.

Parameters:
node - the new node; may not be null
Returns:
the previous node state, or null if the node is new to this workspace
Throws:
UnsupportedOperationException - by default, subclasses should override this method so that this exception is not thrown
See Also:
createMoveCommand(PathNode, PathNode), createPutCommand(PathNode, PathNode), createRemoveCommand(Path)

moveNode

public NodeType moveNode(NodeType source,
                         NodeType target)
Move the node from it's previous location to the new location, overwriting any previous node at that location. This method should be overridden by writable path workspace implementations that use the default PathWorkspace.ChangeCommand implementations.

The move operation is intended to reflect changes to the node's name or parent only. Changes to the children or properties of the node should be reflected separately in a put command of some sort. The details of the put command are implementation-specific.

Parameters:
source - the original version of the node to be moved; may not be null
target - the new version (implying a change to the name or parent) of the node to be moved; may not be null
Returns:
the new node state;may not be null
Throws:
UnsupportedOperationException - by default, subclasses should override this method so that this exception is not thrown
See Also:
createMoveCommand(PathNode, PathNode), createPutCommand(PathNode, PathNode), createRemoveCommand(Path)

removeNode

public NodeType removeNode(Path path)
Remove this node and its descendants from the workspace. This method should be overridden by writable path workspace implementations that use the default PathWorkspace.ChangeCommand implementations.

Parameters:
path - the path to the node to be removed; may not be null
Returns:
the previous node state, or null if the node does not exist in this workspace
Throws:
UnsupportedOperationException - by default, subclasses should override this method so that this exception is not thrown
See Also:
createMoveCommand(PathNode, PathNode), createPutCommand(PathNode, PathNode), createRemoveCommand(Path)

removeAll

public void removeAll()
Remove all of the nodes in this workspace, and make sure there is a single root node with no properties and no children.


toString

public String toString()

Overrides:
toString in class Object
See Also:
Object.toString()

commit

public void commit(List<PathWorkspace.ChangeCommand<NodeType>> commands)
Successively (and in order) apply the changes from the list of pending commands

All validation for each of the objects (including validation of resource availability in the underlying persistent store) should be performed prior to invoking this method.

Parameters:
commands - the list of commands to apply

createPutCommand

public PathWorkspace.ChangeCommand<NodeType> createPutCommand(NodeType oldNode,
                                                              NodeType node)
Create a change command for the required update to the given node

Parameters:
oldNode - the prior version of the node; may be null if this is a new node
node - the new version of the node; may not be null
Returns:
a PathWorkspace.ChangeCommand instance that reflects the changes to the node
See Also:
commit(List)

createRemoveCommand

public PathWorkspace.ChangeCommand<NodeType> createRemoveCommand(Path path)
Create a change command for the removal of the given node and its descendants

Parameters:
path - the path to the node at the root of the branch to be removed; may not be null
Returns:
a PathWorkspace.ChangeCommand instance that reflects the changes to the node
See Also:
createPutCommand(PathNode, PathNode), commit(List)

createMoveCommand

public PathWorkspace.ChangeCommand<NodeType> createMoveCommand(NodeType source,
                                                               NodeType target)
Create a change command that represents the movement of a node. The movement record will only reflect the changes to the node's name and/or parent. Changes to the node's properties or children should be ignored. A separate put command should be used to reflect these changes.

Parameters:
source - the original version of the node; may not be null
target - the new version of the node; may not be null
Returns:
a PathWorkspace.ChangeCommand instance that reflects the changes to the node
See Also:
createMoveCommand(PathNode, PathNode), commit(List)


Copyright © 2008-2010 JBoss, a division of Red Hat. All Rights Reserved.