org.jboss.dna.graph.connector.map
Class AbstractMapWorkspace

java.lang.Object
  extended by org.jboss.dna.graph.connector.map.AbstractMapWorkspace
All Implemented Interfaces:
MapWorkspace

public abstract class AbstractMapWorkspace
extends Object
implements MapWorkspace

A default implementation of MapWorkspace that only requires the user to implement some simple, map-like operations.


Method Summary
 MapNode cloneNode(ExecutionContext context, MapNode original, MapWorkspace newWorkspace, MapNode newParent, Name desiredName, Path.Segment desiredSegment, boolean removeExisting, Set<Location> removedExistingNodes)
          This should clone the subgraph given by the original node and place the cloned copy under the supplied new parent.
 MapNode copyNode(ExecutionContext context, MapNode original, MapWorkspace newWorkspace, MapNode newParent, Name desiredName, boolean recursive)
          This should copy the subgraph given by the original node and place the new copy under the supplied new parent.
 MapNode createNode(ExecutionContext context, MapNode parentNode, Name name, UUID uuid)
          Create a new node with the supplied name, as a child of the supplied parent.
 MapNode createNode(ExecutionContext context, String pathToNewNode)
          Create a node at the supplied path.
 boolean equals(Object obj)
          
 Path getLowestExistingPath(Path path)
          Find the lowest existing node along the path.
 String getName()
          Returns the name of the workspace.
 MapNode getNode(ExecutionContext context, String path)
          Find a node with the given path.
 MapNode getNode(Path path)
          Find a node with the given path.
abstract  MapNode getNode(UUID nodeUuid)
          Gets the node with the given UUID from the backing map, if one exists
 MapNode getRoot()
          Returns the root node in the workspace.
 Set<UUID> getUuidsUnderNode(MapNode node)
          Returns all of the UUIDs in the branch rooted at node.
 void moveNode(ExecutionContext context, MapNode node, Name desiredNewName, MapWorkspace newWorkspace, MapNode newParent, MapNode beforeNode)
          Move the supplied node to the new parent.
 Path pathFor(PathFactory pathFactory, MapNode node)
          Returns the absolute path to the given node
 void removeNode(ExecutionContext context, MapNode node)
          Removes the given node and its children, correcting the SNS and child indices for its parent.
 String toString()
          
 
Methods inherited from class java.lang.Object
getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Method Detail

getNode

public abstract MapNode getNode(UUID nodeUuid)
Gets the node with the given UUID from the backing map, if one exists

Specified by:
getNode in interface MapWorkspace
Parameters:
nodeUuid - the UUID of the node to be retrieved; may not be null
Returns:
the node that exists in the backing map with the given UUID

getName

public String getName()
Description copied from interface: MapWorkspace
Returns the name of the workspace. There can only be one workspace with a given name per repository.

Specified by:
getName in interface MapWorkspace
Returns:
name

getRoot

public MapNode getRoot()
Returns the root node in the workspace. This returns a map node where node.getParent() == null and node.getUuid() == repository.getRootNodeUuid().

Specified by:
getRoot in interface MapWorkspace
Returns:
the root node in the workspace
See Also:
MapWorkspace.getRoot()

getNode

public MapNode getNode(ExecutionContext context,
                       String path)
Find a node with the given path.

Parameters:
context - the execution context to use to convert path to a Path; may not be null
path - the path to the node; may not be null
Returns:
the node with the path, or null if the node does not exist

getNode

public MapNode getNode(Path path)
Find a node with the given path.

Specified by:
getNode in interface MapWorkspace
Parameters:
path - the path to the node; may not be null
Returns:
the node with the path, or null if the node does not exist

pathFor

public Path pathFor(PathFactory pathFactory,
                    MapNode node)
Returns the absolute path to the given node

Specified by:
pathFor in interface MapWorkspace
Parameters:
pathFactory - the path factory to use to create the path from the list of names of all of the nodes on the path from the root node to the given node
node - the node for which the path should be returned
Returns:
the absolute path to the given node

getLowestExistingPath

public Path getLowestExistingPath(Path path)
Find the lowest existing node along the path.

Specified by:
getLowestExistingPath in interface MapWorkspace
Parameters:
path - the path to the node; may not be null
Returns:
the lowest existing node along the path, or the root node if no node exists on the path

removeNode

public void removeNode(ExecutionContext context,
                       MapNode node)
Removes the given node and its children, correcting the SNS and child indices for its parent.

Specified by:
removeNode in interface MapWorkspace
Parameters:
context - the current execution context
node - the node to be removed

createNode

public MapNode createNode(ExecutionContext context,
                          String pathToNewNode)
Create a node at the supplied path. The parent of the new node must already exist.

Specified by:
createNode in interface MapWorkspace
Parameters:
context - the environment; may not be null
pathToNewNode - the path to the new node; may not be null
Returns:
the new node (or root if the path specified the root)

createNode

public MapNode createNode(ExecutionContext context,
                          MapNode parentNode,
                          Name name,
                          UUID uuid)
Create a new node with the supplied name, as a child of the supplied parent.

Specified by:
createNode in interface MapWorkspace
Parameters:
context - the execution context
parentNode - the parent node; may not be null
name - the name; may not be null
uuid - the UUID of the node, or null if the UUID is to be generated
Returns:
the new node

moveNode

public void moveNode(ExecutionContext context,
                     MapNode node,
                     Name desiredNewName,
                     MapWorkspace newWorkspace,
                     MapNode newParent,
                     MapNode beforeNode)
Move the supplied node to the new parent. This method automatically removes the node from its existing parent, and also correctly adjusts the index to be correct in the new parent.

Specified by:
moveNode in interface MapWorkspace
Parameters:
context -
node - the node to be moved; may not be the root
desiredNewName - the new name for the node, if it is to be changed; may be null
newWorkspace - the workspace containing the new parent node
newParent - the new parent; may not be the root
beforeNode - the node before which this new node should be placed

copyNode

public MapNode copyNode(ExecutionContext context,
                        MapNode original,
                        MapWorkspace newWorkspace,
                        MapNode newParent,
                        Name desiredName,
                        boolean recursive)
This should copy the subgraph given by the original node and place the new copy under the supplied new parent. Note that internal references between nodes within the original subgraph must be reflected as internal nodes within the new subgraph.

Specified by:
copyNode in interface MapWorkspace
Parameters:
context - the context; may not be null
original - the node to be copied; may not be null
newWorkspace - the workspace containing the new parent node; may not be null
newParent - the parent where the copy is to be placed; may not be null
desiredName - the desired name for the node; if null, the name will be obtained from the original node
recursive - true if the copy should be recursive
Returns:
the new node, which is the top of the new subgraph

cloneNode

public MapNode cloneNode(ExecutionContext context,
                         MapNode original,
                         MapWorkspace newWorkspace,
                         MapNode newParent,
                         Name desiredName,
                         Path.Segment desiredSegment,
                         boolean removeExisting,
                         Set<Location> removedExistingNodes)
                  throws UuidAlreadyExistsException
This should clone the subgraph given by the original node and place the cloned copy under the supplied new parent. Note that internal references between nodes within the original subgraph must be reflected as internal nodes within the new subgraph.

Specified by:
cloneNode in interface MapWorkspace
Parameters:
context - the context; may not be null
original - the node to be cloned; may not be null
newWorkspace - the workspace containing the new parent node; may not be null
newParent - the parent where the clone is to be placed; may not be null
desiredName - the desired name for the node; if null, the name will be calculated from desiredSegment; Exactly one of desiredSegment and desiredName must be non-null
desiredSegment - the exact segment at which the clone should be rooted; if null, the name will be inferred from desiredName; Exactly one of desiredSegment and desiredName must be non-null
removeExisting - true if existing nodes in the new workspace with the same UUIDs as nodes in the branch rooted at original should be removed; if false, a UuidAlreadyExistsException will be thrown if a UUID conflict is detected
removedExistingNodes - the set into which should be placed all of the existing nodes that were removed as a result of this clone operation, or null if these nodes need not be collected
Returns:
the new node, which is the top of the new subgraph
Throws:
UuidAlreadyExistsException - if removeExisting is true and and a UUID in the source tree already exists in the new workspace
See Also:
MapWorkspace#cloneNode(ExecutionContext, MapNode, MapWorkspace, MapNode, Name, Segment, boolean, Set)

getUuidsUnderNode

public Set<UUID> getUuidsUnderNode(MapNode node)
Returns all of the UUIDs in the branch rooted at node. The UUID of node will be included in the set of returned UUIDs.

Parameters:
node - the root of the branch
Returns:
all of the UUIDs in the branch rooted at node

equals

public boolean equals(Object obj)

Overrides:
equals in class Object
See Also:
Object.equals(java.lang.Object)

toString

public String toString()

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


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