com.metamatrix.common.tree.directory
Class FileSystemEntry

java.lang.Object
  extended by com.metamatrix.common.tree.directory.FileSystemEntry
All Implemented Interfaces:
PropertiedObject, DirectoryEntry, TreeNode, java.lang.Comparable

public class FileSystemEntry
extends java.lang.Object
implements DirectoryEntry

This class represents a single resource on a hierarchical system, such as a file system.


Field Summary
 
Fields inherited from interface com.metamatrix.common.tree.directory.DirectoryEntry
TYPE_FILE, TYPE_FOLDER
 
Constructor Summary
  FileSystemEntry(java.io.File file)
           
protected FileSystemEntry(java.io.File file, ObjectDefinition type)
           
 
Method Summary
 boolean canRead()
          Return whether it is possible to read from this DirectoryEntry, and whether an input stream can be obtained for this entry.
 boolean canWrite()
          Return whether it is possible to write to this DirectoryEntry, and whether an output stream can be obtained for this entry.
 int compareTo(java.lang.Object obj)
          Compares this object to another.
protected  TreeNode copy(FileSystemEntry newParent)
          Creates a copy of this DirectoryEntry under the specified folder.
 boolean equals(java.lang.Object obj)
          Returns true if the specified object is semantically equal to this instance.
 boolean exists()
          Return whether this DirectoryEntry represents an existing resource.
 java.lang.String getAbsoluteSeparator()
          Obtain the character (as a String) that is used to separate names in a path sequence for the abstract path.
 char getAbsoluteSeparatorChar()
          Obtain the character that is used to separate names in a path sequence for the absolute path.
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.io.File getFile()
           
 java.lang.String getFullName()
          Obtain the full name of the DirectoryEntry which is unique within the DirectoryEntryView.
 java.io.InputStream getInputStream()
          If this DirectoryEntry is readable, then return an InputStream instance to the resource represented by this entry.
 java.util.Date getLastModifiedDate()
          Return the last modification time property value
 java.lang.String getName()
          Obtain the name of this DirectoryEntry.
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()
          Obtain the namespace to which this DirectoryEntry belongs.
 java.io.OutputStream getOutputStream()
          If this DirectoryEntry is writable, then return an OutputStream instance to the resource represented by this entry.
 java.lang.String getParentFolderPath()
          Helper method to find the path for the parent folder.
protected static java.util.List getPropertyDefinitionList()
           
protected  java.util.List getPropertyDefinitions()
          Get the definitions of the properties for the DirectoryEntry instances returned from this view.
 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()
          Determine the ObjectDefinition type of this DirectoryEntry.
protected  java.lang.Object getValue(PropertyDefinition def)
          Return the value for this objects's property that corresponds to the specified PropertyDefinition.
 java.util.zip.ZipFile getZipFile()
          Create a ZipFile instance if the entry represents a zip file
protected  boolean hasChildWithName(java.lang.String name)
           
 int hashCode()
          Returns the hash code value for this object.
 boolean isEmpty()
           
 boolean isFile()
           
 boolean isFolder()
          Determine whether this DirectoryEntry is of type FolderDefinition, meaning it represents a container that may have children.
protected  boolean isMarked()
          Return the marked state of the specified entry.
 boolean isModified()
          Return whether this node has undergone changes.
 boolean isReadOnly()
          Return whether this object is read only and may not be modified.
protected  boolean isValidValue(PropertyDefinition definition, java.lang.Object value)
           
 boolean loadPreview()
          Load property values associated with this DirectoryEntry and return whether the preview properties are now available.
protected  boolean loadProperties()
          Load the properties for the file.
protected  boolean move(FileSystemEntry newParent)
          Moves this DirectoryEntry under the specified folder.
protected  boolean renameTo(java.lang.String newName)
          Renames this DirectoryEntry to the specified new name.
 boolean setLastModifiedDate(java.util.Date date)
          Set the last modification time property value
protected  void setMarked(boolean marked)
          Set the marked state of the TreeNode entry.
protected  void setValue(PropertyDefinition def, java.lang.Object value)
          Set this object's value for the property defined by the specified PropertyDefinition.
 java.lang.String toString()
          Return the string form of this DirectoryEntry.
 java.net.URL toURL()
          Converts this abstract pathname into a URL.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

FileSystemEntry

public FileSystemEntry(java.io.File file)
                throws java.io.IOException
Throws:
java.io.IOException

FileSystemEntry

protected FileSystemEntry(java.io.File file,
                          ObjectDefinition type)
                   throws java.io.IOException
Throws:
java.io.IOException
Method Detail

getFile

protected java.io.File getFile()

getPropertyDefinitionList

protected static java.util.List getPropertyDefinitionList()

setMarked

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

Parameters:
marked - the marked state of the entry.

isMarked

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

Returns:
the marked state of the entry.

getPropertyDefinitions

protected java.util.List getPropertyDefinitions()
Get the definitions of the properties for the DirectoryEntry instances returned from this view.

Returns:
the unmodifiable set or PropertyDefinition instances; never null

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.


canWrite

public boolean canWrite()
Return whether it is possible to write to this DirectoryEntry, and whether an output stream can be obtained for this entry. This method may return true even if this entry does not exist (i.e., exists() returns true).

Specified by:
canWrite in interface DirectoryEntry
Returns:
true if writing is possible, as well as whether an OutputStream instance can be obtained by calling the getOutputStream() method.

canRead

public boolean canRead()
Return whether it is possible to read from this DirectoryEntry, and whether an input stream can be obtained for this entry. This method always returns false if this entry does not exist (i.e., exists() returns false).

Specified by:
canRead in interface DirectoryEntry
Returns:
true if reading is possible, as well as whether an InputStream instance can be obtained by calling the getInputStream() method.

getParentFolderPath

public java.lang.String getParentFolderPath()
Helper method to find the path for the parent folder. If this file is a folder, return the path for this file.

Returns:
String path for parent folder

isValidValue

protected boolean isValidValue(PropertyDefinition definition,
                               java.lang.Object value)

exists

public boolean exists()
Return whether this DirectoryEntry represents an existing resource.

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

getName

public java.lang.String getName()
Obtain the name of this DirectoryEntry.

Specified by:
getName in interface TreeNode
Returns:
the name of this entry; never null

getFullName

public java.lang.String getFullName()
Obtain the full name of the DirectoryEntry which is unique within the DirectoryEntryView. The full name is the concatenation of the namespace, separator, and name representing the abstract path for this DirectoryEntry.

Specified by:
getFullName in interface TreeNode
Returns:
the fully qualified name of this entry; never null

getNamespace

public java.lang.String getNamespace()
Obtain the namespace to which this DirectoryEntry belongs. The separator character is used between each of the components of the namespace. The namespace for a DirectoryEntry represents the absolute path minus the entry name.

Specified by:
getNamespace in interface TreeNode
Returns:
the string that represents the namespace of this entry; never null

getAbsoluteSeparatorChar

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

Returns:
the charater used to delimit names in the absolute path.

getAbsoluteSeparator

public java.lang.String getAbsoluteSeparator()
Obtain the character (as a String) that is used to separate names in a path sequence for the abstract path. This character is completely dependent upon the implementation.

Returns:
the string containing the charater used to delimit names in the abstract path; never null

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

loadPreview

public boolean loadPreview()
Load property values associated with this DirectoryEntry and return whether the preview properties are now available.

Specified by:
loadPreview in interface DirectoryEntry
Returns:
if the properties have been loaded.

getInputStream

public java.io.InputStream getInputStream()
                                   throws java.io.IOException
If this DirectoryEntry is readable, then return an InputStream instance to the resource represented by this entry.

Specified by:
getInputStream in interface DirectoryEntry
Returns:
the InputStream for this entry.
Throws:
java.lang.AssertionError - if this method is called on a DirectoryEntry for which canRead() returns false.
java.io.IOException - if there was an error creating the stream

getOutputStream

public java.io.OutputStream getOutputStream()
                                     throws java.io.IOException
If this DirectoryEntry is writable, then return an OutputStream instance to the resource represented by this entry.

Specified by:
getOutputStream in interface DirectoryEntry
Returns:
the OutputStream for this entry.
Throws:
java.lang.AssertionError - if this method is called on a DirectoryEntry for which canWrite() returns false.
java.io.IOException - if there was an error creating the stream

isFolder

public boolean isFolder()
Determine whether this DirectoryEntry is of type FolderDefinition, meaning it represents a container that may have children.

Returns:
true if getType() returns FolderDefinition, or false otherwise.

isFile

public boolean isFile()

isEmpty

public boolean isEmpty()

getType

public ObjectDefinition getType()
Determine the ObjectDefinition type of this DirectoryEntry.

Specified by:
getType in interface TreeNode
Returns:
either FolderDefinition or FileDefinition.

renameTo

protected boolean renameTo(java.lang.String newName)
Renames this DirectoryEntry to the specified new name. If this entry represents an existing resource, the underlying resource is changed.

Returns:
true if this entry was renamed, or false otherwise.

move

protected boolean move(FileSystemEntry newParent)
Moves this DirectoryEntry under the specified folder. If this entry represents an existing resource, the underlying resource is changed.

Returns:
true if this entry was moved, or false otherwise.

copy

protected TreeNode copy(FileSystemEntry newParent)
Creates a copy of this DirectoryEntry under the specified folder. If this entry represents an existing resource, the underlying resource is copied.

Returns:
a reference to the copied entry or null if the copy operation was not successful.

toURL

public java.net.URL toURL()
                   throws java.net.MalformedURLException
Converts this abstract pathname into a URL. The exact form of the URL is dependent upon the implementation. If it can be determined that the file denoted by this abstract pathname is a directory, then the resulting URL will end with a slash.

Specified by:
toURL in interface DirectoryEntry
Returns:
the URL for this DirectoryEntry.
Throws:
java.net.MalformedURLException - if the URL is malformed.

compareTo

public int compareTo(java.lang.Object obj)
Compares this object to another. If the specified object is an instance of the DirectoryEntry class, then this method compares the contents; otherwise, it 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.
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.

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.

hashCode

public int hashCode()
Returns the hash code value for this object.

Overrides:
hashCode in class java.lang.Object
Returns:
a hash code value for this object.

toString

public java.lang.String toString()
Return the string form of this DirectoryEntry.

Specified by:
toString in interface TreeNode
Overrides:
toString in class java.lang.Object
Returns:
the stringified abstract path, equivalent to getPath

loadProperties

protected boolean loadProperties()
Load the properties for the file. Return whether the file's modification time has changed since the last time this method was called.

Returns:
true if the file has been modified since the last time this method was called.

hasChildWithName

protected boolean hasChildWithName(java.lang.String name)

setValue

protected void setValue(PropertyDefinition def,
                        java.lang.Object value)
Set this object's value for the property defined by the specified PropertyDefinition.

Parameters:
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.AssertionError - if the property definition reference is null, or if the object is read only.
java.lang.IllegalArgumentException - if the value does not correspond to the PropertyDefinition requirements.

getValue

protected java.lang.Object getValue(PropertyDefinition def)
Return the value for this objects's property that corresponds to the specified PropertyDefinition. The return type and cardinality depend upon the PropertyDefinition.

Parameters:
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"
Throws:
java.lang.AssertionError - if the property definition reference is null

isReadOnly

public boolean isReadOnly()
Return whether this object is read only and may not be modified.

Returns:
true if this object may not be modified, or false otherwise.

isModified

public boolean isModified()
Return whether this node has undergone changes. This method always returns false.

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

getLastModifiedDate

public java.util.Date getLastModifiedDate()
Return the last modification time property value

Returns:
the date for the last modification to the file; never null

setLastModifiedDate

public boolean setLastModifiedDate(java.util.Date date)
Set the last modification time property value

Returns:
true if the last modification time is set successfully, false otherwise.

getZipFile

public java.util.zip.ZipFile getZipFile()
                                 throws java.io.IOException
Create a ZipFile instance if the entry represents a zip file

Returns:
a ZipFile instance. null if the entry is a folder or the file size is 0.
Throws:
java.lang.AssertionError - if this method is called on a DirectoryEntry for which canRead() returns false.
java.io.IOException - if there was an error creating the ZipFile.


Copyright © 2009. All Rights Reserved.