org.apache.commons.vfs.impl
Class DefaultFileSystemManager

java.lang.Object
  extended byorg.apache.commons.vfs.impl.DefaultFileSystemManager
All Implemented Interfaces:
FileSystemManager
Direct Known Subclasses:
StandardFileSystemManager

public class DefaultFileSystemManager
extends Object
implements FileSystemManager

A default file system manager implementation.

Version:
$Revision: 202335 $ $Date: 2005-06-29 10:30:32 +0200 (Wed, 29 Jun 2005) $
Author:
Adam Murdoch

Constructor Summary
DefaultFileSystemManager()
           
 
Method Summary
 void addExtensionMap(String extension, String scheme)
          Adds an filename extension mapping.
 void addMimeTypeMap(String mimeType, String scheme)
          Adds a mime type mapping.
 void addProvider(String[] urlSchemes, FileProvider provider)
          Registers a file system provider.
 void addProvider(String urlScheme, FileProvider provider)
          Registers a file system provider.
 boolean canCreateFileSystem(FileObject file)
          Determines if a layered file system can be created for a given file.
 void close()
          Closes all files created by this manager, and cleans up any temporary files.
 void closeFileSystem(FileSystem filesystem)
           
 FileObject createFileSystem(FileObject file)
          Creates a layered file system.
 FileObject createFileSystem(String scheme, FileObject file)
          Creates a layered file system.
 FileObject createVirtualFileSystem(FileObject rootFile)
          Creates a virtual file system.
 FileObject createVirtualFileSystem(String rootUri)
          Creates an empty virtual file system.
 void freeUnusedResources()
          Free all resources used by unused filesystems created by this manager.
 FileObject getBaseFile()
          Returns the base file used to resolve relative URI.
 FileContentInfoFactory getFileContentInfoFactory()
          get the fileContentInfoFactory used to determine the infos of a file content.
 FilesCache getFilesCache()
          Returns the filesCache implementation used to cache files
 FileSystemConfigBuilder getFileSystemConfigBuilder(String scheme)
          Get the configuration builder for the given scheme
protected  org.apache.commons.logging.Log getLogger()
          Returns the logger used by this manager.
 Collection getProviderCapabilities(String scheme)
          Get the capabilities for a given scheme.
 FileReplicator getReplicator()
          Returns the file replicator.
 String[] getSchemes()
          Get the schemes currently available.
 TemporaryFileStore getTemporaryFileStore()
          Returns the temporary file store.
 URLStreamHandlerFactory getURLStreamHandlerFactory()
          Get the URLStreamHandlerFactory.
 boolean hasProvider(String scheme)
          Returns true if this manager has a provider for a particular scheme.
 void init()
          Initialises this manager.
 FileObject resolveFile(FileObject baseFile, String uri)
          Resolves a URI, relative to a base file.
 FileObject resolveFile(FileObject baseFile, String uri, FileSystemOptions fileSystemOptions)
          Resolves a URI, realtive to a base file with specified FileSystem configuration
 FileObject resolveFile(File baseFile, String uri)
          Locates a file by URI.
 FileObject resolveFile(String uri)
          Locates a file by URI.
 FileObject resolveFile(String uri, FileSystemOptions fileSystemOptions)
          Locate a file by URI, use the FileSystemOptions for file-system creation
 FileName resolveName(FileName root, String path)
          Resolves a name, relative to the file.
 FileName resolveName(FileName base, String name, NameScope scope)
          Resolves a name, relative to the root.
 FileName resolveURI(String uri)
          resolve the uri to a filename
 void setBaseFile(File baseFile)
          Sets the base file to use when resolving relative URI.
 void setBaseFile(FileObject baseFile)
          Sets the base file to use when resolving relative URI.
 void setDefaultProvider(FileProvider provider)
          Sets the default provider.
 void setFileContentInfoFactory(FileContentInfoFactory fileContentInfoFactory)
          set the fileContentInfoFactory used to determine the infos of a file content.
 void setFilesCache(FilesCache filesCache)
          Sets the filesCache implementation used to cache files
 void setLogger(org.apache.commons.logging.Log log)
          Sets the logger to use.
 void setReplicator(FileReplicator replicator)
          Sets the file replicator to use.
 void setTemporaryFileStore(TemporaryFileStore tempFileStore)
          Sets the temporary file store to use.
 FileObject toFileObject(File file)
          Converts a local file into a FileObject.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultFileSystemManager

public DefaultFileSystemManager()
Method Detail

getLogger

protected org.apache.commons.logging.Log getLogger()
Returns the logger used by this manager.


addProvider

public void addProvider(String urlScheme,
                        FileProvider provider)
                 throws FileSystemException
Registers a file system provider. The manager takes care of all lifecycle management. A provider may be registered multiple times.

Parameters:
urlScheme - The scheme the provider will handle.
provider - The provider.
Throws:
FileSystemException

addProvider

public void addProvider(String[] urlSchemes,
                        FileProvider provider)
                 throws FileSystemException
Registers a file system provider. The manager takes care of all lifecycle management. A provider may be registered multiple times.

Parameters:
urlSchemes - The schemes the provider will handle.
provider - The provider.
Throws:
FileSystemException

hasProvider

public boolean hasProvider(String scheme)
Returns true if this manager has a provider for a particular scheme.


addExtensionMap

public void addExtensionMap(String extension,
                            String scheme)
Adds an filename extension mapping.

Parameters:
extension - The file name extension.
scheme - The scheme to use for files with this extension.

addMimeTypeMap

public void addMimeTypeMap(String mimeType,
                           String scheme)
Adds a mime type mapping.

Parameters:
mimeType - The mime type.
scheme - The scheme to use for files with this mime type.

setDefaultProvider

public void setDefaultProvider(FileProvider provider)
                        throws FileSystemException
Sets the default provider. This is the provider that will handle URI with unknown schemes. The manager takes care of all lifecycle management.

Throws:
FileSystemException

getFilesCache

public FilesCache getFilesCache()
Returns the filesCache implementation used to cache files

Specified by:
getFilesCache in interface FileSystemManager

setFilesCache

public void setFilesCache(FilesCache filesCache)
                   throws FileSystemException
Sets the filesCache implementation used to cache files

Throws:
FileSystemException

getFileContentInfoFactory

public FileContentInfoFactory getFileContentInfoFactory()
get the fileContentInfoFactory used to determine the infos of a file content.

Specified by:
getFileContentInfoFactory in interface FileSystemManager

setFileContentInfoFactory

public void setFileContentInfoFactory(FileContentInfoFactory fileContentInfoFactory)
                               throws FileSystemException
set the fileContentInfoFactory used to determine the infos of a file content.

Throws:
FileSystemException

setReplicator

public void setReplicator(FileReplicator replicator)
                   throws FileSystemException
Sets the file replicator to use. The manager takes care of all lifecycle management.

Throws:
FileSystemException

setTemporaryFileStore

public void setTemporaryFileStore(TemporaryFileStore tempFileStore)
                           throws FileSystemException
Sets the temporary file store to use. The manager takes care of all lifecycle management.

Throws:
FileSystemException

setLogger

public void setLogger(org.apache.commons.logging.Log log)
Sets the logger to use.

Specified by:
setLogger in interface FileSystemManager

getReplicator

public FileReplicator getReplicator()
                             throws FileSystemException
Returns the file replicator.

Returns:
The file replicator. Never returns null.
Throws:
FileSystemException

getTemporaryFileStore

public TemporaryFileStore getTemporaryFileStore()
                                         throws FileSystemException
Returns the temporary file store.

Returns:
The file store. Never returns null.
Throws:
FileSystemException

init

public void init()
          throws FileSystemException
Initialises this manager.

Throws:
FileSystemException

close

public void close()
Closes all files created by this manager, and cleans up any temporary files. Also closes all providers and the replicator.


freeUnusedResources

public void freeUnusedResources()
Free all resources used by unused filesystems created by this manager.


setBaseFile

public void setBaseFile(FileObject baseFile)
                 throws FileSystemException
Sets the base file to use when resolving relative URI.

Throws:
FileSystemException

setBaseFile

public void setBaseFile(File baseFile)
                 throws FileSystemException
Sets the base file to use when resolving relative URI.

Throws:
FileSystemException

getBaseFile

public FileObject getBaseFile()
                       throws FileSystemException
Returns the base file used to resolve relative URI.

Specified by:
getBaseFile in interface FileSystemManager
Throws:
FileSystemException

resolveFile

public FileObject resolveFile(String uri)
                       throws FileSystemException
Locates a file by URI.

Specified by:
resolveFile in interface FileSystemManager
Parameters:
uri - The name of the file.
Returns:
The file. Never returns null.
Throws:
FileSystemException - On error parsing the file name.

resolveFile

public FileObject resolveFile(String uri,
                              FileSystemOptions fileSystemOptions)
                       throws FileSystemException
Locate a file by URI, use the FileSystemOptions for file-system creation

Specified by:
resolveFile in interface FileSystemManager
Parameters:
uri - The name of the file.
fileSystemOptions - The FileSystemOptions used for FileSystem creation
Returns:
The file. Never returns null.
Throws:
FileSystemException - On error parsing the file name.

resolveFile

public FileObject resolveFile(File baseFile,
                              String uri)
                       throws FileSystemException
Locates a file by URI.

Specified by:
resolveFile in interface FileSystemManager
Parameters:
baseFile - The base file to use to resolve relative paths. May be null.
uri - The name of the file.
Returns:
The file. Never returns null.
Throws:
FileSystemException - On error parsing the file name.

resolveFile

public FileObject resolveFile(FileObject baseFile,
                              String uri)
                       throws FileSystemException
Resolves a URI, relative to a base file.

Specified by:
resolveFile in interface FileSystemManager
Parameters:
uri - The name of the file.
baseFile - The base file to use to resolve relative paths. May be null.
Returns:
The file. Never returns null.
Throws:
FileSystemException - On error parsing the file name.

resolveFile

public FileObject resolveFile(FileObject baseFile,
                              String uri,
                              FileSystemOptions fileSystemOptions)
                       throws FileSystemException
Resolves a URI, realtive to a base file with specified FileSystem configuration

Throws:
FileSystemException

resolveName

public FileName resolveName(FileName root,
                            String path)
                     throws FileSystemException
Resolves a name, relative to the file. If the supplied name is an absolute path, then it is resolved relative to the root of the file system that the file belongs to. If a relative name is supplied, then it is resolved relative to this file name.

Specified by:
resolveName in interface FileSystemManager
Parameters:
root - the base filename
path - The name to resolve.
Returns:
A FileName object representing the resolved file name.
Throws:
FileSystemException - If the name is invalid.

resolveName

public FileName resolveName(FileName base,
                            String name,
                            NameScope scope)
                     throws FileSystemException
Resolves a name, relative to the root.

Specified by:
resolveName in interface FileSystemManager
Parameters:
base - the base filename
name - the name
scope - the NameScope
Returns:
Throws:
FileSystemException

resolveURI

public FileName resolveURI(String uri)
                    throws FileSystemException
resolve the uri to a filename

Specified by:
resolveURI in interface FileSystemManager
Throws:
FileSystemException

toFileObject

public FileObject toFileObject(File file)
                        throws FileSystemException
Converts a local file into a FileObject.

Specified by:
toFileObject in interface FileSystemManager
Parameters:
file - The file to convert.
Returns:
The FileObject that represents the local file. Never returns null.
Throws:
FileSystemException - On error converting the file.

createFileSystem

public FileObject createFileSystem(String scheme,
                                   FileObject file)
                            throws FileSystemException
Creates a layered file system.

Specified by:
createFileSystem in interface FileSystemManager
Parameters:
scheme - The name of the file system provider to use. This name is the same as the scheme used in URI to identify the provider.
file - The file to use to create the file system.
Returns:
The root file of the new file system.
Throws:
FileSystemException - On error creating the file system.

createFileSystem

public FileObject createFileSystem(FileObject file)
                            throws FileSystemException
Creates a layered file system.

Specified by:
createFileSystem in interface FileSystemManager
Parameters:
file - The file to use to create the file system.
Returns:
The root file of the new file system.
Throws:
FileSystemException - On error creating the file system.

canCreateFileSystem

public boolean canCreateFileSystem(FileObject file)
                            throws FileSystemException
Determines if a layered file system can be created for a given file.

Specified by:
canCreateFileSystem in interface FileSystemManager
Parameters:
file - The file to check for.
Throws:
FileSystemException

createVirtualFileSystem

public FileObject createVirtualFileSystem(FileObject rootFile)
                                   throws FileSystemException
Creates a virtual file system.

Specified by:
createVirtualFileSystem in interface FileSystemManager
Parameters:
rootFile - The root file to backs the file system.
Returns:
The root of the new file system.
Throws:
FileSystemException

createVirtualFileSystem

public FileObject createVirtualFileSystem(String rootUri)
                                   throws FileSystemException
Creates an empty virtual file system.

Specified by:
createVirtualFileSystem in interface FileSystemManager
Parameters:
rootUri - The root URI to use for the new file system. Can be null.
Returns:
The root file of the new file system.
Throws:
FileSystemException

getURLStreamHandlerFactory

public URLStreamHandlerFactory getURLStreamHandlerFactory()
Get the URLStreamHandlerFactory.

Specified by:
getURLStreamHandlerFactory in interface FileSystemManager

closeFileSystem

public void closeFileSystem(FileSystem filesystem)

getSchemes

public String[] getSchemes()
Get the schemes currently available.

Specified by:
getSchemes in interface FileSystemManager

getProviderCapabilities

public Collection getProviderCapabilities(String scheme)
                                   throws FileSystemException
Get the capabilities for a given scheme.

Specified by:
getProviderCapabilities in interface FileSystemManager
Throws:
FileSystemException - if the given scheme is not konwn

getFileSystemConfigBuilder

public FileSystemConfigBuilder getFileSystemConfigBuilder(String scheme)
                                                   throws FileSystemException
Get the configuration builder for the given scheme

Specified by:
getFileSystemConfigBuilder in interface FileSystemManager
Throws:
FileSystemException - if the given scheme is not konwn


Copyright © 2002-2005 The Apache Software Foundation. All Rights Reserved.