adammurdoch    02/02/14 23:37:19

  Modified:    proposal/myrmidon/src/java/org/apache/aut/vfs
                        FileSystemManager.java
               proposal/myrmidon/src/java/org/apache/aut/vfs/provider/local
                        LocalFileSystemProvider.java
               proposal/myrmidon/src/java/org/apache/aut/vfs/impl
                        DefaultFileSystemManager.java
  Log:
  * Added another FileSystemManager.resolveFile() convenience method.
  * Made a heap of stuff final.
  
  Revision  Changes    Path
  1.3       +18 -1     
jakarta-ant/proposal/myrmidon/src/java/org/apache/aut/vfs/FileSystemManager.java
  
  Index: FileSystemManager.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-ant/proposal/myrmidon/src/java/org/apache/aut/vfs/FileSystemManager.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- FileSystemManager.java    14 Feb 2002 09:46:54 -0000      1.2
  +++ FileSystemManager.java    15 Feb 2002 07:37:18 -0000      1.3
  @@ -8,6 +8,7 @@
   package org.apache.aut.vfs;
   
   import org.apache.avalon.framework.component.Component;
  +import java.io.File;
   
   /**
    * A FileSystemManager is manages a set of file systems.  This interface is
  @@ -85,10 +86,26 @@
        *          The name of the file.
        *
        * @param baseFile
  -     *          The base file to use to resolve paths.
  +     *          The base file to use to resolve relative paths.
        *
        * @throws FileSystemException
        *          On error parsing the file name.
        */
       FileObject resolveFile( FileObject baseFile, String name ) throws 
FileSystemException;
  +
  +    /**
  +     * Locates a file by name.  See [EMAIL PROTECTED] 
#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;
   }
  
  
  
  1.2       +19 -9     
jakarta-ant/proposal/myrmidon/src/java/org/apache/aut/vfs/provider/local/LocalFileSystemProvider.java
  
  Index: LocalFileSystemProvider.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-ant/proposal/myrmidon/src/java/org/apache/aut/vfs/provider/local/LocalFileSystemProvider.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- LocalFileSystemProvider.java      2 Feb 2002 03:29:08 -0000       1.1
  +++ LocalFileSystemProvider.java      15 Feb 2002 07:37:19 -0000      1.2
  @@ -14,6 +14,7 @@
   import org.apache.aut.vfs.provider.FileSystem;
   import org.apache.aut.vfs.provider.FileSystemProvider;
   import org.apache.aut.vfs.provider.ParsedUri;
  +import java.io.File;
   
   /**
    * A file system provider, which uses direct file access.
  @@ -23,20 +24,20 @@
   public class LocalFileSystemProvider extends AbstractFileSystemProvider
       implements FileSystemProvider
   {
  -    private LocalFileNameParser m_parser = new LocalFileNameParser();
  +    private final LocalFileNameParser m_parser = new LocalFileNameParser();
   
       /**
        * 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 );
       }
   
       /**
  -     * 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,
           // and then straight back again
  @@ -44,6 +45,15 @@
       }
   
       /**
  +     * 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
        * locate the file system in the cache (using the root prefix), and is
        * passed to [EMAIL PROTECTED] #createFileSystem} to create the file 
system.
  @@ -51,7 +61,7 @@
        * <p>The provider can annotate this object with any additional
        * 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 );
       }
  @@ -59,14 +69,14 @@
       /**
        * 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.
  -        ParsedFileUri fileUri = (ParsedFileUri)uri;
  -        String rootFile = fileUri.getRootFile();
  +        final ParsedFileUri fileUri = (ParsedFileUri)uri;
  +        final String rootFile = fileUri.getRootFile();
   
           // 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 );
       }
   }
  
  
  
  1.4       +27 -15    
jakarta-ant/proposal/myrmidon/src/java/org/apache/aut/vfs/impl/DefaultFileSystemManager.java
  
  Index: DefaultFileSystemManager.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-ant/proposal/myrmidon/src/java/org/apache/aut/vfs/impl/DefaultFileSystemManager.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- DefaultFileSystemManager.java     9 Feb 2002 22:49:56 -0000       1.3
  +++ DefaultFileSystemManager.java     15 Feb 2002 07:37:19 -0000      1.4
  @@ -34,13 +34,13 @@
           = ResourceManager.getPackageResources( 
DefaultFileSystemManager.class );
   
       /** The default provider. */
  -    private LocalFileSystemProvider m_localFileProvider;
  +    private final LocalFileSystemProvider m_localFileProvider;
   
       /** Mapping from URI scheme to FileSystemProvider. */
  -    private Map m_providers = new HashMap();
  +    private final Map m_providers = new HashMap();
   
       /** The provider context. */
  -    private ProviderContextImpl m_context = new ProviderContextImpl();
  +    private final ProviderContextImpl m_context = new ProviderContextImpl();
   
       /** The base file to use for relative URI. */
       private FileObject m_baseFile;
  @@ -49,7 +49,7 @@
        * The cached file systems.  This is a mapping from root URI to
        * FileSystem object.
        */
  -    private Map m_fileSystems = new HashMap();
  +    private final Map m_fileSystems = new HashMap();
   
       public DefaultFileSystemManager() throws Exception
       {
  @@ -117,7 +117,7 @@
       /**
        * 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;
       }
  @@ -125,9 +125,9 @@
       /**
        * 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 @@
       /**
        * 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.
        */
  -    public FileObject resolveFile( FileObject baseFile, String uri ) throws 
FileSystemException
  +    public FileObject resolveFile( final FileObject baseFile, final String 
uri )
  +        throws FileSystemException
       {
           // Extract the scheme
  -        String scheme = UriParser.extractScheme( uri );
  +        final String scheme = UriParser.extractScheme( uri );
           if( scheme != null )
           {
               // An absolute URI - locate the provider
  -            FileSystemProvider provider = 
(FileSystemProvider)m_providers.get( scheme );
  +            final FileSystemProvider provider = 
(FileSystemProvider)m_providers.get( scheme );
               if( provider != null )
               {
                   return provider.findFile( uri );
  @@ -166,7 +177,7 @@
           // Handle absolute file names
           if( m_localFileProvider.isAbsoluteLocalName( uri ) )
           {
  -            return m_localFileProvider.findFileByLocalName( uri );
  +            return m_localFileProvider.findLocalFile( uri );
           }
   
           // Assume a bad scheme
  @@ -194,7 +205,7 @@
           /**
            * 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
               return (FileSystem)m_fileSystems.get( rootURI );
  @@ -203,7 +214,8 @@
           /**
            * 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
               m_fileSystems.put( rootURI, fs );
  
  
  

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to