Package org.apache.commons.vfs2.impl
Class StandardFileSystemManager
- java.lang.Object
-
- org.apache.commons.vfs2.impl.DefaultFileSystemManager
-
- org.apache.commons.vfs2.impl.StandardFileSystemManager
-
- All Implemented Interfaces:
java.lang.AutoCloseable
,FileSystemManager
public class StandardFileSystemManager extends DefaultFileSystemManager
AFileSystemManager
that configures itself from an XML (Default: providers.xml) configuration file.Certain providers are only loaded and available if the dependent library is in your classpath. You have to configure your debugging facility to log "debug" messages to see if a provider was skipped due to "unresolved externals".
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.apache.commons.vfs2.impl.DefaultFileSystemManager
DefaultFileSystemManager.VfsStreamHandlerFactory
-
-
Field Summary
Fields Modifier and Type Field Description private java.lang.ClassLoader
classLoader
private static java.lang.String
CONFIG_RESOURCE
private java.net.URL
configUri
private static java.lang.String
PLUGIN_CONFIG_RESOURCE
-
Constructor Summary
Constructors Constructor Description StandardFileSystemManager()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private void
addExtensionMap(org.w3c.dom.Element map)
Adds an extension map.private void
addMimeTypeMap(org.w3c.dom.Element map)
Adds a mime-type map.private void
addOperationProvider(org.w3c.dom.Element providerDef)
Adds a operationProvider from a operationProvider definition.private void
addProvider(org.w3c.dom.Element providerDef, boolean isDefault)
Adds a provider from a provider definition.private void
configure(java.lang.String configUri, java.io.InputStream configStream)
Configures this manager from an XML configuration file.private void
configure(java.net.URL configUri)
Configures this manager from an XML configuration file.private void
configure(org.w3c.dom.Element config)
Configures this manager from an parsed XML configuration fileprotected void
configurePlugins()
Scans the classpath to find any droped plugin.protected DefaultFileReplicator
createDefaultFileReplicator()
private javax.xml.parsers.DocumentBuilder
createDocumentBuilder()
Configure and create a DocumentBuilderprivate java.lang.Object
createInstance(java.lang.String className)
Creates a provider.private java.util.Enumeration<java.net.URL>
enumerateResources(java.lang.String name)
Enumerates resources from different class loaders.private boolean
findClass(java.lang.String className)
Tests if a class is available.private java.lang.ClassLoader
findClassLoader()
Returns a class loader or null since some Java implementation is null for the bootstrap class loader.private java.lang.String[]
getRequiredClasses(org.w3c.dom.Element providerDef)
Extracts the required classes from a provider definition.private java.lang.String[]
getRequiredSchemes(org.w3c.dom.Element providerDef)
Extracts the required schemes from a provider definition.private java.lang.String[]
getSchemas(org.w3c.dom.Element provider)
Extracts the schema names from a provider definition.private java.lang.ClassLoader
getValidClassLoader(java.lang.Class<?> clazz)
void
init()
Initializes this manager.private java.lang.Class<?>
loadClass(java.lang.String className)
Load a class from different class loaders.void
setClassLoader(java.lang.ClassLoader classLoader)
Sets the ClassLoader to use to load the providers.void
setConfiguration(java.lang.String configUri)
Sets the configuration file for this manager.void
setConfiguration(java.net.URL configUri)
Sets the configuration file for this manager.private java.lang.ClassLoader
validateClassLoader(java.lang.ClassLoader clazzLoader, java.lang.Class<?> clazz)
-
Methods inherited from class org.apache.commons.vfs2.impl.DefaultFileSystemManager
_closeFileSystem, addExtensionMap, addMimeTypeMap, addOperationProvider, addOperationProvider, addProvider, addProvider, addVirtualFileSystemScheme, canCreateFileSystem, close, closeFileSystem, createFileSystem, createFileSystem, createVirtualFileSystem, createVirtualFileSystem, freeUnusedResources, getBaseFile, getCacheStrategy, getFileContentInfoFactory, getFileObjectDecorator, getFileObjectDecoratorConst, getFilesCache, getFileSystemConfigBuilder, getLogger, getOperationProviders, getProviderCapabilities, getReplicator, getSchemes, getTemporaryFileStore, getURLStreamHandlerFactory, hasProvider, removeProvider, resolveFile, resolveFile, resolveFile, resolveFile, resolveFile, resolveFile, resolveFile, resolveName, resolveName, resolveURI, setBaseFile, setBaseFile, setCacheStrategy, setDefaultProvider, setFileContentInfoFactory, setFileObjectDecorator, setFilesCache, setLogger, setReplicator, setTemporaryFileStore, toFileObject
-
-
-
-
Field Detail
-
CONFIG_RESOURCE
private static final java.lang.String CONFIG_RESOURCE
- See Also:
- Constant Field Values
-
PLUGIN_CONFIG_RESOURCE
private static final java.lang.String PLUGIN_CONFIG_RESOURCE
- See Also:
- Constant Field Values
-
configUri
private java.net.URL configUri
-
classLoader
private java.lang.ClassLoader classLoader
-
-
Method Detail
-
setConfiguration
public void setConfiguration(java.lang.String configUri)
Sets the configuration file for this manager.- Parameters:
configUri
- The URI for this manager.
-
setConfiguration
public void setConfiguration(java.net.URL configUri)
Sets the configuration file for this manager.- Parameters:
configUri
- The URI forthis manager.
-
setClassLoader
public void setClassLoader(java.lang.ClassLoader classLoader)
Sets the ClassLoader to use to load the providers. Default is to use the ClassLoader that loaded this class.- Parameters:
classLoader
- The ClassLoader.
-
init
public void init() throws FileSystemException
Initializes this manager. Adds the providers and replicator.- Overrides:
init
in classDefaultFileSystemManager
- Throws:
FileSystemException
- if an error occurs.
-
configurePlugins
protected void configurePlugins() throws FileSystemException
Scans the classpath to find any droped plugin.The plugin-description has to be in
/META-INF/vfs-providers.xml
.- Throws:
FileSystemException
- if an error occurs.
-
findClassLoader
private java.lang.ClassLoader findClassLoader()
Returns a class loader or null since some Java implementation is null for the bootstrap class loader.- Returns:
- A class loader or null since some Java implementation is null for the bootstrap class loader.
-
createDefaultFileReplicator
protected DefaultFileReplicator createDefaultFileReplicator()
-
configure
private void configure(java.net.URL configUri) throws FileSystemException
Configures this manager from an XML configuration file.- Parameters:
configUri
- The URI of the configuration.- Throws:
FileSystemException
- if an error occus.
-
configure
private void configure(java.lang.String configUri, java.io.InputStream configStream) throws FileSystemException
Configures this manager from an XML configuration file.- Parameters:
configUri
- The URI of the configuration.configStream
- An InputStream containing the configuration.- Throws:
FileSystemException
- if an error occurs.
-
createDocumentBuilder
private javax.xml.parsers.DocumentBuilder createDocumentBuilder() throws javax.xml.parsers.ParserConfigurationException
Configure and create a DocumentBuilder- Returns:
- A DocumentBuilder for the configuration.
- Throws:
javax.xml.parsers.ParserConfigurationException
- if an error occurs.
-
configure
private void configure(org.w3c.dom.Element config) throws FileSystemException
Configures this manager from an parsed XML configuration file- Parameters:
config
- The configuration Element.- Throws:
FileSystemException
- if an error occurs.
-
addExtensionMap
private void addExtensionMap(org.w3c.dom.Element map)
Adds an extension map.- Parameters:
map
- containing the Elements.
-
addMimeTypeMap
private void addMimeTypeMap(org.w3c.dom.Element map)
Adds a mime-type map.- Parameters:
map
- containing the Elements.
-
addProvider
private void addProvider(org.w3c.dom.Element providerDef, boolean isDefault) throws FileSystemException
Adds a provider from a provider definition.- Parameters:
providerDef
- the provider definitionisDefault
- true if the default should be used.- Throws:
FileSystemException
- if an error occurs.
-
addOperationProvider
private void addOperationProvider(org.w3c.dom.Element providerDef) throws FileSystemException
Adds a operationProvider from a operationProvider definition.- Throws:
FileSystemException
-
findClass
private boolean findClass(java.lang.String className)
Tests if a class is available.
-
getRequiredClasses
private java.lang.String[] getRequiredClasses(org.w3c.dom.Element providerDef)
Extracts the required classes from a provider definition.
-
getRequiredSchemes
private java.lang.String[] getRequiredSchemes(org.w3c.dom.Element providerDef)
Extracts the required schemes from a provider definition.
-
getSchemas
private java.lang.String[] getSchemas(org.w3c.dom.Element provider)
Extracts the schema names from a provider definition.
-
getValidClassLoader
private java.lang.ClassLoader getValidClassLoader(java.lang.Class<?> clazz)
-
validateClassLoader
private java.lang.ClassLoader validateClassLoader(java.lang.ClassLoader clazzLoader, java.lang.Class<?> clazz)
-
createInstance
private java.lang.Object createInstance(java.lang.String className) throws FileSystemException
Creates a provider.- Throws:
FileSystemException
-
loadClass
private java.lang.Class<?> loadClass(java.lang.String className) throws java.lang.ClassNotFoundException
Load a class from different class loaders.- Throws:
java.lang.ClassNotFoundException
- if lastloadClass
failed.- See Also:
findClassLoader()
-
enumerateResources
private java.util.Enumeration<java.net.URL> enumerateResources(java.lang.String name) throws java.io.IOException
Enumerates resources from different class loaders.- Throws:
java.io.IOException
- ifgetResource
failed.- See Also:
findClassLoader()
-
-