org.apache.commons.vfs.impl
Class DefaultFileSystemManager

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

public class DefaultFileSystemManager
extends java.lang.Object
implements FileSystemManager

A default file system manager implementation.

Version:
$Revision: 804548 $ $Date: 2006-03-30 21:16:24 +0200 (Do, 30 Mrz 2006) $
Author:
Adam Murdoch

Constructor Summary
DefaultFileSystemManager()
           
 
Method Summary
 void _closeFileSystem(FileSystem filesystem)
          Closes the given filesystem.
If you use VFS as singleton it is VERY dangerous to call this method
 void addExtensionMap(java.lang.String extension, java.lang.String scheme)
          Adds an filename extension mapping.
 void addMimeTypeMap(java.lang.String mimeType, java.lang.String scheme)
          Adds a mime type mapping.
 void addOperationProvider(java.lang.String[] schemes, FileOperationProvider operationProvider)
           
 void addOperationProvider(java.lang.String scheme, FileOperationProvider operationProvider)
          Adds the specified FileOperationProvider for the specified scheme.
 void addProvider(java.lang.String[] urlSchemes, FileProvider provider)
          Registers a file system provider.
 void addProvider(java.lang.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)
          Closes the given filesystem.
If you use VFS as singleton it is VERY dangerous to call this method
 FileObject createFileSystem(FileObject file)
          Creates a layered file system.
 FileObject createFileSystem(java.lang.String scheme, FileObject file)
          Creates a layered file system.
 FileObject createVirtualFileSystem(FileObject rootFile)
          Creates a virtual file system.
 FileObject createVirtualFileSystem(java.lang.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.
 CacheStrategy getCacheStrategy()
          Get the cache strategy used.
 FileContentInfoFactory getFileContentInfoFactory()
          get the fileContentInfoFactory used to determine the infos of a file content.
 java.lang.Class getFileObjectDecorator()
          Get the file object decorator used.
 java.lang.reflect.Constructor getFileObjectDecoratorConst()
          The constructor associated to the fileObjectDecorator.
 FilesCache getFilesCache()
          Returns the filesCache implementation used to cache files.
 FileSystemConfigBuilder getFileSystemConfigBuilder(java.lang.String scheme)
          Get the configuration builder for the given scheme.
protected  org.apache.commons.logging.Log getLogger()
          Returns the logger used by this manager.
 FileOperationProvider[] getOperationProviders(java.lang.String scheme)
           
 java.util.Collection getProviderCapabilities(java.lang.String scheme)
          Get the capabilities for a given scheme.
 FileReplicator getReplicator()
          Returns the file replicator.
 java.lang.String[] getSchemes()
          Get the schemes currently available.
 TemporaryFileStore getTemporaryFileStore()
          Returns the temporary file store.
 java.net.URLStreamHandlerFactory getURLStreamHandlerFactory()
          Get the URLStreamHandlerFactory.
 boolean hasProvider(java.lang.String scheme)
          Returns true if this manager has a provider for a particular scheme.
 void init()
          Initialises this manager.
 FileObject resolveFile(FileObject baseFile, java.lang.String uri)
          Resolves a URI, relative to a base file.
 FileObject resolveFile(FileObject baseFile, java.lang.String uri, FileSystemOptions fileSystemOptions)
          Resolves a URI, realtive to a base file with specified FileSystem configuration.
 FileObject resolveFile(java.io.File baseFile, java.lang.String uri)
          Locates a file by URI.
 FileObject resolveFile(java.lang.String uri)
          Locates a file by URI.
 FileObject resolveFile(java.lang.String uri, FileSystemOptions fileSystemOptions)
          Locate a file by URI, use the FileSystemOptions for file-system creation.
 FileName resolveName(FileName root, java.lang.String path)
          Resolves a name, relative to the file.
 FileName resolveName(FileName base, java.lang.String name, NameScope scope)
          Resolves a name, relative to the root.
 FileName resolveURI(java.lang.String uri)
          Resolve the uri to a filename.
 void setBaseFile(java.io.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 setCacheStrategy(CacheStrategy fileCacheStrategy)
           Set the cache strategy to use when dealing with file object data.
 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 setFileObjectDecorator(java.lang.Class fileObjectDecorator)
          Set a fileObject decorator to be used for ALL returned file objects.
 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(java.io.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.

Returns:
the Logger.

addProvider

public void addProvider(java.lang.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 - if an error occurs adding the provider.

addProvider

public void addProvider(java.lang.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 - if an error occurs adding the provider.

hasProvider

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

Specified by:
hasProvider in interface FileSystemManager
Parameters:
scheme - The scheme to check.
Returns:
true if a provider is configured for this scheme, false otherwise.

addExtensionMap

public void addExtensionMap(java.lang.String extension,
                            java.lang.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(java.lang.String mimeType,
                           java.lang.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.

Parameters:
provider - The FileProvider.
Throws:
FileSystemException - if an error occurs setting the provider.

getFilesCache

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

Specified by:
getFilesCache in interface FileSystemManager
Returns:
The FilesCache.

setFilesCache

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

Parameters:
filesCache - The FilesCache.
Throws:
FileSystemException - if an error occurs setting the cache..

setCacheStrategy

public void setCacheStrategy(CacheStrategy fileCacheStrategy)
                      throws FileSystemException

Set the cache strategy to use when dealing with file object data. You can set it only once before the FileSystemManager is initialized.

The default is CacheStrategy.ON_RESOLVE

Parameters:
fileCacheStrategy - The CacheStrategy to use.
Throws:
FileSystemException - if this is not possible. e.g. it is already set.

getCacheStrategy

public CacheStrategy getCacheStrategy()
Get the cache strategy used.

Specified by:
getCacheStrategy in interface FileSystemManager
Returns:
The CacheStrategy.

getFileObjectDecorator

public java.lang.Class getFileObjectDecorator()
Get the file object decorator used.

Specified by:
getFileObjectDecorator in interface FileSystemManager
Returns:
The decorator.

getFileObjectDecoratorConst

public java.lang.reflect.Constructor getFileObjectDecoratorConst()
The constructor associated to the fileObjectDecorator. We cache it here for performance reasons.

Specified by:
getFileObjectDecoratorConst in interface FileSystemManager
Returns:
The decorator's Constructor.

setFileObjectDecorator

public void setFileObjectDecorator(java.lang.Class fileObjectDecorator)
                            throws FileSystemException
Set a fileObject decorator to be used for ALL returned file objects.

Parameters:
fileObjectDecorator - must be inherted from DecoratedFileObject a has to provide a constructor with a single FileObject as argument
Throws:
FileSystemException - if an error occurs setting the decorator.

getFileContentInfoFactory

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

Specified by:
getFileContentInfoFactory in interface FileSystemManager
Returns:
The FileContentInfoFactory.

setFileContentInfoFactory

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

Parameters:
fileContentInfoFactory - The FileContentInfoFactory.
Throws:
FileSystemException - if an error occurs setting the FileContentInfoFactory.

setReplicator

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

Parameters:
replicator - The FileReplicator.
Throws:
FileSystemException - if an error occurs setting the replicator.

setTemporaryFileStore

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

Parameters:
tempFileStore - The temporary FileStore.
Throws:
FileSystemException - if an error occurs adding the file store.

setLogger

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

Specified by:
setLogger in interface FileSystemManager
Parameters:
log - The Logger to use.

getReplicator

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

Returns:
The file replicator. Never returns null.
Throws:
FileSystemException - if there is no FileReplicator.

getTemporaryFileStore

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

Returns:
The file store. Never returns null.
Throws:
FileSystemException - if there is no TemporaryFileStore.

init

public void init()
          throws FileSystemException
Initialises this manager.

Throws:
FileSystemException - if an error occurs during initialization.

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.

Parameters:
baseFile - The new base FileObject.
Throws:
FileSystemException - if an error occurs.

setBaseFile

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

Parameters:
baseFile - The new base FileObject.
Throws:
FileSystemException - if an error occurs.

getBaseFile

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

Specified by:
getBaseFile in interface FileSystemManager
Returns:
The FileObject that represents the base file.
Throws:
FileSystemException - if an error occurs.

resolveFile

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

Specified by:
resolveFile in interface FileSystemManager
Parameters:
uri - The URI of the file to locate.
Returns:
The FileObject for the located file.
Throws:
FileSystemException - if the file cannot be located or an error occurs.

resolveFile

public FileObject resolveFile(java.lang.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 URI of the file to locate.
fileSystemOptions - The options for the FileSystem.
Returns:
The FileObject for the located file.
Throws:
FileSystemException - if the file cannot be located or an error occurs.

resolveFile

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

Specified by:
resolveFile in interface FileSystemManager
Parameters:
baseFile - The base File to use to locate the file.
uri - The URI of the file to locate.
Returns:
The FileObject for the located file.
Throws:
FileSystemException - if the file cannot be located or an error occurs.

resolveFile

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

Specified by:
resolveFile in interface FileSystemManager
Parameters:
baseFile - The base FileOjbect to use to locate the file.
uri - The URI of the file to locate.
Returns:
The FileObject for the located file.
Throws:
FileSystemException - if the file cannot be located or an error occurs.

resolveFile

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

Parameters:
baseFile - The base file.
uri - The file name. May be a fully qualified or relative path or a url.
fileSystemOptions - Options to pass to the file system.
Returns:
A FileObject representing the target file.
Throws:
FileSystemException - if an error occurs accessing the file.

resolveName

public FileName resolveName(FileName root,
                            java.lang.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 path to the file relative to the base FileName or an absolute path.
Returns:
The constructed FileName.
Throws:
FileSystemException - if an error occurs constructing the FileName.

resolveName

public FileName resolveName(FileName base,
                            java.lang.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:
The FileName of the file.
Throws:
FileSystemException - if an error occurs.

resolveURI

public FileName resolveURI(java.lang.String uri)
                    throws FileSystemException
Resolve the uri to a filename.

Specified by:
resolveURI in interface FileSystemManager
Parameters:
uri - The URI to resolve.
Returns:
The FileName of the file.
Throws:
FileSystemException - if an error occurs.

toFileObject

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

Specified by:
toFileObject in interface FileSystemManager
Parameters:
file - The input File.
Returns:
the create FileObject
Throws:
FileSystemException - if an error occurs creating the file naem.

createFileSystem

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

Specified by:
createFileSystem in interface FileSystemManager
Parameters:
scheme - The scheme to use.
file - The FileObject.
Returns:
The layered FileObject.
Throws:
FileSystemException - if an error occurs.

createFileSystem

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

Specified by:
createFileSystem in interface FileSystemManager
Parameters:
file - The FileObject to use.
Returns:
The layered FileObject.
Throws:
FileSystemException - if an error occurs.

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.
Returns:
true if the FileSystem can be created.
Throws:
FileSystemException - if an error occurs.

createVirtualFileSystem

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

Specified by:
createVirtualFileSystem in interface FileSystemManager
Parameters:
rootFile - The FileObject to use.
Returns:
The FileObject in the VirtualFileSystem.
Throws:
FileSystemException - if an error occurs creating the file.

createVirtualFileSystem

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

Specified by:
createVirtualFileSystem in interface FileSystemManager
Parameters:
rootUri - The URI to use as the root of the FileSystem.
Returns:
A FileObject in the virtual FileSystem.
Throws:
FileSystemException - if an error occurs.

getURLStreamHandlerFactory

public java.net.URLStreamHandlerFactory getURLStreamHandlerFactory()
Get the URLStreamHandlerFactory.

Specified by:
getURLStreamHandlerFactory in interface FileSystemManager
Returns:
The URLStreamHandlerFactory.

closeFileSystem

public void closeFileSystem(FileSystem filesystem)
Closes the given filesystem.
If you use VFS as singleton it is VERY dangerous to call this method

Specified by:
closeFileSystem in interface FileSystemManager
Parameters:
filesystem - The FileSystem to close.

_closeFileSystem

public void _closeFileSystem(FileSystem filesystem)
Closes the given filesystem.
If you use VFS as singleton it is VERY dangerous to call this method

Parameters:
filesystem - The FileSystem to close.

getSchemes

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

Specified by:
getSchemes in interface FileSystemManager
Returns:
The array of scheme names.

getProviderCapabilities

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

Specified by:
getProviderCapabilities in interface FileSystemManager
Parameters:
scheme - The scheme to located.
Returns:
A Collection of capabilities.
Throws:
FileSystemException - if the given scheme is not konwn

getFileSystemConfigBuilder

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

Specified by:
getFileSystemConfigBuilder in interface FileSystemManager
Parameters:
scheme - The scheme to locate.
Returns:
The FileSystemConfigBuilder for the scheme.
Throws:
FileSystemException - if the given scheme is not konwn

addOperationProvider

public void addOperationProvider(java.lang.String scheme,
                                 FileOperationProvider operationProvider)
                          throws FileSystemException
Adds the specified FileOperationProvider for the specified scheme. Several FileOperationProvider's might be registered for the same scheme. For example, for "file" scheme we can register SvnWsOperationProvider and CvsOperationProvider.

Specified by:
addOperationProvider in interface FileSystemManager
Parameters:
scheme - The scheme the provider should be registered for.
operationProvider - The FileOperationProvider.
Throws:
FileSystemException - if an error occurs adding the provider.

addOperationProvider

public void addOperationProvider(java.lang.String[] schemes,
                                 FileOperationProvider operationProvider)
                          throws FileSystemException
Specified by:
addOperationProvider in interface FileSystemManager
Parameters:
schemes - The array of schemes the provider should apply to.
operationProvider - The FileOperationProvider.
Throws:
FileSystemException - if an error occurs.
See Also:
FileSystemManager.addOperationProvider(String, org.apache.commons.vfs.operations.FileOperationProvider)

getOperationProviders

public FileOperationProvider[] getOperationProviders(java.lang.String scheme)
                                              throws FileSystemException
Specified by:
getOperationProviders in interface FileSystemManager
Parameters:
scheme - the scheme for wich we want to get the list af registered providers.
Returns:
the registered FileOperationProviders for the specified scheme. If there were no providers registered for the scheme, it returns null.
Throws:
FileSystemException - if an error occurs.


Copyright © 2002-2011 Apache Software Foundation. All Rights Reserved.