com.metamatrix.common.tree.directory
Class FileSystemEntryEditor

java.lang.Object
  extended by com.metamatrix.common.tree.directory.FileSystemEntryEditor
All Implemented Interfaces:
PropertiedObjectEditor, PropertyAccessPolicy, UserTransactionFactory, DirectoryEntryEditor, TreeNodeEditor

public class FileSystemEntryEditor
extends java.lang.Object
implements DirectoryEntryEditor

This interface defines a view of a hierarchy of TreeNode instances.


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
protected FileSystemEntryEditor(FileSystemView view)
           
 
Method Summary
protected  void assertDescendentOfRoot(TreeNode descendent)
           
protected  FileSystemEntry assertFileSystemEntry(PropertiedObject obj)
           
protected  FileSystemEntry assertFileSystemEntry(TreeNode obj)
           
 TreeNode copy(TreeNode node, TreeNode newParent)
          Copy this TreeNode as a child of the specified new parent.
 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.
protected  TreeNode getActualParent(TreeNode possibleParent)
           
 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.
protected  java.lang.String getNewFileName()
           
protected  java.lang.String getNewFolderName()
           
 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.
protected  FileSystemView getView()
           
 boolean isAncestorOf(TreeNode ancestor, TreeNode descendent)
          Determine whether the specified node is a descendent of the given ancestor node.
 boolean isMarked(TreeNode entry)
          Return the marked state of the specified entry.
 boolean isNameValid(java.lang.String newName)
          Determine whether the specified name is valid for a file or folder on the current file system.
 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 makeExist(DirectoryEntry entry)
          Check for the existance of the specified entry, and creates an underlying resource for the entry if one does not exist.
 boolean move(TreeNode node, 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, boolean deepCopy)
          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 TreeNode to the specified new name.
 void reset(PropertiedObject obj)
           
 void setMarked(TreeNode entry, boolean marked)
          Set the marked state of the TreeNode entry.
 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

FileSystemEntryEditor

protected FileSystemEntryEditor(FileSystemView view)
Method Detail

getView

protected FileSystemView getView()

getActualParent

protected TreeNode getActualParent(TreeNode possibleParent)

setMarked

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

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

isMarked

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

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

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.

The resulting node will not exist (see makeExist())

Specified by:
create in interface TreeNodeEditor
Parameters:
parent - the TreeNode that is to be the parent of the new tree node object
type - the ObjectDefinition instance that defines the type of tree node object to instantiate.
Returns:
the new instance or null if the new instance could not be created.
Throws:
java.lang.IllegalArgumentException - if the parent and the new TreeNode 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

The resulting node will not exist (see makeExist())

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

makeExist

public boolean makeExist(DirectoryEntry entry)
Check for the existance of the specified entry, and creates an underlying resource for the entry if one does not exist.

Specified by:
makeExist in interface DirectoryEntryEditor
Parameters:
obj - the node to be deleted; may not be null
Returns:
true if the entry was successfully created (made to exist); false if the entry already exists or if the entry could not be created
Throws:
java.lang.AssertionError - if obj 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:
true if this paste was successful, or false otherwise.
Throws:
java.lang.AssertionError - if either of original or newParent is null

move

public boolean move(TreeNode node,
                    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

copy

public TreeNode copy(TreeNode node,
                     TreeNode newParent)
Copy this TreeNode as a child of the specified new parent.

Parameters:
obj - the node to be copied; may not be null and must exist
newParent - the node that is to be considered the parent of the copied instance; may not be null
Returns:
a reference to the new TreeNode instance or null if the copy operation was unsuccessful.
Throws:
java.lang.AssertionError - if either of obj or newParent is null

rename

public boolean rename(TreeNode node,
                      java.lang.String newName)
Renames this TreeNode to the specified new name. If this entry represents an existing resource, the underlying resource is changed.

Specified by:
rename in interface TreeNodeEditor
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 entry was renamed, or false otherwise.

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

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.

Specified by:
getDescriptionPropertyDefinition in interface DirectoryEntryEditor
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.

isNameValid

public boolean isNameValid(java.lang.String newName)
Determine whether the specified name is valid for a file or folder on the current file system.

Specified by:
isNameValid in interface DirectoryEntryEditor
Parameters:
newName - the new name to be checked
Returns:
true if the name is null or contains no invalid characters for a folder or file, or false otherwise

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 a 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

setPolicy

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

getPolicy

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

isReadOnly

public boolean isReadOnly(PropertiedObject obj)
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.
Throws:
java.lang.AssertionError - if obj is null

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

assertFileSystemEntry

protected FileSystemEntry assertFileSystemEntry(TreeNode obj)

assertFileSystemEntry

protected FileSystemEntry assertFileSystemEntry(PropertiedObject obj)

assertDescendentOfRoot

protected void assertDescendentOfRoot(TreeNode descendent)

getNewFolderName

protected java.lang.String getNewFolderName()

getNewFileName

protected java.lang.String getNewFileName()


Copyright © 2009. All Rights Reserved.