* Made a heap of stuff final. git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@271360 13f79535-47bb-0310-9956-ffa450edef68master
| @@ -8,6 +8,7 @@ | |||||
| package org.apache.aut.vfs; | package org.apache.aut.vfs; | ||||
| import org.apache.avalon.framework.component.Component; | import org.apache.avalon.framework.component.Component; | ||||
| import java.io.File; | |||||
| /** | /** | ||||
| * A FileSystemManager is manages a set of file systems. This interface is | * A FileSystemManager is manages a set of file systems. This interface is | ||||
| @@ -85,10 +86,26 @@ public interface FileSystemManager | |||||
| * The name of the file. | * The name of the file. | ||||
| * | * | ||||
| * @param baseFile | * @param baseFile | ||||
| * The base file to use to resolve paths. | |||||
| * The base file to use to resolve relative paths. | |||||
| * | * | ||||
| * @throws FileSystemException | * @throws FileSystemException | ||||
| * On error parsing the file name. | * On error parsing the file name. | ||||
| */ | */ | ||||
| FileObject resolveFile( FileObject baseFile, String name ) throws FileSystemException; | FileObject resolveFile( FileObject baseFile, String name ) throws FileSystemException; | ||||
| /** | |||||
| * Locates a file by name. See {@link #resolveFile(FileObject, String)} | |||||
| * for details. | |||||
| * | |||||
| * @param baseFile | |||||
| * The base file to use to resolve relative paths. | |||||
| * | |||||
| * @param name | |||||
| * The name of the file. | |||||
| * | |||||
| * @throws FileSystemException | |||||
| * On error parsing the file name. | |||||
| * | |||||
| */ | |||||
| FileObject resolveFile ( File baseFile, String name ) throws FileSystemException; | |||||
| } | } | ||||
| @@ -34,13 +34,13 @@ public class DefaultFileSystemManager | |||||
| = ResourceManager.getPackageResources( DefaultFileSystemManager.class ); | = ResourceManager.getPackageResources( DefaultFileSystemManager.class ); | ||||
| /** The default provider. */ | /** The default provider. */ | ||||
| private LocalFileSystemProvider m_localFileProvider; | |||||
| private final LocalFileSystemProvider m_localFileProvider; | |||||
| /** Mapping from URI scheme to FileSystemProvider. */ | /** Mapping from URI scheme to FileSystemProvider. */ | ||||
| private Map m_providers = new HashMap(); | |||||
| private final Map m_providers = new HashMap(); | |||||
| /** The provider context. */ | /** The provider context. */ | ||||
| private ProviderContextImpl m_context = new ProviderContextImpl(); | |||||
| private final ProviderContextImpl m_context = new ProviderContextImpl(); | |||||
| /** The base file to use for relative URI. */ | /** The base file to use for relative URI. */ | ||||
| private FileObject m_baseFile; | private FileObject m_baseFile; | ||||
| @@ -49,7 +49,7 @@ public class DefaultFileSystemManager | |||||
| * The cached file systems. This is a mapping from root URI to | * The cached file systems. This is a mapping from root URI to | ||||
| * FileSystem object. | * FileSystem object. | ||||
| */ | */ | ||||
| private Map m_fileSystems = new HashMap(); | |||||
| private final Map m_fileSystems = new HashMap(); | |||||
| public DefaultFileSystemManager() throws Exception | public DefaultFileSystemManager() throws Exception | ||||
| { | { | ||||
| @@ -117,7 +117,7 @@ public class DefaultFileSystemManager | |||||
| /** | /** | ||||
| * Sets the base file to use when resolving relative URI. | * Sets the base file to use when resolving relative URI. | ||||
| */ | */ | ||||
| public void setBaseFile( FileObject baseFile ) throws FileSystemException | |||||
| public void setBaseFile( final FileObject baseFile ) throws FileSystemException | |||||
| { | { | ||||
| m_baseFile = baseFile; | m_baseFile = baseFile; | ||||
| } | } | ||||
| @@ -125,9 +125,9 @@ public class DefaultFileSystemManager | |||||
| /** | /** | ||||
| * Sets the base file to use when resolving relative URI. | * Sets the base file to use when resolving relative URI. | ||||
| */ | */ | ||||
| public void setBaseFile( File baseFile ) throws FileSystemException | |||||
| public void setBaseFile( final File baseFile ) throws FileSystemException | |||||
| { | { | ||||
| m_baseFile = m_localFileProvider.findFileByLocalName( baseFile.getAbsolutePath() ); | |||||
| m_baseFile = m_localFileProvider.findLocalFile( baseFile.getAbsolutePath() ); | |||||
| } | } | ||||
| /** | /** | ||||
| @@ -141,22 +141,33 @@ public class DefaultFileSystemManager | |||||
| /** | /** | ||||
| * Locates a file by URI. | * Locates a file by URI. | ||||
| */ | */ | ||||
| public FileObject resolveFile( String URI ) throws FileSystemException | |||||
| public FileObject resolveFile( final String uri ) throws FileSystemException | |||||
| { | { | ||||
| return resolveFile( m_baseFile, URI ); | |||||
| return resolveFile( m_baseFile, uri ); | |||||
| } | |||||
| /** | |||||
| * Locates a file by URI. | |||||
| */ | |||||
| public FileObject resolveFile( final File baseFile, final String uri ) | |||||
| throws FileSystemException | |||||
| { | |||||
| final FileObject baseFileObj = m_localFileProvider.findFileByLocalName( baseFile ); | |||||
| return resolveFile( baseFileObj, uri ); | |||||
| } | } | ||||
| /** | /** | ||||
| * Resolves a URI, relative to a base file. | * Resolves a URI, relative to a base file. | ||||
| */ | */ | ||||
| public FileObject resolveFile( FileObject baseFile, String uri ) throws FileSystemException | |||||
| public FileObject resolveFile( final FileObject baseFile, final String uri ) | |||||
| throws FileSystemException | |||||
| { | { | ||||
| // Extract the scheme | // Extract the scheme | ||||
| String scheme = UriParser.extractScheme( uri ); | |||||
| final String scheme = UriParser.extractScheme( uri ); | |||||
| if( scheme != null ) | if( scheme != null ) | ||||
| { | { | ||||
| // An absolute URI - locate the provider | // An absolute URI - locate the provider | ||||
| FileSystemProvider provider = (FileSystemProvider)m_providers.get( scheme ); | |||||
| final FileSystemProvider provider = (FileSystemProvider)m_providers.get( scheme ); | |||||
| if( provider != null ) | if( provider != null ) | ||||
| { | { | ||||
| return provider.findFile( uri ); | return provider.findFile( uri ); | ||||
| @@ -166,7 +177,7 @@ public class DefaultFileSystemManager | |||||
| // Handle absolute file names | // Handle absolute file names | ||||
| if( m_localFileProvider.isAbsoluteLocalName( uri ) ) | if( m_localFileProvider.isAbsoluteLocalName( uri ) ) | ||||
| { | { | ||||
| return m_localFileProvider.findFileByLocalName( uri ); | |||||
| return m_localFileProvider.findLocalFile( uri ); | |||||
| } | } | ||||
| // Assume a bad scheme | // Assume a bad scheme | ||||
| @@ -194,7 +205,7 @@ public class DefaultFileSystemManager | |||||
| /** | /** | ||||
| * Locates a cached file system by root URI. | * Locates a cached file system by root URI. | ||||
| */ | */ | ||||
| public FileSystem getFileSystem( String rootURI ) | |||||
| public FileSystem getFileSystem( final String rootURI ) | |||||
| { | { | ||||
| // TODO - need to have a per-fs uri comparator | // TODO - need to have a per-fs uri comparator | ||||
| return (FileSystem)m_fileSystems.get( rootURI ); | return (FileSystem)m_fileSystems.get( rootURI ); | ||||
| @@ -203,7 +214,8 @@ public class DefaultFileSystemManager | |||||
| /** | /** | ||||
| * Registers a file system for caching. | * Registers a file system for caching. | ||||
| */ | */ | ||||
| public void putFileSystem( String rootURI, FileSystem fs ) throws FileSystemException | |||||
| public void putFileSystem( final String rootURI, final FileSystem fs ) | |||||
| throws FileSystemException | |||||
| { | { | ||||
| // TODO - should really check that there's not one already cached | // TODO - should really check that there's not one already cached | ||||
| m_fileSystems.put( rootURI, fs ); | m_fileSystems.put( rootURI, fs ); | ||||
| @@ -14,6 +14,7 @@ import org.apache.aut.vfs.provider.DefaultFileName; | |||||
| import org.apache.aut.vfs.provider.FileSystem; | import org.apache.aut.vfs.provider.FileSystem; | ||||
| import org.apache.aut.vfs.provider.FileSystemProvider; | import org.apache.aut.vfs.provider.FileSystemProvider; | ||||
| import org.apache.aut.vfs.provider.ParsedUri; | import org.apache.aut.vfs.provider.ParsedUri; | ||||
| import java.io.File; | |||||
| /** | /** | ||||
| * A file system provider, which uses direct file access. | * A file system provider, which uses direct file access. | ||||
| @@ -23,26 +24,35 @@ import org.apache.aut.vfs.provider.ParsedUri; | |||||
| public class LocalFileSystemProvider extends AbstractFileSystemProvider | public class LocalFileSystemProvider extends AbstractFileSystemProvider | ||||
| implements FileSystemProvider | implements FileSystemProvider | ||||
| { | { | ||||
| private LocalFileNameParser m_parser = new LocalFileNameParser(); | |||||
| private final LocalFileNameParser m_parser = new LocalFileNameParser(); | |||||
| /** | /** | ||||
| * Determines if a name is an absolute file name. | * Determines if a name is an absolute file name. | ||||
| */ | */ | ||||
| public boolean isAbsoluteLocalName( String name ) | |||||
| public boolean isAbsoluteLocalName( final String name ) | |||||
| { | { | ||||
| return m_parser.isAbsoluteName( name ); | return m_parser.isAbsoluteName( name ); | ||||
| } | } | ||||
| /** | /** | ||||
| * Finds a file by local file name. | |||||
| * Finds a local file, from its local name. | |||||
| */ | */ | ||||
| public FileObject findFileByLocalName( String name ) throws FileSystemException | |||||
| public FileObject findLocalFile( final String name ) throws FileSystemException | |||||
| { | { | ||||
| // TODO - tidy this up, no need to turn the name into an absolute URI, | // TODO - tidy this up, no need to turn the name into an absolute URI, | ||||
| // and then straight back again | // and then straight back again | ||||
| return findFile( "file:" + name ); | return findFile( "file:" + name ); | ||||
| } | } | ||||
| /** | |||||
| * Finds a local file. | |||||
| */ | |||||
| public FileObject findFileByLocalName( final File file ) throws FileSystemException | |||||
| { | |||||
| // TODO - tidy this up, should build file object straight from the file | |||||
| return findFile( "file:" + file.getAbsolutePath() ); | |||||
| } | |||||
| /** | /** | ||||
| * Parses a URI into its components. The returned value is used to | * Parses a URI into its components. The returned value is used to | ||||
| * locate the file system in the cache (using the root prefix), and is | * locate the file system in the cache (using the root prefix), and is | ||||
| @@ -51,7 +61,7 @@ public class LocalFileSystemProvider extends AbstractFileSystemProvider | |||||
| * <p>The provider can annotate this object with any additional | * <p>The provider can annotate this object with any additional | ||||
| * information it requires to create a file system from the URI. | * information it requires to create a file system from the URI. | ||||
| */ | */ | ||||
| protected ParsedUri parseURI( String uri ) throws FileSystemException | |||||
| protected ParsedUri parseURI( final String uri ) throws FileSystemException | |||||
| { | { | ||||
| return m_parser.parseUri( uri ); | return m_parser.parseUri( uri ); | ||||
| } | } | ||||
| @@ -59,14 +69,14 @@ public class LocalFileSystemProvider extends AbstractFileSystemProvider | |||||
| /** | /** | ||||
| * Creates the filesystem. | * Creates the filesystem. | ||||
| */ | */ | ||||
| protected FileSystem createFileSystem( ParsedUri uri ) throws FileSystemException | |||||
| protected FileSystem createFileSystem( final ParsedUri uri ) throws FileSystemException | |||||
| { | { | ||||
| // Build the name of the root file. | // Build the name of the root file. | ||||
| ParsedFileUri fileUri = (ParsedFileUri)uri; | |||||
| String rootFile = fileUri.getRootFile(); | |||||
| final ParsedFileUri fileUri = (ParsedFileUri)uri; | |||||
| final String rootFile = fileUri.getRootFile(); | |||||
| // Create the file system | // Create the file system | ||||
| DefaultFileName rootName = new DefaultFileName( m_parser, fileUri.getRootURI(), "/" ); | |||||
| final DefaultFileName rootName = new DefaultFileName( m_parser, fileUri.getRootURI(), "/" ); | |||||
| return new LocalFileSystem( rootName, rootFile ); | return new LocalFileSystem( rootName, rootFile ); | ||||
| } | } | ||||
| } | } | ||||