org.modeshape.graph.request
Class CloneBranchRequest

java.lang.Object
  extended by org.modeshape.graph.request.Request
      extended by org.modeshape.graph.request.ChangeRequest
          extended by org.modeshape.graph.request.CloneBranchRequest
All Implemented Interfaces:
Serializable, Cloneable

public class CloneBranchRequest
extends ChangeRequest

Instruction that a branch be cloned from one workspace into another. Cloning a branch differs from cloning a branch in that:

  1. Nodes can be cloned within the same workspace or to another workspace; cloned nodes must be cloned from one workspace into another.
  2. Copied nodes always get new UUIDs; cloned nodes always maintain their UUIDs and hence must define the behavior that occurs if a node with the same UUID already exists in the new workspace.
  3. Nodes can be cloned to a specific name under a specific parent, but can only be added as a new child node at the end of the new parent's children; nodes can be cloned to an exact location among the parent's children, replacing the existing node at that location.

See Also:
Serialized Form

Constructor Summary
CloneBranchRequest(Location from, String fromWorkspace, Location into, String intoWorkspace, Name nameForClone, Path.Segment exactSegmentForClone, boolean removeExisting)
          Create a request to clone a branch to another.
 
Method Summary
 void cancel()
          Cancel this request.
 Location changedLocation()
          Get the location of the top-most node that is to be changed by this request.
 String changedWorkspace()
          Get the name of the workspace that was changed by this request.
 boolean changes(String workspace, Path path)
          Determine if this request changes the branch at the given path.
 CloneBranchRequest clone()
           This method does not clone the results.
 Name desiredName()
          Get the name of the clone if it is to be different than that of the original.
 Path.Segment desiredSegment()
          Get the exact segment at which the clone should be rooted
 boolean equals(Object obj)
          
 Location from()
          Get the location defining the top of the branch to be cloned
 String fromWorkspace()
          Get the name of the workspace containing the branch to be cloned.
 Location getActualLocationAfter()
          Get the actual location of the node after being cloned.
 Location getActualLocationBefore()
          Get the actual location of the node before being cloned.
 Set<Location> getRemovedNodes()
          Get the set of nodes that were removed because of this clone operation.
 int hashCode()
          
 Location into()
          Get the location defining the parent where the new clone is to be placed
 String intoWorkspace()
          Get the name of the workspace where the clone is to be placed
 boolean isReadOnly()
          Return whether this request only reads information.
 boolean isSameWorkspace()
          Determine whether this clone operation is within the same workspace.
 boolean removeExisting()
          Gets whether the clone should remove existing nodes in the new workspace with the same UUID as any of the nodes in the source branch or should throw an exception if such conflict is detected.
 void setActualLocations(Location fromLocation, Location intoLocation)
          Sets the actual and complete location of the node being renamed and its new location.
 void setRemovedNodes(Set<Location> existingNodesThatWereRemoved)
          Set the locations of the nodes that were removed by this operation, if removeExisting() is true.
 String toString()
          
 
Methods inherited from class org.modeshape.graph.request.Request
freeze, getError, hasError, isCancelled, isFrozen, setError, setLatchForFreezing
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

CloneBranchRequest

public CloneBranchRequest(Location from,
                          String fromWorkspace,
                          Location into,
                          String intoWorkspace,
                          Name nameForClone,
                          Path.Segment exactSegmentForClone,
                          boolean removeExisting)
Create a request to clone a branch to another.

Parameters:
from - the location of the top node in the existing branch that is to be cloned
fromWorkspace - the name of the workspace where the from node exists
into - the location of the existing node into which the clone should be placed
intoWorkspace - the name of the workspace where the into node is to be cloned
nameForClone - the desired name for the node that results from the clone, or null if the name of the original should be used
exactSegmentForClone - the exact segment at which the cloned tree should be rooted.
removeExisting - whether any nodes in the intoWorkspace with the same UUIDs as a node in the source branch should be removed (if true) or a UuidAlreadyExistsException should be thrown.
Throws:
IllegalArgumentException - if any of the parameters are null except for nameForClone or exactSegmentForClone. Exactly one of nameForClone and exactSegmentForClone must be null.
Method Detail

from

public Location from()
Get the location defining the top of the branch to be cloned

Returns:
the from location; never null

into

public Location into()
Get the location defining the parent where the new clone is to be placed

Returns:
the to location; never null

fromWorkspace

public String fromWorkspace()
Get the name of the workspace containing the branch to be cloned.

Returns:
the name of the workspace containing the branch to be cloned; never null

intoWorkspace

public String intoWorkspace()
Get the name of the workspace where the clone is to be placed

Returns:
the name of the workspace where the clone is to be placed; never null

isSameWorkspace

public boolean isSameWorkspace()
Determine whether this clone operation is within the same workspace.

Returns:
true if this operation is to be performed within the same workspace, or false if the workspace of the original is different than that of the clone

desiredName

public Name desiredName()
Get the name of the clone if it is to be different than that of the original.

Returns:
the desired name of the clone, or null if an exact segment is specified.

desiredSegment

public Path.Segment desiredSegment()
Get the exact segment at which the clone should be rooted

Returns:
the desired segment of the clone, or null if the desired name should be used to generate a new child node for the into location

removeExisting

public boolean removeExisting()
Gets whether the clone should remove existing nodes in the new workspace with the same UUID as any of the nodes in the source branch or should throw an exception if such conflict is detected.

Returns:
whether the clone should remove existing nodes in the new workspace with the same UUID as any of the nodes in the source branch or should throw an exception if such conflict is detected; true indicates that the nodes should be removed and false indicates that an exception should be thrown

isReadOnly

public boolean isReadOnly()
Return whether this request only reads information.

Specified by:
isReadOnly in class Request
Returns:
true if this request reads information, or false if it requests that the repository content be changed in some way
See Also:
Request.isReadOnly()

setActualLocations

public void setActualLocations(Location fromLocation,
                               Location intoLocation)
Sets the actual and complete location of the node being renamed and its new location. This method must be called when processing the request, and the actual location must have a path.

Parameters:
fromLocation - the actual location of the node being cloned
intoLocation - the actual location of the new clone of the node
Throws:
IllegalArgumentException - if the either location is null; if the old location is not equal to the from location; if the new location is not equal to the into location; if the either location does not have a path
IllegalStateException - if the request is frozen

getActualLocationBefore

public Location getActualLocationBefore()
Get the actual location of the node before being cloned.

Returns:
the actual location of the node before being moved, or null if the actual location was not set

getActualLocationAfter

public Location getActualLocationAfter()
Get the actual location of the node after being cloned.

Returns:
the actual location of the node after being cloned, or null if the actual location was not set

setRemovedNodes

public void setRemovedNodes(Set<Location> existingNodesThatWereRemoved)
Set the locations of the nodes that were removed by this operation, if removeExisting() is true.

Parameters:
existingNodesThatWereRemoved - the (immutable) set of existing node locations; may be null

getRemovedNodes

public Set<Location> getRemovedNodes()
Get the set of nodes that were removed because of this clone operation.

Returns:
the immutable set of locations of the nodes that were removed; never null but possibly empty

changes

public boolean changes(String workspace,
                       Path path)
Determine if this request changes the branch at the given path.

Specified by:
changes in class ChangeRequest
Parameters:
workspace - the name of the workspace; may not be null
path - the path; may not be null
Returns:
true if this request changes a node under the given path
See Also:
ChangeRequest.changes(java.lang.String, org.modeshape.graph.property.Path)

changedLocation

public Location changedLocation()
Get the location of the top-most node that is to be changed by this request. If this request has been completed, this location will always have a path.

Specified by:
changedLocation in class ChangeRequest
Returns:
the location changed by this request
See Also:
ChangeRequest.changedLocation()

changedWorkspace

public String changedWorkspace()
Get the name of the workspace that was changed by this request.

Specified by:
changedWorkspace in class ChangeRequest
Returns:
the name of the workspace changed by this request
See Also:
ChangeRequest.changedWorkspace()

hashCode

public int hashCode()

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

cancel

public void cancel()
Cancel this request. After this method is called, the cancellation flag is set, and any current or future processing of the request may be affected by the cancellation. (Note however, that processors may choose to not respect this request.)

This method is safe to be called by different threads.

Overrides:
cancel in class Request
See Also:
Request.cancel()

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

clone

public CloneBranchRequest clone()

This method does not clone the results.

This method does not clone the results.

Specified by:
clone in class ChangeRequest
See Also:
ChangeRequest.clone()


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