adammurdoch    2002/10/23 06:12:15

  Modified:    vfs/src/java/org/apache/commons/vfs/impl
                        DefaultFileSystemManager.java
               vfs/src/java/org/apache/commons/vfs/tasks VfsTask.java
               vfs/src/java/org/apache/commons/vfs Resources.properties
               vfs/src/test/org/apache/commons/vfs/test
                        FileSystemManagerFactoryTestCase.java
  Added:       vfs/src/java/org/apache/commons/vfs/impl
                        StandardFileSystemManager.java
               vfs/src/java/org/apache/commons/vfs VFS.java
  Removed:     vfs/src/java/org/apache/commons/vfs
                        FileSystemManagerFactory.java
  Log:
  - Got rid of package dependency cycle by moving FileSystemManager configuration
    code from vfs package, to a subclass of DefaultFileSystemManager in the vfs.impl
    package.
  - Renamed FileSystemManagerFactory to VFS.
  
  Revision  Changes    Path
  1.11      +8 -1      
jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/impl/DefaultFileSystemManager.java
  
  Index: DefaultFileSystemManager.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/impl/DefaultFileSystemManager.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- DefaultFileSystemManager.java     23 Oct 2002 11:59:40 -0000      1.10
  +++ DefaultFileSystemManager.java     23 Oct 2002 13:12:14 -0000      1.11
  @@ -96,7 +96,6 @@
   public class DefaultFileSystemManager
       implements FileSystemManager
   {
  -
       /** The provider for local files. */
       private LocalFileProvider localFileProvider;
   
  @@ -121,6 +120,14 @@
       /** The context to pass to providers. */
       private final DefaultProviderContext context =
           new DefaultProviderContext( this );
  +
  +    /**
  +     * Returns the logger used by this manager.
  +     */
  +    protected Log getLog()
  +    {
  +        return log;
  +    }
   
       /**
        * Registers a file system provider.  The manager takes care of all
  
  
  
  1.1                  
jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/impl/StandardFileSystemManager.java
  
  Index: StandardFileSystemManager.java
  ===================================================================
  /* ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   */
  package org.apache.commons.vfs.impl;
  
  import org.apache.commons.vfs.FileSystemException;
  import org.apache.commons.vfs.util.Messages;
  import org.apache.commons.vfs.provider.FileReplicator;
  import org.apache.commons.vfs.provider.FileProvider;
  
  /**
   * A {@link org.apache.commons.vfs.FileSystemManager} that configures itself
   * to use the standard providers and other components.
   *
   * @author <a href="mailto:adammurdoch@;apache.org">Adam Murdoch</a>
   * @version $Revision: 1.1 $ $Date: 2002/10/23 13:12:14 $
   */
  public class StandardFileSystemManager
      extends DefaultFileSystemManager
  {
      /**
       * Initializes this manager.  Adds the providers and replicator.
       */
      public void init() throws FileSystemException
      {
          // Set the replicator
          FileReplicator replicator = new DefaultFileReplicator();
          replicator = new PrivilegedFileReplicator( replicator );
          setReplicator( replicator );
  
          // Add the standard providers
          addProvider( "file", 
"org.apache.commons.vfs.provider.local.DefaultLocalFileSystemProvider" );
          addProvider( "zip", 
"org.apache.commons.vfs.provider.zip.ZipFileSystemProvider" );
          addProvider( "jar", 
"org.apache.commons.vfs.provider.jar.JarFileSystemProvider" );
          addProvider( "ftp", 
"org.apache.commons.vfs.provider.ftp.FtpFileSystemProvider" );
          addProvider( "smb", 
"org.apache.commons.vfs.provider.smb.SmbFileSystemProvider" );
  
          // Add a default provider
          final FileProvider provider = createProvider( 
"org.apache.commons.vfs.provider.url.UrlFileProvider" );
          if ( provider != null )
          {
              setDefaultProvider( provider );
          }
      }
  
      /**
       * Adds a provider.
       */
      private void addProvider( final String scheme,
                                final String providerClassName )
          throws FileSystemException
      {
          final FileProvider provider = createProvider( providerClassName );
          if ( provider != null )
          {
              addProvider( scheme, provider );
          }
      }
  
      /**
       * Creates a provider.
       */
      private FileProvider createProvider( final String providerClassName )
          throws FileSystemException
      {
          try
          {
              final Class providerClass = Class.forName( providerClassName );
              return (FileProvider)providerClass.newInstance();
          }
          catch ( final ClassNotFoundException e )
          {
              // Ignore
              final String message = Messages.getString( 
"vfs.impl/create-provider.warn", providerClassName );
              getLog().warn( message, e );
              return null;
          }
          catch ( final Exception e )
          {
              throw new FileSystemException("vfs.impl/create-provider.error", 
providerClassName, e );
          }
      }
  
  }
  
  
  
  1.3       +3 -3      
jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/tasks/VfsTask.java
  
  Index: VfsTask.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/tasks/VfsTask.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- VfsTask.java      23 Oct 2002 11:59:42 -0000      1.2
  +++ VfsTask.java      23 Oct 2002 13:12:14 -0000      1.3
  @@ -58,7 +58,7 @@
   import org.apache.tools.ant.Task;
   import org.apache.commons.vfs.FileObject;
   import org.apache.commons.vfs.FileSystemException;
  -import org.apache.commons.vfs.FileSystemManagerFactory;
  +import org.apache.commons.vfs.VFS;
   import org.apache.commons.vfs.FileSystemManager;
   
   /**
  @@ -83,7 +83,7 @@
       {
           if ( manager == null )
           {
  -            manager = FileSystemManagerFactory.getManager();
  +            manager = VFS.getManager();
           }
           return manager.resolveFile( getProject().getBaseDir(), uri );
       }
  
  
  
  1.5       +4 -0      
jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/Resources.properties
  
  Index: Resources.properties
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/Resources.properties,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- Resources.properties      23 Oct 2002 10:56:32 -0000      1.4
  +++ Resources.properties      23 Oct 2002 13:12:14 -0000      1.5
  @@ -1,3 +1,5 @@
  +# Factory
  +vfs/create-manager.error=Could not create a file system manager of class "{0}".
   
   # AbstractFileObject
   vfs.provider/delete-not-supported.error=This file type does not support delete.
  @@ -64,6 +66,8 @@
   vfs.impl/replicate-file.error=Could not replicate "{0}".
   vfs.impl/delete-temp.warn=Could not clean up temporary file "{0}".
   vfs.impl/init-replicator.error=Could not initialise file replicator.
  +vfs.impl/create-provider.warn=Could not create file provider of class "{0}".
  +vfs.impl/create-provider.error=Could not create file provider of class "{0}".
   
   # VFSClassLoader
   vfs.impl/pkg-sealing-unsealed=Trying to seal package "{0}" that exists as unsealed.
  
  
  
  1.1                  
jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/VFS.java
  
  Index: VFS.java
  ===================================================================
  /* ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   */
  package org.apache.commons.vfs;
  
  import java.lang.reflect.InvocationTargetException;
  import java.lang.reflect.Method;
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
  
  /**
   * The main entry point for the VFS.  Used to create {@link FileSystemManager}
   * instances.
   *
   * @author <a href="mailto:adammurdoch@;apache.org">Adam Murdoch</a>
   * @version $Revision: 1.1 $ $Date: 2002/10/23 13:12:14 $
   */
  public class VFS
  {
      private static FileSystemManager instance;
  
      private VFS()
      {
      }
  
      /**
       * Returns the default {@link FileSystemManager} instance.
       */
      public static synchronized FileSystemManager getManager()
          throws FileSystemException
      {
          if ( instance == null )
          {
              instance = createManager( 
"org.apache.commons.vfs.impl.StandardFileSystemManager" );
          }
          return instance;
      }
  
      /**
       * Creates a file system manager instance.
       *
       * @todo Load manager config from a file.
       */
      private static FileSystemManager createManager( final String managerClassName )
          throws FileSystemException
      {
          try
          {
              // Create instance
              final Class mgrClass = Class.forName( managerClassName );
              final FileSystemManager mgr = (FileSystemManager)mgrClass.newInstance();
  
              try
              {
                  // Set the logger
                  final Method setLogMethod = mgrClass.getMethod( "setLogger", new 
Class[] { Log.class } );
                  final Log logger = LogFactory.getLog( VFS.class );
                  setLogMethod.invoke( mgr, new Object[] { logger } );
              }
              catch ( final NoSuchMethodException e )
              {
                  // Ignore; don't set the logger
              }
  
              try
              {
                  // Initialise
                  final Method initMethod = mgrClass.getMethod( "init", null );
                  initMethod.invoke( mgr, null );
              }
              catch ( final NoSuchMethodException e )
              {
                  // Ignore; don't initialize
              }
  
              return mgr;
          }
          catch ( final InvocationTargetException e )
          {
              throw new FileSystemException( "vfs/create-manager.error",
                                             managerClassName,
                                             e.getTargetException() );
          }
          catch ( final Exception e )
          {
              throw new FileSystemException( "vfs/create-manager.error",
                                             managerClassName,
                                             e );
          }
      }
  }
  
  
  
  1.4       +4 -4      
jakarta-commons-sandbox/vfs/src/test/org/apache/commons/vfs/test/FileSystemManagerFactoryTestCase.java
  
  Index: FileSystemManagerFactoryTestCase.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons-sandbox/vfs/src/test/org/apache/commons/vfs/test/FileSystemManagerFactoryTestCase.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- FileSystemManagerFactoryTestCase.java     23 Oct 2002 11:59:39 -0000      1.3
  +++ FileSystemManagerFactoryTestCase.java     23 Oct 2002 13:12:15 -0000      1.4
  @@ -57,12 +57,12 @@
   
   import org.apache.commons.AbstractVfsTestCase;
   import org.apache.commons.vfs.FileSystemManager;
  -import org.apache.commons.vfs.FileSystemManagerFactory;
  +import org.apache.commons.vfs.VFS;
   import org.apache.commons.vfs.FileObject;
   import java.io.File;
   
   /**
  - * Test cases for the FileSystemManagerFactory.
  + * Test cases for the VFS factory.
    *
    * @author <a href="mailto:adammurdoch@;apache.org">Adam Murdoch</a>
    * @version $Revision$ $Date$
  @@ -81,7 +81,7 @@
       public void testDefaultInstance() throws Exception
       {
           // Locate the default manager
  -        final FileSystemManager manager = FileSystemManagerFactory.getManager();
  +        final FileSystemManager manager = VFS.getManager();
   
           // Lookup a test file
           final File testDir = getTestResource( "basedir" );
  
  
  

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

Reply via email to