ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From adammurd...@apache.org
Subject cvs commit: jakarta-ant/proposal/myrmidon/src/testcases/org/apache/aut/vfs BasicFileSystemTestBase.java
Date Sun, 03 Feb 2002 00:06:38 GMT
adammurdoch    02/02/02 16:06:38

  Modified:    proposal/myrmidon/src/java/org/apache/aut/vfs/provider
                        Resources.properties
               proposal/myrmidon/src/testcases/org/apache/aut/vfs
                        BasicFileSystemTestBase.java
  Added:       proposal/myrmidon/src/java/org/apache/aut/vfs/impl
                        DefaultFileSystemManager.java Resources.properties
  Removed:     proposal/myrmidon/src/java/org/apache/aut/vfs/provider
                        DefaultFileSystemManager.java
  Log:
  Move DefaultFileSystemManager to impl package, to get rid of circular package dependency.
  
  Revision  Changes    Path
  1.1                  jakarta-ant/proposal/myrmidon/src/java/org/apache/aut/vfs/impl/DefaultFileSystemManager.java
  
  Index: DefaultFileSystemManager.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE.txt file.
   */
  package org.apache.aut.vfs.impl;
  
  import java.util.HashMap;
  import java.util.Iterator;
  import java.util.Map;
  import java.io.File;
  import org.apache.aut.vfs.FileObject;
  import org.apache.aut.vfs.FileSystemException;
  import org.apache.aut.vfs.FileSystemManager;
  import org.apache.aut.vfs.provider.local.LocalFileSystemProvider;
  import org.apache.aut.vfs.provider.FileSystemProvider;
  import org.apache.aut.vfs.provider.UriParser;
  import org.apache.aut.vfs.provider.FileSystemProviderContext;
  import org.apache.aut.vfs.provider.FileSystem;
  import org.apache.avalon.excalibur.i18n.Resources;
  import org.apache.avalon.excalibur.i18n.ResourceManager;
  
  /**
   * A default file system manager implementation.
   *
   * @author Adam Murdoch
   */
  public class DefaultFileSystemManager implements FileSystemManager
  {
      private static final Resources REZ
          = ResourceManager.getPackageResources( DefaultFileSystemManager.class );
  
      /** The default provider. */
      private LocalFileSystemProvider m_localFileProvider;
  
      /** Mapping from URI scheme to FileSystemProvider. */
      private Map m_providers = new HashMap();
  
      /** The provider context. */
      private ProviderContextImpl m_context = new ProviderContextImpl();
  
      /** The base file to use for relative URI. */
      private FileObject m_baseFile;
  
      /**
       * The cached file systems.  This is a mapping from root URI to
       * FileSystem object.
       */
      private Map m_fileSystems = new HashMap();
  
      public DefaultFileSystemManager() throws Exception
      {
          // Create the local provider
          m_localFileProvider = new LocalFileSystemProvider();
          m_providers.put( "file", m_localFileProvider );
  
          // TODO - make this list configurable
          // Create the providers
  
          FileSystemProvider provider = createProvider( "org.apache.aut.vfs.provider.zip.ZipFileSystemProvider"
);
          if( provider != null )
          {
              m_providers.put( "zip", provider );
              m_providers.put( "jar", provider );
          }
  
          provider = createProvider( "org.apache.aut.vfs.provider.smb.SmbFileSystemProvider"
);
          if( provider != null )
          {
              m_providers.put( "smb", provider );
          }
  
          provider = createProvider( "org.apache.aut.vfs.provider.ftp.FtpFileSystemProvider"
);
          if( provider != null )
          {
              m_providers.put( "ftp", provider );
          }
  
          // Contextualise the providers
          for( Iterator iterator = m_providers.values().iterator(); iterator.hasNext(); )
          {
              provider = (FileSystemProvider)iterator.next();
              provider.setContext( m_context );
          }
      }
  
      /**
       * Creates a provider instance, returns null if the provider class is
       * not found.
       */
      private FileSystemProvider createProvider( final String className ) throws Exception
      {
          try
          {
              // TODO - wrap exceptions
              return (FileSystemProvider)Class.forName( className ).newInstance();
          }
          catch( ClassNotFoundException e )
          {
              // This is fine, for now
              return null;
          }
      }
  
      /**
       * Closes all file systems created by this file system manager.
       */
      public void close()
      {
          // TODO - implement this
      }
  
      /**
       * Sets the base file to use when resolving relative URI.
       */
      public void setBaseFile( FileObject baseFile ) throws FileSystemException
      {
          m_baseFile = baseFile;
      }
  
      /**
       * Sets the base file to use when resolving relative URI.
       */
      public void setBaseFile( File baseFile ) throws FileSystemException
      {
          m_baseFile = m_localFileProvider.findFileByLocalName( baseFile.getAbsolutePath()
);
      }
  
      /**
       * Returns the base file used to resolve relative URI.
       */
      public FileObject getBaseFile()
      {
          return m_baseFile;
      }
  
      /**
       * Locates a file by URI.
       */
      public FileObject resolveFile( String URI ) throws FileSystemException
      {
          return resolveFile( m_baseFile, URI );
      }
  
      /**
       * Resolves a URI, relative to a base file.
       */
      public FileObject resolveFile( FileObject baseFile, String uri ) throws FileSystemException
      {
          // Extract the scheme
          String scheme = UriParser.extractScheme( uri );
          if( scheme != null )
          {
              // An absolute URI - locate the provider
              FileSystemProvider provider = (FileSystemProvider)m_providers.get( scheme );
              if( provider != null )
              {
                  return provider.findFile( uri );
              }
          }
  
          // Handle absolute file names
          if( m_localFileProvider.isAbsoluteLocalName( uri ) )
          {
              return m_localFileProvider.findFileByLocalName( uri );
          }
  
          // Assume a bad scheme
          if( scheme != null )
          {
              final String message = REZ.getString( "unknown-scheme.error", scheme, uri );
              throw new FileSystemException( message );
          }
  
          // Use the supplied base file
          if( baseFile == null )
          {
              final String message = REZ.getString( "find-rel-file.error", uri );
              throw new FileSystemException( message );
          }
          return baseFile.resolveFile( uri );
      }
  
      /**
       * A provider context implementation.
       */
      private final class ProviderContextImpl implements FileSystemProviderContext
      {
          /**
           * Locates a cached file system by root URI.
           */
          public FileSystem getFileSystem( String rootURI )
          {
              // TODO - need to have a per-fs uri comparator
              return (FileSystem)m_fileSystems.get( rootURI );
          }
  
          /**
           * Registers a file system for caching.
           */
          public void putFileSystem( String rootURI, FileSystem fs ) throws FileSystemException
          {
              // TODO - should really check that there's not one already cached
              m_fileSystems.put( rootURI, fs );
          }
      }
  }
  
  
  
  1.1                  jakarta-ant/proposal/myrmidon/src/java/org/apache/aut/vfs/impl/Resources.properties
  
  Index: Resources.properties
  ===================================================================
  # DefaultFileSystemManager
  unknown-scheme.error=Unknown scheme "{0}" in URI "{0}".
  find-rel-file.error=Could not find file with URI "{0}" because it is a relative path, and
no base URI was provided.
  
  
  
  1.2       +0 -4      jakarta-ant/proposal/myrmidon/src/java/org/apache/aut/vfs/provider/Resources.properties
  
  Index: Resources.properties
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/java/org/apache/aut/vfs/provider/Resources.properties,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Resources.properties	2 Feb 2002 03:29:08 -0000	1.1
  +++ Resources.properties	3 Feb 2002 00:06:37 -0000	1.2
  @@ -31,10 +31,6 @@
   # AbstractFileSystemProvider
   invalid-absolute-uri.error=Invalid absolute URI "{0}".
   
  -# DefaultFileSystemManager
  -unknown-scheme.error=Unknown scheme "{0}" in URI "{0}".
  -find-rel-file.error=Could not find file with URI "{0}" because it is a relative path, and
no base URI was provided.
  -
   # UriParser
   missing-double-slashes.error=Expecting // to follow the scheme in URI "{0}".
   missing-hostname.error=Hostname missing from URI "{0}".
  
  
  
  1.2       +1 -1      jakarta-ant/proposal/myrmidon/src/testcases/org/apache/aut/vfs/BasicFileSystemTestBase.java
  
  Index: BasicFileSystemTestBase.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/testcases/org/apache/aut/vfs/BasicFileSystemTestBase.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- BasicFileSystemTestBase.java	2 Feb 2002 03:29:09 -0000	1.1
  +++ BasicFileSystemTestBase.java	3 Feb 2002 00:06:37 -0000	1.2
  @@ -17,7 +17,7 @@
   import java.util.List;
   import java.util.Map;
   import junit.framework.TestCase;
  -import org.apache.aut.vfs.provider.DefaultFileSystemManager;
  +import org.apache.aut.vfs.impl.DefaultFileSystemManager;
   
   /**
    * File system test cases, which verifies the structure and naming
  
  
  

--
To unsubscribe, e-mail:   <mailto:ant-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:ant-dev-help@jakarta.apache.org>


Mime
View raw message