org.itr_rescue.dataGuard.localFileSystem
Class JFMFile

java.lang.Object
  extended by org.itr_rescue.dataGuard.localFileSystem.JFMFile
All Implemented Interfaces:
java.lang.Comparable
Direct Known Subclasses:
JFMLocalFile

public abstract class JFMFile
extends java.lang.Object
implements java.lang.Comparable

This class is the base class of an File object. It is supposed to be implemented by every filesystem implementation. The methods implemented by this class are very similar to those offered by the java.io.File class found in the JDK. Even the comments are the same. Why? Because, IMHO, java.io.File represents a very good abstractisation of an file object but I can't use it, because of the way its implemented. Or ... I haven't found a way to use it yet. If somebody will point me to the proper documentation, i will be more than happy to study it, to see how can I improve my skills.

Author:
sergiu

Field Summary
protected  java.lang.Object data
          This object holds the data required for the implementing file to initialize itself.
protected  java.lang.String displayName
          This parameter, if setted to a different value than null determines what the toString() method will return
protected  boolean marked
          This parameter is set to true when the file is marked in the view.
protected  java.util.Hashtable<java.lang.String,java.lang.String> multiPart
          This parameter contains the id of each file which this file has been splitted.
 
Constructor Summary
JFMFile(java.lang.Object data)
          Constructor.
 
Method Summary
abstract  boolean canRead()
          Tests whether the application can read the file denoted by the abstract pathname.
abstract  boolean canWrite()
          Tests whether the application can modify to the file denoted by the abstract pathname.
abstract  int compareTo(JFMFile pathname)
          Compares two abstract pathnames lexicographically.
 int compareTo(java.lang.Object o)
          Compares this abstract pathname to another object.
abstract  JFMFile createFile(java.lang.String name)
          Creates the file named by the abstract pathname denoted by the parameter.
abstract  boolean delete()
          Deletes the file or directory denoted by the abstract pathname.
abstract  boolean equals(java.lang.Object obj)
          Tests this abstract pathname for equality with the given object.
abstract  boolean exists()
          Tests whether the file or directory denoted by the abstract pathname exists.
abstract  JFMFile getAbsoluteFile()
          Returns the absolute form of this abstract pathname.
abstract  java.lang.String getAbsolutePath()
          Returns the absolute pathname string of this abstract pathname.
abstract  JFMFile getCanonicalFile()
          Returns the canonical form of this abstract pathname.
abstract  java.lang.String getCanonicalPath()
          Returns the canonical pathname string of this abstract pathname.
 java.lang.String getDisplayName()
          Returns the display name
 java.io.File getFile()
          gets the content of the JFMFile if it exists.
abstract  javax.swing.Icon getIcon()
          Returns the filesystem's icon associated with this file, or null if it can't be determined.
abstract  java.io.InputStream getInputStream()
          Returns an InputStream to read from this file, or null if it can't be done (the filesystem doesn't support it)
abstract  java.lang.String getMimeType()
          This method returns the string that represents the mime-type of this file, or null if it can't be determined.
 java.util.Hashtable<java.lang.String,java.lang.String> getMultiPart()
          gets the hashtbale multipart.
abstract  java.lang.String getName()
          This string represents the short name of the file (e.g.
abstract  java.io.OutputStream getOutputStream()
          Returns an OutputStream to write to this file, or null if the write operation isn't supported (or doesn;t make sense from the filesystem's point of view).
abstract  java.lang.String getParent()
          Returns the pathname string of this abstract pathname's parent, or null if this pathname does not name a parent directory.
abstract  JFMFile getParentFile()
          Returns the abstract pathname of this abstract pathname's parent, or null if this pathname does not name a parent directory.
abstract  java.lang.String getPath()
          Converts this abstract pathname into a pathname string.
 JFMFile getRootDriveFile()
          This method returns the root directory of the filesystem of witch the file belongs to.
abstract  java.lang.String getSystemDisplayName()
          Returns the system display name as returned by the filesystem viewer, or null
abstract  int hashCode()
          Computes a hash code for this abstract pathname.
abstract  boolean isAbsolute()
          Tests whether this abstract pathname is absolute.
abstract  boolean isDirectory()
          Tests whether the file denoted by this abstract pathname is a directory.
abstract  boolean isFile()
          Tests whether the file denoted by this abstract pathname is a normal file.
abstract  boolean isHidden()
          Tests whether the file named by this abstract pathname is a hidden file.
 boolean isMarked()
          Returns true if the file has been marked in the view, false otherwise
abstract  long lastModified()
          Returns the time that the file denoted by this abstract pathname was last modified.
abstract  long length()
          Returns the length of the file denoted by this abstract pathname.
abstract  JFMFile[] listFiles()
          Returns an array of abstract pathnames denoting the files in the directory denoted by this abstract pathname.
abstract  JFMFile mkdir(java.lang.String name)
          Creates the directory named by the abstract pathname denoted by the parameter.
 void setDisplayName(java.lang.String displayName)
          Sets the display name
 void setMarked(boolean flag)
          Sets the marked flag.
 void setMultiPart(java.util.Hashtable<java.lang.String,java.lang.String> multiPart)
          Sets the hashtbale multipart.
 java.lang.String toString()
          If getDisplayName() return null it returns the pathname string of this abstract pathname.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

data

protected java.lang.Object data
This object holds the data required for the implementing file to initialize itself. In the case of an local file, the absolute pathname (String) would be required. In the case of other implementing filesystems, it may contain other stuff. Usualy it will be used by the implementing filesystem.


displayName

protected java.lang.String displayName
This parameter, if setted to a different value than null determines what the toString() method will return


marked

protected boolean marked
This parameter is set to true when the file is marked in the view.


multiPart

protected java.util.Hashtable<java.lang.String,java.lang.String> multiPart
This parameter contains the id of each file which this file has been splitted.

Constructor Detail

JFMFile

public JFMFile(java.lang.Object data)
Constructor.

Method Detail

listFiles

public abstract JFMFile[] listFiles()
Returns an array of abstract pathnames denoting the files in the directory denoted by this abstract pathname.

If this abstract pathname does not denote a directory, then this method returns null. Otherwise an array of File objects is returned, one for each file or directory in the directory. Pathnames denoting the directory itself and the directory's parent directory are not included in the result. Each resulting abstract pathname is constructed from this abstract pathname using the File(File, String) constructor. Therefore if this pathname is absolute then each resulting pathname is absolute; if this pathname is relative then each resulting pathname will be relative to the same directory.

There is no guarantee that the name strings in the resulting array will appear in any specific order; they are not, in particular, guaranteed to appear in alphabetical order.

Returns:
An array of abstract pathnames denoting the files and directories in the directory denoted by this abstract pathname. The array will be empty if the directory is empty. Returns null if this abstract pathname does not denote a directory, or if an I/O error occurs.
Throws:
java.lang.SecurityException - If a security manager exists and its SecurityManager.checkRead(java.lang.String) method denies read access to the directory

getInputStream

public abstract java.io.InputStream getInputStream()
Returns an InputStream to read from this file, or null if it can't be done (the filesystem doesn't support it)

Returns:
an InputStream to read from the file

getOutputStream

public abstract java.io.OutputStream getOutputStream()
Returns an OutputStream to write to this file, or null if the write operation isn't supported (or doesn;t make sense from the filesystem's point of view). The way that this is implemented in every filesystem can vary. The call to this method might get the file to be emptied (as in the LocalFileSystem implementation) You have been warned.

Returns:
An OutputStream to write to this file

getName

public abstract java.lang.String getName()
This string represents the short name of the file (e.g. foo.txt)


getParent

public abstract java.lang.String getParent()
Returns the pathname string of this abstract pathname's parent, or null if this pathname does not name a parent directory.

The parent of an abstract pathname consists of the pathname's prefix, if any, and each name in the pathname's name sequence except for the last. If the name sequence is empty then the pathname does not name a parent directory.

Returns:
The pathname string of the parent directory named by this abstract pathname, or null if this pathname does not name a parent

getParentFile

public abstract JFMFile getParentFile()
Returns the abstract pathname of this abstract pathname's parent, or null if this pathname does not name a parent directory.

The parent of an abstract pathname consists of the pathname's prefix, if any, and each name in the pathname's name sequence except for the last. If the name sequence is empty then the pathname does not name a parent directory.

Returns:
The abstract pathname of the parent directory named by this abstract pathname, or null if this pathname does not name a parent

getPath

public abstract java.lang.String getPath()
Converts this abstract pathname into a pathname string. The resulting string uses the default name-separator character to separate the names in the name sequence.

Returns:
The string form of this abstract pathname

isAbsolute

public abstract boolean isAbsolute()
Tests whether this abstract pathname is absolute. The definition of absolute pathname is system dependent. On UNIX systems, a pathname is absolute if its prefix is "/". On Microsoft Windows systems, a pathname is absolute if its prefix is a drive specifier followed by "\\", or if its prefix is "\\". Some other filesystems implementations (FTP, NFS, SMB, etc.) can have their own definition of the absolute pathname, ven though I would recommend sticking to the UNIX definition.

Returns:
true if this abstract pathname is absolute, false otherwise

getAbsolutePath

public abstract java.lang.String getAbsolutePath()
Returns the absolute pathname string of this abstract pathname.

If this abstract pathname is already absolute, then the pathname string is simply returned as if by the getPath() method. If this abstract pathname is the empty abstract pathname then the pathname string of the current user directory, which is named by the system property user.dir, is returned. Otherwise this pathname is resolved in a system-dependent way. On UNIX systems, a relative pathname is made absolute by resolving it against the current user directory. On Microsoft Windows systems, a relative pathname is made absolute by resolving it against the current directory of the drive named by the pathname, if any; if not, it is resolved against the current user directory.

Returns:
The absolute pathname string denoting the same file or directory as this abstract pathname
Throws:
java.lang.SecurityException - If a required system property value cannot be accessed.
See Also:
org.jfm.md.filesystems.JFMFile#isAbsolute()

getAbsoluteFile

public abstract JFMFile getAbsoluteFile()
Returns the absolute form of this abstract pathname.

Returns:
The absolute abstract pathname denoting the same file or directory as this abstract pathname
Throws:
java.lang.SecurityException - If a required system property value cannot be accessed.

getCanonicalPath

public abstract java.lang.String getCanonicalPath()
                                           throws FSException
Returns the canonical pathname string of this abstract pathname.

A canonical pathname is both absolute and unique. The precise definition of canonical form is system-dependent. This method first converts this pathname to absolute form if necessary, as if by invoking the getAbsolutePath() method, and then maps it to its unique form in a system-dependent way. This typically involves removing redundant names such as "." and ".." from the pathname, resolving symbolic links (on UNIX platforms), and converting drive letters to a standard case (on Microsoft Windows platforms).

Every pathname that denotes an existing file or directory has a unique canonical form. Every pathname that denotes a nonexistent file or directory also has a unique canonical form. The canonical form of the pathname of a nonexistent file or directory may be different from the canonical form of the same pathname after the file or directory is created. Similarly, the canonical form of the pathname of an existing file or directory may be different from the canonical form of the same pathname after the file or directory is deleted.

Returns:
The canonical pathname string denoting the same file or directory as this abstract pathname
Throws:
FSException - If an filesystem error occurs, which is possible because the construction of the canonical pathname may require filesystem queries
java.lang.SecurityException - If a required system property value cannot be accessed.

getCanonicalFile

public abstract JFMFile getCanonicalFile()
                                  throws FSException
Returns the canonical form of this abstract pathname.

Returns:
The canonical pathname string denoting the same file or directory as this abstract pathname
Throws:
FSException - If an filesystem error occurs, which is possible because the construction of the canonical pathname may require filesystem queries
java.lang.SecurityException - If a required system property value cannot be accessed.

isDirectory

public abstract boolean isDirectory()
Tests whether the file denoted by this abstract pathname is a directory.

Returns:
true if and only if the file denoted by this abstract pathname exists and is a directory; false otherwise
Throws:
java.lang.SecurityException - If a security manager exists and its SecurityManager.checkRead(java.lang.String) method denies read access to the file

isFile

public abstract boolean isFile()
Tests whether the file denoted by this abstract pathname is a normal file. A file is normal if it is not a directory and, in addition, satisfies other system-dependent criteria. Any non-directory file created by a Java application is guaranteed to be a normal file.

Returns:
true if and only if the file denoted by this abstract pathname exists and is a normal file; false otherwise
Throws:
java.lang.SecurityException - If a security manager exists and its SecurityManager.checkRead(java.lang.String) method denies read access to the file

isHidden

public abstract boolean isHidden()
Tests whether the file named by this abstract pathname is a hidden file. The exact definition of hidden is system-dependent. On UNIX systems, a file is considered to be hidden if its name begins with a period character ('.'). On Microsoft Windows systems, a file is considered to be hidden if it has been marked as such in the filesystem.

Returns:
true if and only if the file denoted by this abstract pathname is hidden according to the conventions of the underlying platform
Throws:
java.lang.SecurityException - If a security manager exists and its SecurityManager.checkRead(java.lang.String) method denies read access to the file

lastModified

public abstract long lastModified()
Returns the time that the file denoted by this abstract pathname was last modified.

Returns:
A long value representing the time the file was last modified, measured in milliseconds since the epoch (00:00:00 GMT, January 1, 1970), or 0L if the file does not exist or if an I/O error occurs
Throws:
java.lang.SecurityException - If a security manager exists and its SecurityManager.checkRead(java.lang.String) method denies read access to the file

length

public abstract long length()
Returns the length of the file denoted by this abstract pathname. The return value is unspecified if this pathname denotes a directory.

Returns:
The length, in bytes, of the file denoted by this abstract pathname, or 0L if the file does not exist
Throws:
java.lang.SecurityException - If a security manager exists and its SecurityManager.checkRead(java.lang.String) method denies read access to the file

compareTo

public abstract int compareTo(JFMFile pathname)
Compares two abstract pathnames lexicographically. The ordering defined by this method depends upon the underlying system. On UNIX systems, alphabetic case is significant in comparing pathnames; on Microsoft Windows systems it is not.

Parameters:
pathname - The abstract pathname to be compared to this abstract pathname
Returns:
Zero if the argument is equal to this abstract pathname, a value less than zero if this abstract pathname is lexicographically less than the argument, or a value greater than zero if this abstract pathname is lexicographically greater than the argument

compareTo

public int compareTo(java.lang.Object o)
Compares this abstract pathname to another object. If the other object is an abstract pathname, then this function behaves like compareTo(JFMFile). Otherwise, it throws a ClassCastException, since abstract pathnames can only be compared to abstract pathnames.

Specified by:
compareTo in interface java.lang.Comparable
Parameters:
o - The Object to be compared to this abstract pathname
Returns:
If the argument is an abstract pathname, returns zero if the argument is equal to this abstract pathname, a value less than zero if this abstract pathname is lexicographically less than the argument, or a value greater than zero if this abstract pathname is lexicographically greater than the argument
Throws:
ClassCastException - if the argument is not an abstract pathname
See Also:
Comparable

equals

public abstract boolean equals(java.lang.Object obj)
Tests this abstract pathname for equality with the given object. Returns true if and only if the argument is not null and is an abstract pathname that denotes the same file or directory as this abstract pathname. Whether or not two abstract pathnames are equal depends upon the underlying system. On UNIX systems, alphabetic case is significant in comparing pathnames; on Microsoft Windows systems it is not. With other filesystems implementation ... it's their responsability to decide wether it should be case sensitive or not.

Overrides:
equals in class java.lang.Object
Parameters:
obj - The object to be compared with this abstract pathname
Returns:
true if and only if the objects are the same; false otherwise

hashCode

public abstract int hashCode()
Computes a hash code for this abstract pathname. Because equality of abstract pathnames is inherently system-dependent, so is the computation of their hash codes. On UNIX systems, the hash code of an abstract pathname is equal to the exclusive or of its pathname string and the decimal value 1234321. On Microsoft Windows systems, the hash code is equal to the exclusive or of its pathname string, convered to lower case, and the decimal value 1234321.

Overrides:
hashCode in class java.lang.Object
Returns:
A hash code for this abstract pathname

toString

public java.lang.String toString()
If getDisplayName() return null it returns the pathname string of this abstract pathname. This is just the string returned by the getPath() method. Otherwise it just returns the displayName.

Overrides:
toString in class java.lang.Object
Returns:
The string form of this abstract pathname

getSystemDisplayName

public abstract java.lang.String getSystemDisplayName()
Returns the system display name as returned by the filesystem viewer, or null

Returns:

getMimeType

public abstract java.lang.String getMimeType()
This method returns the string that represents the mime-type of this file, or null if it can't be determined.

Returns:
the mime type of this file

getRootDriveFile

public JFMFile getRootDriveFile()
This method returns the root directory of the filesystem of witch the file belongs to. For example:

If the active filesystem is the local filesystem and is an Windows filesystem, this method should return the drive letter of the drive that this file belongs to. On Unix filesystems it will always return '/'. On other filesystems .... it will return whatever the one that implements it wants to.

Returns:
JFMFile the root drive (it cannot be null). It can be the same file that was passed as an argument.

getDisplayName

public java.lang.String getDisplayName()
Returns the display name

Returns:
String the display name

setDisplayName

public void setDisplayName(java.lang.String displayName)
Sets the display name

Parameters:
displayName - String the new display name

canRead

public abstract boolean canRead()
Tests whether the application can read the file denoted by the abstract pathname.

Parameters:
file - The file that denotes the abstract pathname
Returns:
true if and only if the file specified by this abstract pathname exists and can be read by the application; false otherwise
Throws:
java.lang.SecurityException - If a security manager exists and its SecurityManager.checkRead(java.lang.String) method denies read access to the file

canWrite

public abstract boolean canWrite()
Tests whether the application can modify to the file denoted by the abstract pathname.

Parameters:
file - The file that denotes the abstract pathname
Returns:
true if and only if the file system actually contains a file denoted by this abstract pathname and the application is allowed to write to the file; false otherwise.
Throws:
java.lang.SecurityException - If a security manager exists and its SecurityManager.checkWrite(java.lang.String) method denies write access to the file

exists

public abstract boolean exists()
Tests whether the file or directory denoted by the abstract pathname exists.

Parameters:
file - The file that denotes the abstract pathname
Returns:
true if and only if the file or directory denoted by this abstract pathname exists; false otherwise
Throws:
java.lang.SecurityException - If a security manager exists and its SecurityManager.checkRead(java.lang.String) method denies read access to the file or directory

mkdir

public abstract JFMFile mkdir(java.lang.String name)
Creates the directory named by the abstract pathname denoted by the parameter.

Parameters:
file - The file that denotes the abstract pathname
Returns:
The new file object created or null otherwise
Throws:
java.lang.SecurityException - If a security manager exists and its SecurityManager.checkWrite(java.lang.String) method does not permit the named directory to be created

createFile

public abstract JFMFile createFile(java.lang.String name)
Creates the file named by the abstract pathname denoted by the parameter.

Parameters:
file - The file that denotes the abstract pathname
Returns:
The new file object created or null otherwise
Throws:
java.lang.SecurityException - If a security manager exists and its SecurityManager.checkWrite(java.lang.String) method does not permit the named directory to be created

delete

public abstract boolean delete()
Deletes the file or directory denoted by the abstract pathname. If this pathname denotes a directory, then the directory must be empty in order to be deleted.

Parameters:
file - The file that denotes the abstract pathname
Returns:
true if and only if the file or directory is successfully deleted; false otherwise
Throws:
java.lang.SecurityException - If a security manager exists and its SecurityManager.checkDelete(java.lang.String) method denies delete access to the file

getIcon

public abstract javax.swing.Icon getIcon()
Returns the filesystem's icon associated with this file, or null if it can't be determined.

Returns:
The filesystem's icon associated with this file, or null if it can't be determined.

isMarked

public boolean isMarked()
Returns true if the file has been marked in the view, false otherwise

Returns:
true if the file has been marked in the view, false otherwise

setMarked

public void setMarked(boolean flag)
Sets the marked flag. This method is usually called by the UI View to signal that the file has been marked for selection. It helps to draw the file name with another color, and to perform operations on the file.

Parameters:
flag -

setMultiPart

public void setMultiPart(java.util.Hashtable<java.lang.String,java.lang.String> multiPart)
Sets the hashtbale multipart. This method is called when the file is too big and must be splitted. The hashtable cointains the information about every small file

Parameters:
multiPart -

getMultiPart

public java.util.Hashtable<java.lang.String,java.lang.String> getMultiPart()
gets the hashtbale multipart. This method is usually called when I want to check if this file is too big or not, checking the size of the hashtable


getFile

public java.io.File getFile()
gets the content of the JFMFile if it exists.