com.vinculumtech.carrierwave.plan
Class GraphNode

java.lang.Object
  extended bycom.vinculumtech.carrierwave.plan.GraphNode
All Implemented Interfaces:
java.lang.Cloneable, java.io.Serializable
Direct Known Subclasses:
GraphNodeSet

public class GraphNode
extends java.lang.Object
implements java.io.Serializable, java.lang.Cloneable

GraphNode instances represent nodes in a graph node tree or a graph plan.

Graph plans are used to describe the closure of a graph of Image or Imageable instances, and is interchangeable between each. A graph plan is simply a flat representation (tree) of an object graph closure. An analogy would be to consider a graph plan a type or class, and an object graph an instance of a graph plan.

Any given instance of a GraphNode may only appear once in a graph node tree, they may not be reused. GraphNodes are re-entrant, subsequently graph plans are re-entrant and may be used concurrently.

Version:
$Id: //depot/carrierwave/src/shared/com/vinculumtech/carrierwave/plan/GraphNode.java#24 $
See Also:
Serialized Form

Field Summary
static int NO_INDEX
          No index value.
static java.lang.Object NO_KEY
          No key value.
 
Constructor Summary
GraphNode()
           
GraphNode(java.lang.Class type)
          Creates an origin node.
GraphNode(java.lang.String typeName)
          Creates an origin node.
GraphNode(java.lang.String typeName, java.lang.String edge)
           
GraphNode(java.lang.String typeName, java.lang.String edge, boolean isReadOnly, boolean isReferenceOnly)
           
GraphNode(java.lang.String typeName, java.lang.String edge, boolean isReadOnly, boolean isReferenceOnly, boolean isLiteral)
           
GraphNode(java.lang.String typeName, java.lang.String edge, int index)
           
GraphNode(java.lang.String typeName, java.lang.String edge, int index, boolean isReadOnly, boolean isReferenceOnly)
           
GraphNode(java.lang.String typeName, java.lang.String edge, int index, boolean isReadOnly, boolean isReferenceOnly, boolean isLiteral)
           
GraphNode(java.lang.String typeName, java.lang.String edge, java.lang.Object key)
           
GraphNode(java.lang.String typeName, java.lang.String edge, java.lang.Object key, boolean isReadOnly, boolean isReferenceOnly)
           
GraphNode(java.lang.String typeName, java.lang.String edge, java.lang.Object key, boolean isReadOnly, boolean isReferenceOnly, boolean isLiteral)
           
 
Method Summary
 GraphNode addChildNode(GraphNode childNode)
          Adds the given GraphNode instance to the graph node tree this GraphNode instance is a member of.
Note that GraphNode instances may only belong to one tree, and may only be added to a tree once.
 java.lang.Object clone()
           
 GraphNode cloneShallow()
           
 GraphNode findChildNodeWith(java.lang.String fullEdge)
          Searches for an immediate child GraphNode instance with the given fullEdge value.
 GraphNode findChildNodeWith(java.lang.String edge, boolean isFullEdge)
           
 java.util.List getAllNodes()
          Returns a List of all GraphNode instances in this node tree, including this GraphNode instance.
The List will include all GraphNodeSet instances, but not the GraphNode peer instances in the GraphNodeSet but will include the children of the peer node instances.
 java.util.List getAllParentNodes()
          Returns new List of all the parents of this GraphNode instance, up to and including the origin node.
 java.util.List getChildren()
           
 int getDepth()
          The origin node has a depth of zero.
 java.lang.String getEdge()
           
 java.lang.String getFullEdge()
          Returns the full edge, of the forms:
foo foo[] foo<> foo[0] foo<key>
protected  GraphPlan getGraphPlan()
           
 int getIndex()
           
 java.lang.Object getKey()
           
 java.util.List getNodePath()
          Returns new List containing this GraphNode instance and all the parents of this GraphNode instance, up to and including the origin GraphNode instance.
 GraphNode getOriginNode()
           
protected  GraphNode getOriginNodeOrThis()
           
 GraphNode getParentNode()
           
 java.lang.String getTypeName()
           
 boolean hasChildren()
           
 boolean isContained()
           
 boolean isContainer()
           
 boolean isList()
           
 boolean isLiteral()
           
 boolean isMap()
           
 boolean isNodeSet()
           
 boolean isOrigin()
           
 boolean isReadOnly()
           
 boolean isReferenceOnly()
          Marks this node as a reference-only node in the graph it represents.
 void removeChildNode(GraphNode childNode)
          Removes the given child GraphNode instance from the graph node tree this GraphNode instance is a member of.
The removed childNode may be re-used.
 void resetIndex(int index)
          Forces the element index this GraphNode instance refereces to be the given index value.
This method is intended for use by internal tools.
 void resetKey(java.lang.Object key)
          Forces the element key this GraphNode instance refereces to be the given key value.
This method is intended for use by internal tools.
 void setEdge(java.lang.String fullEdge)
          Sets the fullEdge the GraphNode instance represents.
protected  void setGraphPlan(GraphPlan graphPlan)
           
 void setIndex(int index)
          Sets the element index this GraphNode instance refereces to be the given index value.
If the index or key is already set for this GraphNode instance, and IllegalStateException will be thrown.
 void setKey(java.lang.Object key)
          Sets the element key this GraphNode instance refereces to be the given key value.
If the index or key is already set for this GraphNode instance, and IllegalStateException will be thrown.
 void setLiteral(boolean literal)
           
protected  void setOriginNode(GraphNode originNode)
           
protected  void setParentNode(GraphNode parentNode)
           
 void setReadOnly(boolean isReadOnly)
          Marks this node as a read-only node in the graph it represents.
 void setReferenceOnly(boolean referenceOnly)
           
 void setTypeName(java.lang.String typeName)
          Sets the Class typeName this GraphNode instance represents.
Note, this value should not be null, but is currently not enforced.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NO_INDEX

public static final int NO_INDEX
No index value.

See Also:
Constant Field Values

NO_KEY

public static final java.lang.Object NO_KEY
No key value.

Constructor Detail

GraphNode

public GraphNode()

GraphNode

public GraphNode(java.lang.Class type)
Creates an origin node.

Parameters:
type -

GraphNode

public GraphNode(java.lang.String typeName)
Creates an origin node.

Parameters:
typeName -

GraphNode

public GraphNode(java.lang.String typeName,
                 java.lang.String edge,
                 boolean isReadOnly,
                 boolean isReferenceOnly)

GraphNode

public GraphNode(java.lang.String typeName,
                 java.lang.String edge,
                 int index,
                 boolean isReadOnly,
                 boolean isReferenceOnly)

GraphNode

public GraphNode(java.lang.String typeName,
                 java.lang.String edge,
                 java.lang.Object key,
                 boolean isReadOnly,
                 boolean isReferenceOnly)

GraphNode

public GraphNode(java.lang.String typeName,
                 java.lang.String edge,
                 boolean isReadOnly,
                 boolean isReferenceOnly,
                 boolean isLiteral)

GraphNode

public GraphNode(java.lang.String typeName,
                 java.lang.String edge,
                 int index,
                 boolean isReadOnly,
                 boolean isReferenceOnly,
                 boolean isLiteral)

GraphNode

public GraphNode(java.lang.String typeName,
                 java.lang.String edge,
                 java.lang.Object key,
                 boolean isReadOnly,
                 boolean isReferenceOnly,
                 boolean isLiteral)

GraphNode

public GraphNode(java.lang.String typeName,
                 java.lang.String edge)

GraphNode

public GraphNode(java.lang.String typeName,
                 java.lang.String edge,
                 int index)

GraphNode

public GraphNode(java.lang.String typeName,
                 java.lang.String edge,
                 java.lang.Object key)
Method Detail

isLiteral

public boolean isLiteral()

setLiteral

public void setLiteral(boolean literal)

isOrigin

public boolean isOrigin()
Returns:
true if this GraphNode instance is the node tree origin

setOriginNode

protected void setOriginNode(GraphNode originNode)

getOriginNode

public GraphNode getOriginNode()
Returns:
the GraphNode instance that is the node tree origin, null if this instance is the origin

getOriginNodeOrThis

protected GraphNode getOriginNodeOrThis()
Returns:
the GraphNode instance that is the node tree origin, or this if this instance is the origin

setGraphPlan

protected void setGraphPlan(GraphPlan graphPlan)

getGraphPlan

protected GraphPlan getGraphPlan()

isNodeSet

public boolean isNodeSet()
Returns:
true if this instance is a GraphNodeSet

setParentNode

protected void setParentNode(GraphNode parentNode)
Parameters:
parentNode -

getParentNode

public GraphNode getParentNode()
Returns:
the parent of this GraphNode instance

getAllParentNodes

public java.util.List getAllParentNodes()
Returns new List of all the parents of this GraphNode instance, up to and including the origin node.

Returns:
a new List of all the parents of this GraphNode instance

getAllNodes

public java.util.List getAllNodes()
Returns a List of all GraphNode instances in this node tree, including this GraphNode instance.
The List will include all GraphNodeSet instances, but not the GraphNode peer instances in the GraphNodeSet but will include the children of the peer node instances.

Returns:
a List of all GraphNodes in the node tree, including this GraphNode instance

getNodePath

public java.util.List getNodePath()
Returns new List containing this GraphNode instance and all the parents of this GraphNode instance, up to and including the origin GraphNode instance.

Returns:
a new List of all parent nodes ended with this GraphNode instance

getDepth

public int getDepth()
The origin node has a depth of zero.

Returns:
the distance this GraphNode is from the origin node

isContainer

public boolean isContainer()
Returns:
true if this GraphNode instance references a container (List or Map)

isContained

public boolean isContained()
Returns:
true if this GraphNode instance references an element in a container

isList

public boolean isList()
Returns:
true if this GraphNode instance references a List or an element in a List

isMap

public boolean isMap()
Returns:
true if this GraphNode instance references a Map or an element in a Map

resetIndex

public void resetIndex(int index)
Forces the element index this GraphNode instance refereces to be the given index value.
This method is intended for use by internal tools.

Parameters:
index -

setIndex

public void setIndex(int index)
Sets the element index this GraphNode instance refereces to be the given index value.
If the index or key is already set for this GraphNode instance, and IllegalStateException will be thrown.

Parameters:
index -

getIndex

public int getIndex()
Returns:
the element index this GraphNode instance references, NO_INDEX (-1) if no index is referenced

resetKey

public void resetKey(java.lang.Object key)
Forces the element key this GraphNode instance refereces to be the given key value.
This method is intended for use by internal tools.

Parameters:
key -

setKey

public void setKey(java.lang.Object key)
Sets the element key this GraphNode instance refereces to be the given key value.
If the index or key is already set for this GraphNode instance, and IllegalStateException will be thrown.

Parameters:
key -

getKey

public java.lang.Object getKey()
Returns:
the element key this GraphNode instance references, NO_KEY (null) if no key is referenced

setTypeName

public void setTypeName(java.lang.String typeName)
Sets the Class typeName this GraphNode instance represents.
Note, this value should not be null, but is currently not enforced.

Parameters:
typeName -

getTypeName

public java.lang.String getTypeName()
Returns:
the Class typeName this GraphNode instance represents

setEdge

public void setEdge(java.lang.String fullEdge)
Sets the fullEdge the GraphNode instance represents.

Parameters:
fullEdge -

getEdge

public java.lang.String getEdge()
Returns:
the local edge this GraphNode instance references, not the full edge

getFullEdge

public java.lang.String getFullEdge()
Returns the full edge, of the forms:

Returns:
the full edge this GraphNode instance references

setReadOnly

public void setReadOnly(boolean isReadOnly)
Marks this node as a read-only node in the graph it represents.

Parameters:
isReadOnly -

isReadOnly

public boolean isReadOnly()
Returns:
true if this GraphNode instance represents a read-only node

isReferenceOnly

public boolean isReferenceOnly()
Marks this node as a reference-only node in the graph it represents.

Returns:

setReferenceOnly

public void setReferenceOnly(boolean referenceOnly)
Parameters:
referenceOnly - true if this GraphNode instance represents a reference-only node

addChildNode

public GraphNode addChildNode(GraphNode childNode)
Adds the given GraphNode instance to the graph node tree this GraphNode instance is a member of.
Note that GraphNode instances may only belong to one tree, and may only be added to a tree once. They may not be re-used in a different position.

Parameters:
childNode -
Returns:
Throws:
java.lang.IllegalStateException - if the given GraphNode instance has already been added to a parent node

removeChildNode

public void removeChildNode(GraphNode childNode)
Removes the given child GraphNode instance from the graph node tree this GraphNode instance is a member of.
The removed childNode may be re-used.

Parameters:
childNode -

findChildNodeWith

public GraphNode findChildNodeWith(java.lang.String fullEdge)
Searches for an immediate child GraphNode instance with the given fullEdge value.

Parameters:
fullEdge -
Returns:
null if not GraphNode instance is found

findChildNodeWith

public GraphNode findChildNodeWith(java.lang.String edge,
                                   boolean isFullEdge)

getChildren

public java.util.List getChildren()
Returns:
a List of all the immediate child GraphNode instances registered with the GraphNode instance

hasChildren

public boolean hasChildren()
Returns:
true if there are child GraphNode instances registered with this GraphNode instance

clone

public java.lang.Object clone()
                       throws java.lang.CloneNotSupportedException
Throws:
java.lang.CloneNotSupportedException

cloneShallow

public GraphNode cloneShallow()
Returns:
a copy of this GraphNode instance, except for its child GraphNode instances


Copyright (C) 2002 Vinculum Technologies, Inc. All Rights Reserved.