com.metamatrix.common.tree.basic
Class BasicTreeNode

java.lang.Object
  extended by com.metamatrix.common.tree.basic.BasicTreeNode
All Implemented Interfaces:
PropertiedObject, TreeNode, java.io.Serializable, java.lang.Comparable
Direct Known Subclasses:
PermissionDataNodeImpl

public class BasicTreeNode
extends java.lang.Object
implements TreeNode, java.io.Serializable

See Also:
Serialized Form

Field Summary
static java.lang.String DELIMITER
           
static char DELIMITER_CHAR
           
 
Constructor Summary
BasicTreeNode(BasicTreeNode parent, java.lang.String name, ObjectDefinition defn, ObjectID guid)
          Construct a new instance by specifying the parent that owns this entity, the name of the instance, the type of the instance and the global UID for the instance.
 
Method Summary
 void add(BasicTreeNode child)
          Insert the node as a child of this node, and place it at the end of this node's list of children.
 void add(BasicTreeNode child, int index)
          Insert the node as a child of this node, and place it at the end of this node's list of children.
protected  void addChild(BasicTreeNode child, ObjectDefinition childType, int index)
           
protected  boolean addChildIsValid(BasicTreeNode child)
          This method is called prior to adding the specified child to this TreeNode allowing any subclass to provide specific behavior if necessary.
protected  java.lang.StringBuffer addFullName(java.lang.StringBuffer sb, java.lang.String delimiter)
          Helper method to build a string of the full name without having to construct a new StringBuffer in each node.
protected  void addMarkedNodesToSet(java.util.Set result)
          Return the set of marked nodes for this view.
protected  boolean areDuplicateChildNamesAllowed()
          This method is used to determine whether two child nodes under a single parent are allowed to have the same name.
protected  BasicTreeNode assertBasicTreeNode(TreeNode obj)
           
 int compareTo(java.lang.Object obj)
          Compares this object to another.
 boolean containsChildWithName(java.lang.String name)
           
protected  java.lang.Object convertTypeToString(java.lang.Object value, PropertyDefinition def)
          hook to allow some PropertyDefinition values to be converted non-string values into Strings before they are set on the PropertiedObject.
protected  void ensureNameIsValid()
          Set the name of the new node (before its been added as a sibling to the nodes in siblings
 boolean equals(java.lang.Object obj)
          Returns true if the specified object is semantically equal to this instance.
 boolean exists()
          Return whether this TreeNode represents an existing metadata entity.
protected  TreeNode find(ObjectID globalUID)
           
 void findLeafNodes(java.util.Set leafNodes)
          Go through the tree and find out the leaf nodes beneath this object.
 boolean findMarkedAndUnmarkedNodes(java.util.Set unmarkedNodes, java.util.Set markedLeafNodes)
          Go through the tree and find out the top-level objects that are not marked and that do not have marked nodes beneath them, and find the leaf-level marked objects.
 void findTopLevelMarkedNodes(java.util.Set markedTopLevelNodes)
          Go through the tree and find out the top-level objects that are not marked and that do not have marked nodes beneath them, and find the leaf-level marked objects.
 TreeNode getChild(java.lang.String name, ObjectDefinition defn, boolean ignoreCase)
          Return the immediate child of this object that has the specified name.
 int getChildCount()
           
 java.util.List getChildren()
          Return the ordered list of children.
 java.util.List getChildren(java.lang.String name, boolean ignoreCase)
          Return the immediate child of this object that has the specified name.
 java.util.Collection getDecendant(java.lang.String pathWithName, boolean ignoreCase)
           
 java.util.Collection getDecendant(java.lang.String pathWithName, java.lang.String delimiter, boolean ignoreCase)
           
protected  java.lang.String getDefaultName()
          This method is used to determine the default name for a node when that node has no name.
protected  PropertyDefinition getDescriptionPropertyDefinition()
          This method is used to determine which, if any, of the property definitions for this object are used to access the description.
protected  java.lang.String getEntityForm()
           
 java.lang.String getFullName()
          Get the actual or programmatic name of this property.
 java.lang.String getFullName(java.lang.String delimiter)
          Get the actual or programmatic name of this property.
 ObjectID getGlobalUID()
           
 int getIndexOfChild(TreeNode child)
           
 java.lang.String getName()
          Get this name of this entity.
protected  PropertyDefinition getNamePropertyDefinition()
          This method is used to determine which, if any, of the property definitions for this object are used to access the name.
 java.lang.String getNamespace()
          Get the actual or programmatic name of this property.
 BasicTreeNode getParent()
          Get the model entity which which is the parent of this entity.
 java.util.Map getProperties()
           
protected  java.util.List getPropertyDefinitions()
          This method is used to determine the property definitions for this object.
 java.lang.Object getPropertyValue(PropertyDefinition propertyDefn)
           
 java.lang.String getSeparator()
          Obtain the character (as a String) that is used to separate names in a path sequence for the abstract path.
 char getSeparatorChar()
          Obtain the character that is used to separate names in a path sequence for the abstract path.
 ObjectDefinition getType()
          Get this type for this entity.
 boolean hasChildren()
          Return true if this node currently does have any children.
 void insert(BasicTreeNode child, int index)
          Insert the node as a child of this node.
 boolean isAncestorOf(TreeNode node)
          Determine whether this handle is an ancestor of the specified handle, The result of this method is equivalent to calling the following, although this method uses a much more efficient algorithm that does not rely upon string comparisons:
 boolean isMarked()
          Return the marked state of the specified node.
 boolean isModified()
          Return whether this node has undergone changes.
 boolean isParentOf(TreeNode node)
          Determine whether this handle is the parent of the specified handle.
protected  boolean isValidNewName(java.lang.String newName)
           
 java.util.Iterator iterator()
           
 void moveChild(BasicTreeNode child, int newIndex)
          Move the child to a new index under the same parent.
 void print(java.io.PrintStream stream)
           
protected  void printInfo(java.io.PrintStream stream)
           
 void remove(BasicTreeNode child)
          Remove from this node the specified child, null the parent reference of the node, and mark the node as non-existant.
 void remove(int index)
          Remove from this node the child specified by the index, null the parent reference of the node, and mark the node as non-existant.
 void removeAll()
          Remove from this node the child specified by the index, null the parent reference of the node, and mark the node as non-existant.
 java.lang.Object removePropertyValue(PropertyDefinition propertyDefn)
           
protected  java.lang.Object resolveTypeFromString(java.lang.Object value, PropertyDefinition def)
          hook to allow some PropertyDefinition values to be converted from String values before they are sent to clients of this Editor.
 void setExists(boolean value)
          Ensure that the existance flag on this instance is set to the specified value.
protected  void setGlobalUID(ObjectID newID)
          Use this with extreme care!!!!
 void setMarked(boolean marked)
          Set the marked state of the TreeNode node.

Default behavior is to mark the whole subtree from this node.
 void setMarked(boolean marked, boolean recursive)
          Set the marked state of the TreeNode node.
 void setModified(boolean modified)
          Set the modified state of the TreeNode node.

Default behavior is to set as modified the whole subtree starting with this node.
 void setModified(boolean modified, boolean recursive)
          Set the modified state of the TreeNode node.
 void setName(java.lang.String newName)
          Set the name of this node.
protected  void setNameOfNode(java.lang.String newName)
           
 java.lang.Object setPropertyValue(PropertyDefinition propertyDefn, java.lang.Object value)
           
 java.lang.String toString()
          Returns a string representing the current state of the object.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DELIMITER_CHAR

public static final char DELIMITER_CHAR
See Also:
Constant Field Values

DELIMITER

public static final java.lang.String DELIMITER
See Also:
Constant Field Values
Constructor Detail

BasicTreeNode

public BasicTreeNode(BasicTreeNode parent,
                     java.lang.String name,
                     ObjectDefinition defn,
                     ObjectID guid)
Construct a new instance by specifying the parent that owns this entity, the name of the instance, the type of the instance and the global UID for the instance. Note: this constructor does NOT verify that the name is valid within the parent's namespace.

Parameters:
parent - the parent that is considered the owning namespace for this instance; may be null if the new instance is to be the root
name - the name for the new entity instance; may be null or zero length if the node name is to be determined
type - the reference to the MetaModelEntity that defines the type of entity; may not be null
guid - the globally-unique identifier for this instance; may not be null
Method Detail

getName

public java.lang.String getName()
Get this name of this entity. The name does not contain the namespace, but is unique within the namespace of the entity.

Specified by:
getName in interface TreeNode
Returns:
the entity's name; never null or zero-length

getFullName

public java.lang.String getFullName()
Get the actual or programmatic name of this property.

Specified by:
getFullName in interface TreeNode
Returns:
the property's name (never null)

getFullName

public java.lang.String getFullName(java.lang.String delimiter)
Get the actual or programmatic name of this property.

Parameters:
delimiter - the string delimiter to use between the names of nodes
Returns:
the property's name (never null)

addFullName

protected java.lang.StringBuffer addFullName(java.lang.StringBuffer sb,
                                             java.lang.String delimiter)
Helper method to build a string of the full name without having to construct a new StringBuffer in each node.

This method is implemented by having the node invoke this method on its parent (so that the parent can add its full name first), and then this node adds the delimiter and its name.

Parameters:
sb - the StringBuffer to which the name of this node should be appended
Returns:
the StringBuffer containing the full name of this node

getNamespace

public java.lang.String getNamespace()
Get the actual or programmatic name of this property.

Specified by:
getNamespace in interface TreeNode
Returns:
the property's name (never null)

getType

public ObjectDefinition getType()
Get this type for this entity.

Specified by:
getType in interface TreeNode
Returns:
the entity's type; never null

exists

public boolean exists()
Return whether this TreeNode represents an existing metadata entity.

This attribute is set to true any time the object is part of a model, and it is set to false whenever the object is removed (deleted) from a model.

Specified by:
exists in interface TreeNode
Returns:
true the entry exists, or false otherwise.

setExists

public void setExists(boolean value)
Ensure that the existance flag on this instance is set to the specified value. If the values are the same, this method simply returns without doing anything. However, if the existance value is different that the desired value, this method sets the existance value on this node and all of its children (recursively).


getSeparatorChar

public char getSeparatorChar()
Obtain the character that is used to separate names in a path sequence for the abstract path. This character is completely dependent upon the implementation.

Specified by:
getSeparatorChar in interface TreeNode
Returns:
the charater used to delimit names in the abstract path.

getSeparator

public java.lang.String getSeparator()
Obtain the character (as a String) that is used to separate names in a path sequence for the abstract path.

Specified by:
getSeparator in interface TreeNode
Returns:
the string containing the charater used to delimit names in the abstract path; never null

equals

public boolean equals(java.lang.Object obj)
Returns true if the specified object is semantically equal to this instance. Note: this method is consistent with compareTo().

Specified by:
equals in interface TreeNode
Overrides:
equals in class java.lang.Object
Parameters:
obj - the object that this instance is to be compared to.
Returns:
whether the object is equal to this object.

compareTo

public int compareTo(java.lang.Object obj)
Compares this object to another. If the specified object is not an instance of the ModelEntity class, then this method throws a ClassCastException (as instances are comparable only to instances of the same class). Note: this method is consistent with equals(), meaning that (compare(x, y)==0) == (x.equals(y)).

Specified by:
compareTo in interface TreeNode
Specified by:
compareTo in interface java.lang.Comparable
Parameters:
obj - the object that this instance is to be compared to; may not be null.
Returns:
a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object, respectively.
Throws:
java.lang.ClassCastException - if the specified object's type prevents it from being compared to this instance.

toString

public java.lang.String toString()
Returns a string representing the current state of the object.

Specified by:
toString in interface TreeNode
Overrides:
toString in class java.lang.Object
Returns:
the string representation of this instance.

getGlobalUID

public ObjectID getGlobalUID()

setGlobalUID

protected void setGlobalUID(ObjectID newID)
Use this with extreme care!!!!


iterator

public java.util.Iterator iterator()

getChildren

public java.util.List getChildren(java.lang.String name,
                                  boolean ignoreCase)
Return the immediate child of this object that has the specified name.

Parameters:
name - the name of the child to find; may not be null or zero-length
ignoreCase - flag specifying true if the names should be compared in a case-insensitive manner, or false if the names should compare in a case-sensitive manner.
Returns:
the list of children with the matching name, or null if no child is found.

getChild

public TreeNode getChild(java.lang.String name,
                         ObjectDefinition defn,
                         boolean ignoreCase)
Return the immediate child of this object that has the specified name.

Parameters:
name - the name of the child to find; may not be null or zero-length
ignoreCase - flag specifying true if the names should be compared in a case-insensitive manner, or false if the names should compare in a case-sensitive manner.
Returns:
the child with the matching name, or null if no child is found.

getIndexOfChild

public int getIndexOfChild(TreeNode child)

getChildren

public java.util.List getChildren()
Return the ordered list of children.


hasChildren

public boolean hasChildren()
Return true if this node currently does have any children.


getChildCount

public int getChildCount()

containsChildWithName

public boolean containsChildWithName(java.lang.String name)

setName

public void setName(java.lang.String newName)
Set the name of this node. Note: this method does NOT verify that the child's name is valid within this namespace


setNameOfNode

protected void setNameOfNode(java.lang.String newName)

assertBasicTreeNode

protected BasicTreeNode assertBasicTreeNode(TreeNode obj)

getParent

public BasicTreeNode getParent()
Get the model entity which which is the parent of this entity.

Returns:
the parent model entity, which may be null if no parent exists.

isParentOf

public boolean isParentOf(TreeNode node)
Determine whether this handle is the parent of the specified handle. The result of this method is equivalent to calling the following, although this method uses a much more efficient algorithm that does not rely upon string comparisons:

return this.getFullName().equals( node.getNamespace() )

Returns:
true if this handle is the namespace of the specified node

isAncestorOf

public boolean isAncestorOf(TreeNode node)
Determine whether this handle is an ancestor of the specified handle, The result of this method is equivalent to calling the following, although this method uses a much more efficient algorithm that does not rely upon string comparisons:

return node.getNamespace().startsWith( this.getFullName() )

Returns:
true if this handle is an ancestor of the specified node

isModified

public boolean isModified()
Return whether this node has undergone changes. The time from which changes are maintained is left to the implementation.

Specified by:
isModified in interface TreeNode
Returns:
true if this TreeNode has changes, or false otherwise.

setModified

public void setModified(boolean modified)
Set the modified state of the TreeNode node.

Default behavior is to set as modified the whole subtree starting with this node.

Parameters:
marked - the marked state of the node.

setModified

public void setModified(boolean modified,
                        boolean recursive)
Set the modified state of the TreeNode node.

Parameters:
modified - the marked state of the node.
recursive - true if the whole subtree starting from this node should be set as modified, or false if only this node is to be set as modified.

isMarked

public boolean isMarked()
Return the marked state of the specified node.

Returns:
the marked state of the node.

setMarked

public void setMarked(boolean marked)
Set the marked state of the TreeNode node.

Default behavior is to mark the whole subtree from this node.

Parameters:
marked - the marked state of the node.

setMarked

public void setMarked(boolean marked,
                      boolean recursive)
Set the marked state of the TreeNode node.

Parameters:
marked - the marked state of the node.
recursive - mark the whole subtree starting from this node.

addMarkedNodesToSet

protected void addMarkedNodesToSet(java.util.Set result)
Return the set of marked nodes for this view.

Parameters:
the - unmodifiable set of marked nodes; never null

findLeafNodes

public void findLeafNodes(java.util.Set leafNodes)
Go through the tree and find out the leaf nodes beneath this object.


findMarkedAndUnmarkedNodes

public boolean findMarkedAndUnmarkedNodes(java.util.Set unmarkedNodes,
                                          java.util.Set markedLeafNodes)
Go through the tree and find out the top-level objects that are not marked and that do not have marked nodes beneath them, and find the leaf-level marked objects.

Returns:
true if there are nodes below this node that are marked

findTopLevelMarkedNodes

public void findTopLevelMarkedNodes(java.util.Set markedTopLevelNodes)
Go through the tree and find out the top-level objects that are not marked and that do not have marked nodes beneath them, and find the leaf-level marked objects.


getDecendant

public java.util.Collection getDecendant(java.lang.String pathWithName,
                                         java.lang.String delimiter,
                                         boolean ignoreCase)

getDecendant

public java.util.Collection getDecendant(java.lang.String pathWithName,
                                         boolean ignoreCase)

remove

public void remove(BasicTreeNode child)
Remove from this node the specified child, null the parent reference of the node, and mark the node as non-existant.

Parameters:
child - the child entity

removeAll

public void removeAll()
Remove from this node the child specified by the index, null the parent reference of the node, and mark the node as non-existant.

Parameters:
index - the index of the child to be removed
Throws:
java.lang.IndexOutOfBoundsException - if the index is not within the range 0 <= newIndex < this.getChildCount()

remove

public void remove(int index)
Remove from this node the child specified by the index, null the parent reference of the node, and mark the node as non-existant.

Parameters:
index - the index of the child to be removed
Throws:
java.lang.IndexOutOfBoundsException - if the index is not within the range 0 <= newIndex < this.getChildCount()

moveChild

public void moveChild(BasicTreeNode child,
                      int newIndex)
Move the child to a new index under the same parent.

Parameters:
child - the child entity
newIndex - the location
Throws:
java.lang.IndexOutOfBoundsException - if the index is not within the range 0 <= newIndex < this.getChildCount()

insert

public void insert(BasicTreeNode child,
                   int index)
Insert the node as a child of this node. If the child already has a parent, this method removes the child from that parent. Note: this method does NOT verify that the child's name is valid within this namespace

Parameters:
child - the child entity
newIndex - the location
Throws:
java.lang.IndexOutOfBoundsException - if the index is not within the range 0 <= newIndex <= this.getChildCount()

add

public void add(BasicTreeNode child)
Insert the node as a child of this node, and place it at the end of this node's list of children. If the child already has a parent, this method removes the child from that parent.

Note: this method does NOT verify that the child's name is valid within this namespace

Parameters:
child - the child entity

add

public void add(BasicTreeNode child,
                int index)
Insert the node as a child of this node, and place it at the end of this node's list of children. If the child already has a parent, this method removes the child from that parent.

Note: this method does NOT verify that the child's name is valid within this namespace

Parameters:
child - the child entity

addChild

protected void addChild(BasicTreeNode child,
                        ObjectDefinition childType,
                        int index)

getPropertyValue

public java.lang.Object getPropertyValue(PropertyDefinition propertyDefn)

setPropertyValue

public java.lang.Object setPropertyValue(PropertyDefinition propertyDefn,
                                         java.lang.Object value)

resolveTypeFromString

protected java.lang.Object resolveTypeFromString(java.lang.Object value,
                                                 PropertyDefinition def)
hook to allow some PropertyDefinition values to be converted from String values before they are sent to clients of this Editor. Subclasses may override this method to convert custom types.


convertTypeToString

protected java.lang.Object convertTypeToString(java.lang.Object value,
                                               PropertyDefinition def)
hook to allow some PropertyDefinition values to be converted non-string values into Strings before they are set on the PropertiedObject. Subclasses may override this method to convert custom types.


removePropertyValue

public java.lang.Object removePropertyValue(PropertyDefinition propertyDefn)

getProperties

public java.util.Map getProperties()

print

public void print(java.io.PrintStream stream)

getEntityForm

protected java.lang.String getEntityForm()

printInfo

protected void printInfo(java.io.PrintStream stream)

find

protected TreeNode find(ObjectID globalUID)

getPropertyDefinitions

protected java.util.List getPropertyDefinitions()
This method is used to determine the property definitions for this object. By default, this method returns an empty list.


getNamePropertyDefinition

protected PropertyDefinition getNamePropertyDefinition()
This method is used to determine which, if any, of the property definitions for this object are used to access the name. By default, this method returns null, meaning there is no name property definition.


getDescriptionPropertyDefinition

protected PropertyDefinition getDescriptionPropertyDefinition()
This method is used to determine which, if any, of the property definitions for this object are used to access the description. By default, this method returns null, meaning there is no description property definition.


areDuplicateChildNamesAllowed

protected boolean areDuplicateChildNamesAllowed()
This method is used to determine whether two child nodes under a single parent are allowed to have the same name. By default, this method returns true.


getDefaultName

protected java.lang.String getDefaultName()
This method is used to determine the default name for a node when that node has no name. By default, this method returns the name of the node's type.


isValidNewName

protected boolean isValidNewName(java.lang.String newName)

addChildIsValid

protected boolean addChildIsValid(BasicTreeNode child)
This method is called prior to adding the specified child to this TreeNode allowing any subclass to provide specific behavior if necessary. This implementation returns true by default.


ensureNameIsValid

protected void ensureNameIsValid()
Set the name of the new node (before its been added as a sibling to the nodes in siblings



Copyright © 2009. All Rights Reserved.