org.modeshape.graph.connector.base
Class MapWorkspace<NodeType extends MapNode>

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

@NotThreadSafe
public abstract class MapWorkspace<NodeType extends MapNode>
extends Object
implements Workspace

The Workspace implementation that represents all nodes as MapNode objects and stores them keyed by their UUID.

Subclasses are required to provide thread-safe access and modification of the state within the encapsulated map, since multiple Transaction implementations may be committing changes to the map 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 map implementation. For example, a subclass may use a lock, or it may use a map implementation that provides the thread-safety.


Field Summary
protected  String name
           
protected  UUID rootNodeUuid
           
 
Constructor Summary
MapWorkspace(String name, MapWorkspace<NodeType> originalToClone)
          Create a new instance of the workspace.
MapWorkspace(String name, NodeType rootNode)
          Create a new instance of the workspace.
 
Method Summary
 String getName()
          Returns the name of the workspace.
abstract  NodeType getNode(UUID uuid)
          Get the node with the supplied UUID.
 NodeType getRootNode()
          Get the root node in this workspace.
 UUID getRootNodeUuid()
          Get the UUID of the root node.
abstract  NodeType putNode(NodeType node)
          Add the node into this workspace's map, overwriting any previous record of the node
abstract  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.
abstract  NodeType removeNode(UUID uuid)
          Remove and return the node with the supplied UUID.
 String toString()
          
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

name

protected final String name

rootNodeUuid

protected final UUID rootNodeUuid
Constructor Detail

MapWorkspace

public MapWorkspace(String name,
                    NodeType rootNode)
Create a new instance of the workspace.

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

MapWorkspace

public MapWorkspace(String name,
                    MapWorkspace<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

getRootNodeUuid

public UUID getRootNodeUuid()
Get the UUID of the root node.

Returns:
rootNodeUuid

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()

getRootNode

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

Returns:
the root node; never null

getNode

public abstract NodeType getNode(UUID uuid)
Get the node with the supplied UUID.

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

putNode

public abstract NodeType putNode(NodeType node)
Add the node into this workspace's map, overwriting any previous record of the node

Parameters:
node - the new node; may not be null
Returns:
the previous node state, or null if the node is new to this workspace

removeNode

public abstract NodeType removeNode(UUID uuid)
Remove and return the node with the supplied UUID. This method will never remove the root node.

Parameters:
uuid - the UUID of the node to be removed
Returns:
the node that was removed, or null if the supplied UUID is the root node's UUID or if this workspace does not contain a node with the supplied UUID

removeAll

public abstract 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()


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