org.jboss.dna.graph.session
Class GraphSession.Node<Payload,PropertyPayload>

java.lang.Object
  extended by org.jboss.dna.graph.session.GraphSession.Node<Payload,PropertyPayload>
Enclosing class:
GraphSession<Payload,PropertyPayload>

@NotThreadSafe
public static class GraphSession.Node<Payload,PropertyPayload>
extends Object


Constructor Summary
GraphSession.Node(GraphSession<Payload,PropertyPayload> cache, GraphSession.Node<Payload,PropertyPayload> parent, GraphSession.NodeId nodeId, Location location)
           
 
Method Summary
 void clearChanges()
          Clear any transient changes that have been accumulated in this node.
 void cloneNode()
          Clone this node (and all nodes below it).
 boolean containsChangesWithExternalDependencies()
          This method determines whether this node, or any nodes below it, contain changes that depend on nodes that are outside of this branch.
 void copyTo(GraphSession.Node<Payload,PropertyPayload> parent)
          Copy this node (and all nodes below it) and place the copy under the supplied parent location.
 GraphSession.Node<Payload,PropertyPayload> createChild(Name name)
          Create a new child node with the supplied name.
 GraphSession.Node<Payload,PropertyPayload> createChild(Name name, Collection<Property> idProperties)
          Create a new child node with the supplied name and multiple initial identification properties.
 GraphSession.Node<Payload,PropertyPayload> createChild(Name name, Collection<Property> idProperties, Property... remainingProperties)
          Create a new child node with the supplied name and multiple initial properties.
 GraphSession.Node<Payload,PropertyPayload> createChild(Name name, Property... properties)
          Create a new child node with the supplied name and multiple initial properties.
 void destroy()
          Remove this node from it's parent and destroy it's contents.
 boolean equals(Object obj)
          
 GraphSession.Node<Payload,PropertyPayload> getChild(Name name, int sns)
          Get the child with the supplied name and SNS index.
 GraphSession.Node<Payload,PropertyPayload> getChild(Path.Segment segment)
          Get the child with the supplied segment.
 Iterable<GraphSession.Node<Payload,PropertyPayload>> getChildren()
          Get an iterator over the children.
 Iterable<GraphSession.Node<Payload,PropertyPayload>> getChildren(Name name)
          Get an iterator over the children that have the supplied name.
 int getChildrenCount()
          Get the number of children.
 int getChildrenCount(Name name)
          Get the number of children that have the same supplied name.
 long getExpirationTimeInMillis()
          Get the time when this node expires.
 GraphSession.Node<Payload,PropertyPayload> getFirstChild(Name name)
          Get the first child matching the name and lowest SNS index
 Location getLocation()
          Get the current location for this node.
 Name getName()
          Get the name of this node, without any same-name-sibling index.
 GraphSession.NodeId getNodeId()
           
 GraphSession.Node<Payload,PropertyPayload> getParent()
          Get this node's parent node.
 Path getPath()
          Get the current path to this node.
 Payload getPayload()
           
 Collection<GraphSession.PropertyInfo<PropertyPayload>> getProperties()
          Get the information for each of the properties on this node.
 GraphSession.PropertyInfo<PropertyPayload> getProperty(Name name)
          Get from this node the property with the supplied name.
 int getPropertyCount()
          Get the number of properties owned by this node.
 Set<Name> getPropertyNames()
          Get the names of the properties on this node.
 Path.Segment getSegment()
          Get the path segment for this node.
 GraphSession<Payload,PropertyPayload> getSession()
          Get the session to which this node belongs.
 GraphSession.StructureSnapshot<PropertyPayload> getSnapshot(boolean pathsOnly)
          Obtain a snapshot of the structure below this node.
 String getString(NamespaceRegistry registry)
          Utility method to obtain a string representation that uses the namespace prefixes where appropriate.
 boolean hasChild(Name name, int sns)
          Determine whether this node has a child with the supplied name and SNS index.
 boolean hasChild(Path.Segment segment)
          Determine whether this node has a child with the supplied name and SNS index.
 int hashCode()
          
 boolean isAtOrBelow(GraphSession.Node<Payload,PropertyPayload> other)
           
 boolean isChanged(boolean recursive)
          Determine whether this node has been marked as having changes.
 boolean isExpired()
          Determine if this node's information has expired.
 boolean isLeaf()
          Determine if this node is a leaf node with no children.
 boolean isLoaded()
          Determine if this node is loaded and usable.
 boolean isNew()
          Determine whether this node has been created since the last save.
 boolean isRoot()
           
 boolean isStale()
          Determine whether this node is stale because it was dropped from the cache.
 void loadedWith(List<Location> children, Map<Name,GraphSession.PropertyInfo<PropertyPayload>> properties, DateTime expirationTime)
          Define the persistent child information that this node is to be populated with.
 void markAsChanged()
          Mark this node as having changes.
 void markAsCopied()
           
 void markAsNew()
          Mark this node has having been created and not yet saved.
 void moveTo(GraphSession.Node<Payload,PropertyPayload> parent)
          Move this node from its current location so that is is a child of the supplied parent.
 void moveTo(GraphSession.Node<Payload,PropertyPayload> parent, Name newNodeName)
          Move this node from its current location so that is is a child of the supplied parent, renaming the node in the process.
 void onCachedNodes(GraphSession.NodeVisitor<Payload,PropertyPayload> visitor)
          Visit all loaded and unloaded nodes in the cache.
 void onChangedNodes(GraphSession.NodeVisitor<Payload,PropertyPayload> visitor)
          Visit all changed nodes in the cache.
 void onLoadedNodes(GraphSession.NodeVisitor<Payload,PropertyPayload> visitor)
          Visit all nodes in the cache that are already loaded
 void orderChildBefore(Path.Segment childToBeMoved, Path.Segment before)
          Move the specified child to be located immediately before the other supplied node.
 GraphSession.PropertyInfo<PropertyPayload> removeProperty(Name name)
          Remove a property from this node.
 void rename(Name newNodeName)
          Rename this node to have a different name.
 void setPayload(Payload payload)
           
 GraphSession.PropertyInfo<PropertyPayload> setProperty(Property property, boolean isMultiValued, PropertyPayload payload)
          Set the supplied property information on this node.
 String toString()
          
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

GraphSession.Node

public GraphSession.Node(GraphSession<Payload,PropertyPayload> cache,
                         GraphSession.Node<Payload,PropertyPayload> parent,
                         GraphSession.NodeId nodeId,
                         Location location)
Method Detail

getSession

public GraphSession<Payload,PropertyPayload> getSession()
Get the session to which this node belongs.

Returns:
the session; never null

getExpirationTimeInMillis

public final long getExpirationTimeInMillis()
Get the time when this node expires.

Returns:
the time in milliseconds past the epoch when this node's cached information expires, or Long.MAX_VALUE if there is no expiration or if the node has not been loaded
See Also:
isExpired(), isLoaded()

isExpired

public final boolean isExpired()
Determine if this node's information has expired. This method will never return true if the node is not loaded. This method is idempotent.

Returns:
true if this node's information has been read from the store and is expired

isLoaded

public final boolean isLoaded()
Determine if this node is loaded and usable. Even though the node may have been loaded previously, this method may return false (and unloads the cached information) if the cached information has expired and thus is no longer usable. Note, however, that changes on or below this node will prevent the node from being unloaded.

Returns:
true if the node's information has already been loaded and may be used, or false otherwise

loadedWith

public void loadedWith(List<Location> children,
                       Map<Name,GraphSession.PropertyInfo<PropertyPayload>> properties,
                       DateTime expirationTime)
Define the persistent child information that this node is to be populated with. This method does not cause the node's information to be read from the store.

This method is intended to be called by the GraphSession.Operations#materialize(org.jboss.dna.graph.Node, Node) , and should not be called by other components.

Parameters:
children - the children for this node; may not be null
properties - the properties for this node; may not be null
expirationTime - the time that this cached information expires, or null if there is no expiration

isChanged

public final boolean isChanged(boolean recursive)
Determine whether this node has been marked as having changes.

Parameters:
recursive - true if the nodes under this node should be checked, or false if only this node should be checked
Returns:
true if there are changes in the specified scope, or false otherwise

isNew

public final boolean isNew()
Determine whether this node has been created since the last save. If this method returns true, then by definition the parent node will be marked as having changed.

Returns:
true if this node is new, or false otherwise

containsChangesWithExternalDependencies

public boolean containsChangesWithExternalDependencies()
This method determines whether this node, or any nodes below it, contain changes that depend on nodes that are outside of this branch.

Returns:
true if this branch has nodes with changes dependent on nodes outside of this branch

clearChanges

public void clearChanges()
Clear any transient changes that have been accumulated in this node.

See Also:
markAsChanged()

markAsChanged

public final void markAsChanged()
Mark this node as having changes.

See Also:
clearChanges(), markAsNew()

markAsCopied

public final void markAsCopied()

markAsNew

public final void markAsNew()
Mark this node has having been created and not yet saved.

See Also:
clearChanges(), markAsChanged()

moveTo

public void moveTo(GraphSession.Node<Payload,PropertyPayload> parent)
Move this node from its current location so that is is a child of the supplied parent.

Parameters:
parent - the new parent for this node; may not be null
Throws:
RepositorySourceException - if the parent node is to be loaded but a problem is encountered while doing so
IllegalArgumentException - if this is the root node

moveTo

public void moveTo(GraphSession.Node<Payload,PropertyPayload> parent,
                   Name newNodeName)
Move this node from its current location so that is is a child of the supplied parent, renaming the node in the process.

Parameters:
parent - the new parent for this node; may not be null
newNodeName - the new name for the node, or null if the node should keep the same name
Throws:
RepositorySourceException - if the parent node is to be loaded but a problem is encountered while doing so
IllegalArgumentException - if this is the root node

rename

public void rename(Name newNodeName)
Rename this node to have a different name.

Parameters:
newNodeName -

copyTo

public void copyTo(GraphSession.Node<Payload,PropertyPayload> parent)
Copy this node (and all nodes below it) and place the copy under the supplied parent location. The new copy will be appended to any existing children of the supplied parent node, and will be given the appropriate same-name-sibling index. This method may not be called on the root node.

Parameters:
parent - the new parent for the new copy; may not be null
Throws:
RepositorySourceException - if the parent node is to be loaded but a problem is encountered while doing so
IllegalArgumentException - if the parent is null, or if this is the root node
AccessControlException - if the caller does not have the permission to perform the operation

cloneNode

public void cloneNode()
Clone this node (and all nodes below it). The new copy will be appended to the existing children of the parent, and will be given the appropriate same-name-sibling index.

This is equivalent to calling node.copyTo(node.getParent())

Throws:
IllegalArgumentException - if this is the root node

orderChildBefore

public void orderChildBefore(Path.Segment childToBeMoved,
                             Path.Segment before)
                      throws PathNotFoundException
Move the specified child to be located immediately before the other supplied node.

Parameters:
childToBeMoved - the path segment specifying the child that is to be moved
before - the path segment of the node before which the childToBeMoved should be placed, or null if the child should be moved to the end
Throws:
PathNotFoundException - if the childToBeMoved or before segments do not specify an existing child
IllegalArgumentException - if either segment is null or does not specify an existing node

destroy

public void destroy()
Remove this node from it's parent and destroy it's contents. The location of sibling nodes with the same name will be updated, and the node and all nodes below it will be destroyed and removed from the cache.

Throws:
AccessControlException - if the caller does not have the permission to perform the operation

isRoot

public final boolean isRoot()

isStale

public boolean isStale()
Determine whether this node is stale because it was dropped from the cache.

Returns:
true if the node is stale and should no longer be used

getParent

public GraphSession.Node<Payload,PropertyPayload> getParent()
Get this node's parent node.

Returns:
the parent node

getNodeId

public final GraphSession.NodeId getNodeId()
Returns:
nodeId

getName

public Name getName()
Get the name of this node, without any same-name-sibling index.

Returns:
the name; never null

getSegment

public final Path.Segment getSegment()
Get the path segment for this node.

Returns:
the path segment; never null

getPath

public final Path getPath()
Get the current path to this node.

Returns:
the current path; never null

getLocation

public final Location getLocation()
Get the current location for this node.

Returns:
the current location; never null

createChild

public GraphSession.Node<Payload,PropertyPayload> createChild(Name name)
Create a new child node with the supplied name. The same-name-sibling index will be determined based upon the existing children.

Parameters:
name - the name of the new child node
Returns:
the new child node
Throws:
IllegalArgumentException - if the name is null
RepositorySourceException - if this node must be loaded but doing so results in a problem

createChild

public GraphSession.Node<Payload,PropertyPayload> createChild(Name name,
                                                              Property... properties)
Create a new child node with the supplied name and multiple initial properties. The same-name-sibling index will be determined based upon the existing children.

Parameters:
name - the name of the new child node
properties - the (non-identification) properties for the new node
Returns:
the new child node
Throws:
IllegalArgumentException - if the name or properties are null
ValidationException - if the new node is not valid as a child
RepositorySourceException - if this node must be loaded but doing so results in a problem

createChild

public GraphSession.Node<Payload,PropertyPayload> createChild(Name name,
                                                              Collection<Property> idProperties)
Create a new child node with the supplied name and multiple initial identification properties. The same-name-sibling index will be determined based upon the existing children.

Parameters:
name - the name of the new child node
idProperties - the identification properties for the new node
Returns:
the new child node
Throws:
IllegalArgumentException - if the name or properties are null
ValidationException - if the new node is not valid as a child
RepositorySourceException - if this node must be loaded but doing so results in a problem

createChild

public GraphSession.Node<Payload,PropertyPayload> createChild(Name name,
                                                              Collection<Property> idProperties,
                                                              Property... remainingProperties)
Create a new child node with the supplied name and multiple initial properties. The same-name-sibling index will be determined based upon the existing children.

Parameters:
name - the name of the new child node
idProperties - the identification properties for the new node
remainingProperties - the remaining (non-identification) properties for the new node
Returns:
the new child node
Throws:
IllegalArgumentException - if the name or properties are null
ValidationException - if the new node is not valid as a child
RepositorySourceException - if this node must be loaded but doing so results in a problem

hasChild

public boolean hasChild(Path.Segment segment)
Determine whether this node has a child with the supplied name and SNS index.

Parameters:
segment - the segment of the child
Returns:
true if there is a child, or false if there is no such child
Throws:
RepositorySourceException - if there is a problem loading this node's information from the store

hasChild

public boolean hasChild(Name name,
                        int sns)
Determine whether this node has a child with the supplied name and SNS index.

Parameters:
name - the name of the child
sns - the same-name-sibling index; must be 1 or more
Returns:
true if there is a child, or false if there is no such child
Throws:
RepositorySourceException - if there is a problem loading this node's information from the store

getChild

public GraphSession.Node<Payload,PropertyPayload> getChild(Path.Segment segment)
Get the child with the supplied segment.

Parameters:
segment - the segment of the child
Returns:
the child with the supplied name and SNS index, or null if the children have not yet been loaded
Throws:
PathNotFoundException - if the children have been loaded and the child does not exist
RepositorySourceException - if there is a problem loading this node's information from the store

getFirstChild

public GraphSession.Node<Payload,PropertyPayload> getFirstChild(Name name)
Get the first child matching the name and lowest SNS index

Parameters:
name - the name of the child
Returns:
the first child with the supplied name, or null if the children have not yet been loaded
Throws:
PathNotFoundException - if the children have been loaded and the child does not exist
RepositorySourceException - if there is a problem loading this node's information from the store

getChild

public GraphSession.Node<Payload,PropertyPayload> getChild(Name name,
                                                           int sns)
Get the child with the supplied name and SNS index.

Parameters:
name - the name of the child
sns - the same-name-sibling index; must be 1 or more
Returns:
the child with the supplied name and SNS index; never null
Throws:
PathNotFoundException - if the children have been loaded and the child does not exist
RepositorySourceException - if there is a problem loading this node's information from the store

getChildren

public Iterable<GraphSession.Node<Payload,PropertyPayload>> getChildren(Name name)
Get an iterator over the children that have the supplied name.

Parameters:
name - the of the child nodes to be returned; may not be null
Returns:
an unmodifiable iterator over the cached children that have the supplied name; never null but possibly empty
Throws:
RepositorySourceException - if there is a problem loading this node's information from the store

getChildren

public Iterable<GraphSession.Node<Payload,PropertyPayload>> getChildren()
Get an iterator over the children.

Returns:
an unmodifiable iterator over the cached children; never null
Throws:
RepositorySourceException - if there is a problem loading this node's information from the store

getChildrenCount

public int getChildrenCount()
Get the number of children.

Returns:
the number of children in the cache
Throws:
RepositorySourceException - if there is a problem loading this node's information from the store

getChildrenCount

public int getChildrenCount(Name name)
Get the number of children that have the same supplied name.

Parameters:
name - the name of the children to count
Returns:
the number of children in the cache
Throws:
RepositorySourceException - if there is a problem loading this node's information from the store

isLeaf

public boolean isLeaf()
Determine if this node is a leaf node with no children.

Returns:
true if this node has no children
Throws:
RepositorySourceException - if there is a problem loading this node's information from the store

getProperty

public GraphSession.PropertyInfo<PropertyPayload> getProperty(Name name)
Get from this node the property with the supplied name.

Parameters:
name - the property name; may not be null
Returns:
the property with the supplied name, or null if there is no such property on this node

setProperty

public GraphSession.PropertyInfo<PropertyPayload> setProperty(Property property,
                                                              boolean isMultiValued,
                                                              PropertyPayload payload)
Set the supplied property information on this node.

Parameters:
property - the new property; may not be null
isMultiValued - true if the property is multi-valued
payload - the optional payload for this property; may be null
Returns:
the previous information for the property, or null if there was no previous property
Throws:
AccessControlException - if the caller does not have the permission to perform the operation

removeProperty

public GraphSession.PropertyInfo<PropertyPayload> removeProperty(Name name)
Remove a property from this node.

Parameters:
name - the name of the property to be removed; may not be null
Returns:
the previous information for the property, or null if there was no previous property

getPropertyNames

public Set<Name> getPropertyNames()
Get the names of the properties on this node.

Returns:
the names of the properties; never null

getProperties

public Collection<GraphSession.PropertyInfo<PropertyPayload>> getProperties()
Get the information for each of the properties on this node.

Returns:
the information for each of the properties; never null

getPropertyCount

public int getPropertyCount()
Get the number of properties owned by this node.

Returns:
the number of properties; never negative

isAtOrBelow

public boolean isAtOrBelow(GraphSession.Node<Payload,PropertyPayload> other)

getPayload

public Payload getPayload()
Returns:
payload

setPayload

public void setPayload(Payload payload)
Parameters:
payload - Sets payload to the specified value.

hashCode

public final int hashCode()

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

equals

public boolean equals(Object obj)

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

getString

public String getString(NamespaceRegistry registry)
Utility method to obtain a string representation that uses the namespace prefixes where appropriate.

Parameters:
registry - the namespace registry, or null if no prefixes should be used
Returns:
the string representation; never null

toString

public String toString()

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

onLoadedNodes

public void onLoadedNodes(GraphSession.NodeVisitor<Payload,PropertyPayload> visitor)
Visit all nodes in the cache that are already loaded

Parameters:
visitor - the visitor; may not be null

onCachedNodes

public void onCachedNodes(GraphSession.NodeVisitor<Payload,PropertyPayload> visitor)
Visit all loaded and unloaded nodes in the cache.

Parameters:
visitor - the visitor; may not be null

onChangedNodes

public void onChangedNodes(GraphSession.NodeVisitor<Payload,PropertyPayload> visitor)
Visit all changed nodes in the cache.

Parameters:
visitor - the visitor; may not be null

getSnapshot

public GraphSession.StructureSnapshot<PropertyPayload> getSnapshot(boolean pathsOnly)
Obtain a snapshot of the structure below this node.

Parameters:
pathsOnly - true if the snapshot should only include paths, or false if the entire locations should be included
Returns:
the snapshot


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