com.metamatrix.common.tree.basic
Class BasicTreeNodeEditor

java.lang.Object
  extended by com.metamatrix.common.tree.basic.BasicTreeNodeEditor
All Implemented Interfaces:
PropertiedObjectEditor, PropertyAccessPolicy, UserTransactionFactory, TreeNodeEditor

public class BasicTreeNodeEditor
extends java.lang.Object
implements TreeNodeEditor


Field Summary
 
Fields inherited from interface com.metamatrix.common.object.PropertiedObjectEditor
NO_VALUE
 
Fields inherited from interface com.metamatrix.common.object.PropertyAccessPolicy
DEFAULT_READ_ONLY_PRIVILEGE
 
Constructor Summary
BasicTreeNodeEditor(ObjectIDFactory idFactory)
          Create an empty property definition object with all defaults.
BasicTreeNodeEditor(ObjectIDFactory idFactory, PropertyAccessPolicy policy)
           
BasicTreeNodeEditor(ObjectIDFactory idFactory, PropertyAccessPolicy policy, UserTransactionFactory txnFactory)
           
BasicTreeNodeEditor(ObjectIDFactory idFactory, UserTransactionFactory txnFactory)
           
 
Method Summary
protected  BasicTreeNode assertBasicTreeNode(PropertiedObject obj)
           
protected  BasicTreeNode cloneBasicTreeNode(BasicTreeNode original, BasicTreeNode newParent, boolean deep)
           
protected  java.lang.Object copyPropertyValue(java.lang.Object value)
           
 TreeNode create(TreeNode parent, ObjectDefinition type)
          Create a new instance of a TreeNode under the specified parent and with the specified type.
 TreeNode create(TreeNode parent, java.lang.String name, ObjectDefinition type)
          Create a new instance of a TreeNode under the specified parent, with the specified type and with the specified name
 UserTransaction createReadTransaction()
          Create a new instance of a UserTransaction that may be used to read information.
 UserTransaction createWriteTransaction()
          Create a new instance of a UserTransaction that may be used to write and/or update information.
 UserTransaction createWriteTransaction(java.lang.Object source)
          Create a new instance of a UserTransaction that may be used to write and/or update information.
 boolean delete(TreeNode node)
          Removes the specified TreeNode instance (and all its children) from its parent.
 java.util.List getAllowedValues(PropertiedObject obj, PropertyDefinition def)
          Get the allowed values for the property on the specified object.
 PropertyDefinition getDescriptionPropertyDefinition(TreeNode obj)
          Filter the specified PropertyDefinition instances and return the first definition that is mapped to "the description" property for the metadata object.
 PropertyDefinition getNamePropertyDefinition(TreeNode obj)
          Filter the specified PropertyDefinition instances and return the first definition that is mapped to "the name" property for the tree node.
 PropertyAccessPolicy getPolicy()
           
 java.util.List getPropertyDefinitions(PropertiedObject obj)
          Obtain the list of PropertyDefinitions that apply to the specified object's type.
 java.lang.Object getValue(PropertiedObject obj, PropertyDefinition def)
          Obtain from the specified PropertiedObject the property value that corresponds to the specified PropertyDefinition.
 boolean isAncestorOf(TreeNode ancestor, TreeNode descendent)
          Determine whether the specified node is a descendent of the given ancestor node.
 boolean isMarked(TreeNode node)
          Return the marked state of the specified node.
 boolean isParentOf(TreeNode parent, TreeNode child)
          Determine whether the specified node is a child of the given parent node.
 boolean isReadOnly(PropertiedObject obj)
          Return whether this editor may be used to set property values on the specified PropertiedObject.
 boolean isReadOnly(PropertiedObject obj, PropertyDefinition def)
           
 boolean isValidValue(PropertiedObject obj, PropertyDefinition def, java.lang.Object value)
          Return whether the specified value is considered valid.
 boolean move(TreeNode original, TreeNode newParent)
          Moves this TreeNode to be a child of the specified new parent.
 boolean move(TreeNode node, TreeNode newParent, int indexInNewParent)
          Moves this TreeNode to be a child at a particular index in the specified new parent.
 boolean moveChild(TreeNode child, int newIndex)
          Moves this TreeNode to the specified location within the ordered list of children for the node's parent.
 TreeNode paste(TreeNode original, TreeNode newParent)
          Creates and places a copy of the specified original TreeNode under the specified new parent.
 TreeNode paste(TreeNode original, TreeNode newParent, boolean deepCopy)
          Creates and places a copy of the specified original TreeNode under the specified new parent.
 TreeNode paste(TreeNode original, TreeNode newParent, boolean deepCopy, boolean forceCopy)
          Creates and places a copy of the specified original TreeNode under the specified new parent.
 boolean rename(TreeNode node, java.lang.String newName)
          Renames this MetaObject to the specified new name.
 void reset(PropertiedObject obj)
           
 void setMarked(TreeNode node, boolean marked)
          Set the marked state of the TreeNode node.
 void setPolicy(PropertyAccessPolicy policy)
           
 void setReadOnly(PropertiedObject obj, boolean readOnly)
           
 void setReadOnly(PropertiedObject obj, PropertyDefinition def, boolean readOnly)
           
 void setValue(PropertiedObject obj, PropertyDefinition def, java.lang.Object value)
          Set on the specified PropertiedObject the value defined by the specified PropertyDefinition.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BasicTreeNodeEditor

public BasicTreeNodeEditor(ObjectIDFactory idFactory,
                           PropertyAccessPolicy policy,
                           UserTransactionFactory txnFactory)

BasicTreeNodeEditor

public BasicTreeNodeEditor(ObjectIDFactory idFactory)
Create an empty property definition object with all defaults.


BasicTreeNodeEditor

public BasicTreeNodeEditor(ObjectIDFactory idFactory,
                           PropertyAccessPolicy policy)

BasicTreeNodeEditor

public BasicTreeNodeEditor(ObjectIDFactory idFactory,
                           UserTransactionFactory txnFactory)
Method Detail

assertBasicTreeNode

protected BasicTreeNode assertBasicTreeNode(PropertiedObject obj)

getPropertyDefinitions

public java.util.List getPropertyDefinitions(PropertiedObject obj)
Obtain the list of PropertyDefinitions that apply to the specified object's type.

Specified by:
getPropertyDefinitions in interface PropertiedObjectEditor
Parameters:
obj - the propertied object for which the PropertyDefinitions are to be obtained; may not be null
Returns:
an unmodifiable list of the PropertyDefinition objects that define the properties for the object; never null but possibly empty
Throws:
java.lang.AssertionError - if obj is null

getAllowedValues

public java.util.List getAllowedValues(PropertiedObject obj,
                                       PropertyDefinition def)
Get the allowed values for the property on the specified object. By default, this implementation simply returns the allowed values in the supplied PropertyDefinition instance.

Specified by:
getAllowedValues in interface PropertiedObjectEditor
Parameters:
obj - the propertied object whose property value is to be obtained; may not be null
def - the reference to the PropertyDefinition describing the property whose value is to be returned; may not be null
Returns:
the unmodifiable list of allowed values for this property, or an empty set if the values do not have to conform to a fixed set.
See Also:
#hasAllowedValues

getValue

public java.lang.Object getValue(PropertiedObject obj,
                                 PropertyDefinition def)
Obtain from the specified PropertiedObject the property value that corresponds to the specified PropertyDefinition. The return type and cardinality (including whether the value may be null) depend upon the PropertyDefinition.

Specified by:
getValue in interface PropertiedObjectEditor
Parameters:
obj - the propertied object whose property value is to be obtained; may not be null
def - the reference to the PropertyDefinition describing the property whose value is to be returned; may not be null
Returns:
the value for the property, which may be an empty collection if the property is multi-valued, or may be null if the multiplicity includes "0", or the NO_VALUE reference if the specified object does not contain the specified PropertyDefinition
Throws:
java.lang.AssertionError - if either of obj or def is null

isValidValue

public boolean isValidValue(PropertiedObject obj,
                            PropertyDefinition def,
                            java.lang.Object value)
Return whether the specified value is considered valid. The value is not valid if the propertied object does not have the specified property definition, or if it does but the value is inconsistent with the requirements of the property definition.

Specified by:
isValidValue in interface PropertiedObjectEditor
Parameters:
obj - the propertied object whose property value is to be validated; may not be null
def - the reference to the PropertyDefinition describing the property whose value is to be validated; may not be null
value - the proposed value for the property, which may be a collection if the property is multi-valued, or may be null if the multiplicity includes "0"
Returns:
true if the value is considered valid, or false otherwise.
Throws:
java.lang.AssertionError - if either of obj or def is null

setValue

public void setValue(PropertiedObject obj,
                     PropertyDefinition def,
                     java.lang.Object value)
Set on the specified PropertiedObject the value defined by the specified PropertyDefinition.

Specified by:
setValue in interface PropertiedObjectEditor
Parameters:
obj - the propertied object whose property value is to be set; may not be null
def - the reference to the PropertyDefinition describing the property whose value is to be changed; may not be null
value - the new value for the property; the cardinality and type must conform PropertyDefinition
Throws:
java.lang.IllegalArgumentException - if the value does not correspond to the PropertyDefinition requirements.
java.lang.AssertionError - if either of obj or def is null
java.lang.RuntimeException - if attempting to update a read-only value.

getPolicy

public PropertyAccessPolicy getPolicy()
Specified by:
getPolicy in interface PropertiedObjectEditor

setPolicy

public void setPolicy(PropertyAccessPolicy policy)
Specified by:
setPolicy in interface PropertiedObjectEditor

isReadOnly

public boolean isReadOnly(PropertiedObject obj)
Description copied from interface: PropertiedObjectEditor
Return whether this editor may be used to set property values on the specified PropertiedObject.

Specified by:
isReadOnly in interface PropertiedObjectEditor
Specified by:
isReadOnly in interface PropertyAccessPolicy
Parameters:
obj - the propertied object; may not be null
Returns:
true if the object may not be modified, or false otherwise.

isReadOnly

public boolean isReadOnly(PropertiedObject obj,
                          PropertyDefinition def)
Specified by:
isReadOnly in interface PropertyAccessPolicy

setReadOnly

public void setReadOnly(PropertiedObject obj,
                        PropertyDefinition def,
                        boolean readOnly)
Specified by:
setReadOnly in interface PropertyAccessPolicy

setReadOnly

public void setReadOnly(PropertiedObject obj,
                        boolean readOnly)
Specified by:
setReadOnly in interface PropertyAccessPolicy

reset

public void reset(PropertiedObject obj)
Specified by:
reset in interface PropertyAccessPolicy

createReadTransaction

public UserTransaction createReadTransaction()
Create a new instance of a UserTransaction that may be used to read information. Read transactions do not have a source object associated with them (since they never directly modify data).

Specified by:
createReadTransaction in interface UserTransactionFactory
Returns:
the new transaction object

createWriteTransaction

public UserTransaction createWriteTransaction()
Create a new instance of a UserTransaction that may be used to write and/or update information. The transaction will not have a source object associated with it.

Specified by:
createWriteTransaction in interface UserTransactionFactory
Returns:
the new transaction object

createWriteTransaction

public UserTransaction createWriteTransaction(java.lang.Object source)
Create a new instance of a UserTransaction that may be used to write and/or update information. The source object will be used for all events that are fired as a result of or as a product of this transaction.

Specified by:
createWriteTransaction in interface UserTransactionFactory
Parameters:
source - the object that is considered to be the source of the transaction; may be null
Returns:
the new transaction object

setMarked

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

Specified by:
setMarked in interface TreeNodeEditor
Parameters:
marked - the marked state of the node.

isMarked

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

Specified by:
isMarked in interface TreeNodeEditor
Returns:
the marked state of the node.

isParentOf

public boolean isParentOf(TreeNode parent,
                          TreeNode child)
Determine whether the specified node is a child of the given parent node.

Specified by:
isParentOf in interface TreeNodeEditor
Returns:
true if the node is a child of the given parent node.

isAncestorOf

public boolean isAncestorOf(TreeNode ancestor,
                            TreeNode descendent)
Determine whether the specified node is a descendent of the given ancestor node.

Specified by:
isAncestorOf in interface TreeNodeEditor
Returns:
true if the node is a descendent of the given ancestor node.

create

public TreeNode create(TreeNode parent,
                       ObjectDefinition type)
Create a new instance of a TreeNode under the specified parent and with the specified type. The name of the new object is created automatically.

Specified by:
create in interface TreeNodeEditor
Parameters:
parent - the MetaObject that is to be the parent of the new metadata object
type - the ObjectDefinition instance that defines the type of metadata object to instantiate.
Returns:
the new instance
Throws:
java.lang.IllegalArgumentException - if the parent and the new MetaObject are not compatible
java.lang.AssertionError - if parent or type is null

create

public TreeNode create(TreeNode parent,
                       java.lang.String name,
                       ObjectDefinition type)
Create a new instance of a TreeNode under the specified parent, with the specified type and with the specified name

Specified by:
create in interface TreeNodeEditor
Parameters:
parent - the MetaObject that is to be the parent of the new metadata object
name - the name for the new object
type - the ObjectDefinition instance that defines the type of metadata object to instantiate.
Returns:
the new instance
Throws:
java.lang.AssertionError - if parent or type is null

delete

public boolean delete(TreeNode node)
Removes the specified TreeNode instance (and all its children) from its parent. After this method is called, the caller is responsible for maintaining the referenced to the specified object (to prevent garbage collection).

Specified by:
delete in interface TreeNodeEditor
Parameters:
obj - the node to be deleted; may not be null
Returns:
true if deletion is successful, or false otherwise.
Throws:
java.lang.AssertionError - if obj is null

paste

public TreeNode paste(TreeNode original,
                      TreeNode newParent,
                      boolean deepCopy)
Creates and places a copy of the specified original TreeNode under the specified new parent. This method does not affect the original TreeNode or its contents.

This methods may be used in conjunction with a reference to an existing TreeNode instance in this or another session to copy TreeNode instances and paste them in this session.

Specified by:
paste in interface TreeNodeEditor
Parameters:
original - the original node to be copied; may not be null
newParent - the nodethat is to be considered the parent of the newly created instances; may not be null
deepCopy - true if this paste operation is to place a deep copy of original, or false if only the original node and its immediate properties are to be pasted.
Returns:
the node that resulted from the paste, or null if the paste failed.
Throws:
java.lang.AssertionError - if either of original or newParent is null

paste

public TreeNode paste(TreeNode original,
                      TreeNode newParent)
Creates and places a copy of the specified original TreeNode under the specified new parent. This method does not affect the original TreeNode or its contents.

This methods may be used in conjunction with a reference to an existing TreeNode instance in this or another session to copy TreeNode instances and paste them in this session.

Parameters:
original - the original node to be copied; may not be null
newParent - the nodethat is to be considered the parent of the newly created instances; may not be null
Returns:
the node that resulted from the paste, or null if the paste failed.
Throws:
java.lang.AssertionError - if either of original or newParent is null

paste

public TreeNode paste(TreeNode original,
                      TreeNode newParent,
                      boolean deepCopy,
                      boolean forceCopy)
Creates and places a copy of the specified original TreeNode under the specified new parent. This method does not affect the original TreeNode or its contents.

This methods may be used in conjunction with a reference to an existing TreeNode instance in this or another session to copy TreeNode instances and paste them in this session.

Parameters:
original - the original node to be copied; may not be null
newParent - the nodethat is to be considered the parent of the newly created instances; may not be null
deepCopy - true if this paste operation is to place a deep copy of original, or false if only the original node and its immediate properties are to be pasted.
forceCopy - if true, ensures that original objects are never reused but always copied; if false, this method may choose whether to create copies or to reuse the original.
Returns:
the node that resulted from the paste, or null if the paste failed.
Throws:
java.lang.AssertionError - if either of original or newParent is null

move

public boolean move(TreeNode original,
                    TreeNode newParent)
Moves this TreeNode to be a child of the specified new parent. The specified object is modified, since it's namespace is changed to be newParent.

This method may be used in conjunction with the delete method of an editor from this or another another session to cut TreeNode instances from the original's session and paste them (or move them) into this session.

Specified by:
move in interface TreeNodeEditor
Parameters:
obj - the node to be moved; may not be null
newParent - the node that is to be considered the parent of the existing instance; may not be null
Returns:
true if this node was moved, or false otherwise.
Throws:
java.lang.AssertionError - if either of obj or newParent is null

move

public boolean move(TreeNode node,
                    TreeNode newParent,
                    int indexInNewParent)
Moves this TreeNode to be a child at a particular index in the specified new parent. The specified object is modified, since it's namespace is changed to be newParent.

This method may be used in conjunction with the delete method of an editor from this or another another session to cut TreeNode instances from the original's session and paste them (or move them) into this session.

Specified by:
move in interface TreeNodeEditor
Parameters:
obj - the node to be moved; may not be null
newParent - the node that is to be considered the parent of the existing instance; may not be null
indexInNewParent - the position that this node will occupy within the ordered list of children for newParent.
Returns:
true if this node was moved, or false otherwise.
Throws:
java.lang.AssertionError - if either of obj or newParent is null
java.lang.IndexOutOfBoundsException - if the index is not within the range 0 <= newIndex < childCount

moveChild

public boolean moveChild(TreeNode child,
                         int newIndex)
Moves this TreeNode to the specified location within the ordered list of children for the node's parent.

Specified by:
moveChild in interface TreeNodeEditor
Parameters:
child - the node to be moved; may not be null
newIndex - the position that this node will occupy within the ordered list of children for the node's parent.
Returns:
true if this node was moved, or false otherwise.
Throws:
java.lang.AssertionError - if either of obj or newParent is null
java.lang.IndexOutOfBoundsException - if the index is not within the range 0 <= newIndex < this.getChildCount()

rename

public boolean rename(TreeNode node,
                      java.lang.String newName)
Renames this MetaObject to the specified new name. This operation will not succeed if there is already a node underneath the parent with the same name as the specified newName.

Specified by:
rename in interface TreeNodeEditor
Parameters:
obj - the node to be renamed; may not be null
newName - the new name for the object; may not be null or zero-length, and must not be used by an existing sibling
Returns:
true if this node was renamed, or false otherwise.
Throws:
java.lang.AssertionError - if either of obj or newName is null, or if newName is zero-length

getNamePropertyDefinition

public PropertyDefinition getNamePropertyDefinition(TreeNode obj)
Filter the specified PropertyDefinition instances and return the first definition that is mapped to "the name" property for the tree node.

Specified by:
getNamePropertyDefinition in interface TreeNodeEditor
Parameters:
obj - the tree node; may not be null
Returns:
the first PropertyDefinition instance found in the list of PropertyDefinition instances that represents the name property for the object, or null if no such PropertyDefinition is found.

getDescriptionPropertyDefinition

public PropertyDefinition getDescriptionPropertyDefinition(TreeNode obj)
Filter the specified PropertyDefinition instances and return the first definition that is mapped to "the description" property for the metadata object.

Parameters:
obj - the tree node; may not be null
Returns:
the first PropertyDefinition instance found in the list of PropertyDefinition instances that represents the description property for the object, or null if no such PropertyDefinition is found.

cloneBasicTreeNode

protected BasicTreeNode cloneBasicTreeNode(BasicTreeNode original,
                                           BasicTreeNode newParent,
                                           boolean deep)

copyPropertyValue

protected java.lang.Object copyPropertyValue(java.lang.Object value)


Copyright © 2009. All Rights Reserved.