org.apache.commons.vfs.provider
Class AbstractFileSystem

java.lang.Object
  extended by org.apache.commons.vfs.provider.AbstractVfsComponent
      extended by org.apache.commons.vfs.provider.AbstractFileSystem
All Implemented Interfaces:
FileSystem, VfsComponent
Direct Known Subclasses:
CompressedFileFileSystem, FtpFileSystem, HttpFileSystem, LocalFileSystem, RamFileSystem, SftpFileSystem, TarFileSystem, UrlFileSystem, VirtualFileSystem, ZipFileSystem

public abstract class AbstractFileSystem
extends AbstractVfsComponent
implements FileSystem

A partial FileSystem implementation.

Version:
$Revision: 484648 $ $Date: 2006-12-08 17:18:36 +0100 (Fr, 08 Dez 2006) $
Author:
Adam Murdoch

Field Summary
private  FileSystemKey cacheKey
           
private  java.util.Collection caps
           
private  FileSystemOptions fileSystemOptions
          FileSystemOptions used for configuration
private  java.util.Map listenerMap
          Map from FileName to an ArrayList of listeners for that file.
private static org.apache.commons.logging.Log log
           
private  int openStreams
          open streams counter for this filesystem
private  FileObject parentLayer
           
private  FileName rootName
           
private  long useCount
          How many fileObjects are handed out
 
Constructor Summary
protected AbstractFileSystem(FileName rootName, FileObject parentLayer, FileSystemOptions fileSystemOptions)
           
 
Method Summary
protected abstract  void addCapabilities(java.util.Collection caps)
          Adds the capabilities of this file system.
 void addJunction(java.lang.String junctionPoint, FileObject targetFile)
          Adds a junction to this file system.
 void addListener(FileObject file, FileListener listener)
          Adds a listener on a file in this file system.
 void close()
          Closes this component.
 void closeCommunicationLink()
          Close the underlaying link used to access the files
protected abstract  FileObject createFile(FileName name)
          Creates a file object.
protected  FileObject decorateFileObject(FileObject file)
           
protected  void doCloseCommunicationLink()
          Close the underlaying link used to access the files
protected  java.io.File doReplicateFile(FileObject file, FileSelector selector)
          Creates a temporary local copy of a file and its descendents.
(package private)  void fileObjectDestroyed(FileObject fileObject)
           
(package private)  void fileObjectHanded(FileObject fileObject)
           
private  void fireEvent(AbstractFileChangeEvent event)
          Fires an event.
 void fireFileChanged(FileObject file)
          Fires a file changed event.
 void fireFileCreated(FileObject file)
          Fires a file create event.
 void fireFileDeleted(FileObject file)
          Fires a file delete event.
(package private)  void freeResources()
           
 java.lang.Object getAttribute(java.lang.String attrName)
          Retrieves the attribute with the specified name.
private  FilesCache getCache()
           
(package private)  FileSystemKey getCacheKey()
           
protected  FileObject getFileFromCache(FileName name)
          Returns a cached file.
 FileSystemManager getFileSystemManager()
          Return the FileSystemManager used to instantiate this filesystem
 FileSystemOptions getFileSystemOptions()
          Return the FileSystemOptions used to instantiate this filesystem
 double getLastModTimeAccuracy()
          Returns the accuracy of the last modification time
 FileObject getParentLayer()
          Returns the parent layer if this is a layered file system.
 FileObject getRoot()
          Returns the root file of this file system.
 FileName getRootName()
          Returns the name of the root of this file system.
 boolean hasCapability(Capability capability)
          Determines if this file system has a particular capability.
 void init()
          Initialises this component.
 boolean isOpen()
          check if this filesystem has open streams
 boolean isReleaseable()
          returns true if no file is using this filesystem
protected  void notifyAllStreamsClosed()
          will be called after all file-objects closed their streams.
protected  void putFileToCache(FileObject file)
          Adds a file object to the cache.
protected  void removeFileFromCache(FileName name)
          remove a cached file.
 void removeJunction(java.lang.String junctionPoint)
          Removes a junction from this file system.
 void removeListener(FileObject file, FileListener listener)
          Removes a listener from a file in this file system.
 java.io.File replicateFile(FileObject file, FileSelector selector)
          Creates a temporary local copy of a file and its descendents.
 FileObject resolveFile(FileName name)
          Finds a file in this file system.
private  FileObject resolveFile(FileName name, boolean useCache)
           
 FileObject resolveFile(java.lang.String nameStr)
          Finds a file in this file system.
 void setAttribute(java.lang.String attrName, java.lang.Object value)
          Sets the attribute with the specified name.
(package private)  void setCacheKey(FileSystemKey cacheKey)
           
(package private)  void streamClosed()
           
(package private)  void streamOpened()
           
 
Methods inherited from class org.apache.commons.vfs.provider.AbstractVfsComponent
getContext, getLogger, setContext, setLogger
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

private static final org.apache.commons.logging.Log log

rootName

private final FileName rootName

parentLayer

private FileObject parentLayer

caps

private final java.util.Collection caps

listenerMap

private final java.util.Map listenerMap
Map from FileName to an ArrayList of listeners for that file.


fileSystemOptions

private final FileSystemOptions fileSystemOptions
FileSystemOptions used for configuration


useCount

private long useCount
How many fileObjects are handed out


cacheKey

private FileSystemKey cacheKey

openStreams

private int openStreams
open streams counter for this filesystem

Constructor Detail

AbstractFileSystem

protected AbstractFileSystem(FileName rootName,
                             FileObject parentLayer,
                             FileSystemOptions fileSystemOptions)
Method Detail

init

public void init()
          throws FileSystemException
Initialises this component.

Specified by:
init in interface VfsComponent
Overrides:
init in class AbstractVfsComponent
Throws:
FileSystemException

close

public void close()
Closes this component.

Specified by:
close in interface VfsComponent
Overrides:
close in class AbstractVfsComponent

closeCommunicationLink

public void closeCommunicationLink()
Close the underlaying link used to access the files


doCloseCommunicationLink

protected void doCloseCommunicationLink()
Close the underlaying link used to access the files


createFile

protected abstract FileObject createFile(FileName name)
                                  throws java.lang.Exception
Creates a file object. This method is called only if the requested file is not cached.

Throws:
java.lang.Exception

addCapabilities

protected abstract void addCapabilities(java.util.Collection caps)
Adds the capabilities of this file system.


getRootName

public FileName getRootName()
Returns the name of the root of this file system.

Specified by:
getRootName in interface FileSystem

putFileToCache

protected void putFileToCache(FileObject file)
Adds a file object to the cache.


getCache

private FilesCache getCache()

getFileFromCache

protected FileObject getFileFromCache(FileName name)
Returns a cached file.


removeFileFromCache

protected void removeFileFromCache(FileName name)
remove a cached file.


hasCapability

public boolean hasCapability(Capability capability)
Determines if this file system has a particular capability.

Specified by:
hasCapability in interface FileSystem
Parameters:
capability - The capability to check for.
Returns:
true if this filesystem has the requested capability. Note that not all files in the file system may have the capability.

getAttribute

public java.lang.Object getAttribute(java.lang.String attrName)
                              throws FileSystemException
Retrieves the attribute with the specified name. The default implementation simply throws an exception.

Specified by:
getAttribute in interface FileSystem
Parameters:
attrName - The name of the attribute.
Returns:
The value of the attribute.
Throws:
FileSystemException - If the file does not exist, or is being written, or if the attribute is unknown.
See Also:
FileContent.getAttribute(java.lang.String)

setAttribute

public void setAttribute(java.lang.String attrName,
                         java.lang.Object value)
                  throws FileSystemException
Sets the attribute with the specified name. The default implementation simply throws an exception.

Specified by:
setAttribute in interface FileSystem
Parameters:
attrName - The name of the attribute.
value - The value of the attribute.
Throws:
FileSystemException - If the file is read-only, or is being read, or if the attribute is not supported, or on error setting the attribute.
See Also:
FileContent.setAttribute(java.lang.String, java.lang.Object)

getParentLayer

public FileObject getParentLayer()
                          throws FileSystemException
Returns the parent layer if this is a layered file system.

Specified by:
getParentLayer in interface FileSystem
Returns:
The parent layer, or null if this is not a layered file system.
Throws:
FileSystemException

getRoot

public FileObject getRoot()
                   throws FileSystemException
Returns the root file of this file system.

Specified by:
getRoot in interface FileSystem
Throws:
FileSystemException

resolveFile

public FileObject resolveFile(java.lang.String nameStr)
                       throws FileSystemException
Finds a file in this file system.

Specified by:
resolveFile in interface FileSystem
Parameters:
nameStr - The name of the file. This must be an absolute path.
Returns:
The file. Never returns null.
Throws:
FileSystemException

resolveFile

public FileObject resolveFile(FileName name)
                       throws FileSystemException
Finds a file in this file system.

Specified by:
resolveFile in interface FileSystem
Parameters:
name - The name of the file.
Returns:
The file. Never returns null.
Throws:
FileSystemException

resolveFile

private FileObject resolveFile(FileName name,
                               boolean useCache)
                        throws FileSystemException
Throws:
FileSystemException

decorateFileObject

protected FileObject decorateFileObject(FileObject file)
                                 throws FileSystemException
Throws:
FileSystemException

replicateFile

public java.io.File replicateFile(FileObject file,
                                  FileSelector selector)
                           throws FileSystemException
Creates a temporary local copy of a file and its descendents.

Specified by:
replicateFile in interface FileSystem
Parameters:
file - The file to replicate.
selector - The selector to use to select the files to replicate.
Returns:
The local copy of this file.
Throws:
FileSystemException - If this file does not exist, or on error replicating the file.

getFileSystemOptions

public FileSystemOptions getFileSystemOptions()
Return the FileSystemOptions used to instantiate this filesystem

Specified by:
getFileSystemOptions in interface FileSystem

getFileSystemManager

public FileSystemManager getFileSystemManager()
Return the FileSystemManager used to instantiate this filesystem

Specified by:
getFileSystemManager in interface FileSystem

getLastModTimeAccuracy

public double getLastModTimeAccuracy()
Returns the accuracy of the last modification time

Specified by:
getLastModTimeAccuracy in interface FileSystem
Returns:
ms 0 perfectly accurate, >0 might be off by this value e.g. sftp 1000ms

doReplicateFile

protected java.io.File doReplicateFile(FileObject file,
                                       FileSelector selector)
                                throws java.lang.Exception
Creates a temporary local copy of a file and its descendents.

Throws:
java.lang.Exception

addJunction

public void addJunction(java.lang.String junctionPoint,
                        FileObject targetFile)
                 throws FileSystemException
Adds a junction to this file system.

Specified by:
addJunction in interface FileSystem
Parameters:
junctionPoint - The point in this file system to add the junction.
targetFile - The file to link to.
Throws:
FileSystemException - If this file system does not support junctions, or the junction point or target file is invalid (the file system may not support nested junctions, for example).

removeJunction

public void removeJunction(java.lang.String junctionPoint)
                    throws FileSystemException
Removes a junction from this file system.

Specified by:
removeJunction in interface FileSystem
Parameters:
junctionPoint - The junction to remove.
Throws:
FileSystemException - On error removing the junction.

addListener

public void addListener(FileObject file,
                        FileListener listener)
Adds a listener on a file in this file system.

Specified by:
addListener in interface FileSystem
Parameters:
file - The file to attach the listener to.
listener - The listener to add.

removeListener

public void removeListener(FileObject file,
                           FileListener listener)
Removes a listener from a file in this file system.

Specified by:
removeListener in interface FileSystem
Parameters:
file - The file to remove the listener from.
listener - The listener to remove.

fireFileCreated

public void fireFileCreated(FileObject file)
Fires a file create event.


fireFileDeleted

public void fireFileDeleted(FileObject file)
Fires a file delete event.


fireFileChanged

public void fireFileChanged(FileObject file)
Fires a file changed event.
This will only happen if you monitor the file using FileMonitor.


isReleaseable

public boolean isReleaseable()
returns true if no file is using this filesystem


freeResources

void freeResources()

fireEvent

private void fireEvent(AbstractFileChangeEvent event)
Fires an event.


fileObjectHanded

void fileObjectHanded(FileObject fileObject)

fileObjectDestroyed

void fileObjectDestroyed(FileObject fileObject)

setCacheKey

void setCacheKey(FileSystemKey cacheKey)

getCacheKey

FileSystemKey getCacheKey()

streamOpened

void streamOpened()

streamClosed

void streamClosed()

notifyAllStreamsClosed

protected void notifyAllStreamsClosed()
will be called after all file-objects closed their streams.


isOpen

public boolean isOpen()
check if this filesystem has open streams