You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by ad...@apache.org on 2002/08/22 04:24:37 UTC

cvs commit: jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider AbstractFileSystemProvider.java FileProvider.java FileReplicator.java FileSystem.java

adammurdoch    2002/08/21 19:24:37

  Modified:    vfs/src/java/org/apache/commons/vfs/impl
                        DefaultFileSystemManager.java
                        PrivilegedFileReplicator.java
               vfs/src/java/org/apache/commons/vfs/provider
                        AbstractFileSystemProvider.java FileProvider.java
                        FileReplicator.java FileSystem.java
  Log:
  Detached VfsComponent from FileProvider, FileSystem, and FileReplicator.
  
  Revision  Changes    Path
  1.7       +25 -9     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.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- DefaultFileSystemManager.java	21 Aug 2002 14:28:07 -0000	1.6
  +++ DefaultFileSystemManager.java	22 Aug 2002 02:24:37 -0000	1.7
  @@ -148,19 +148,35 @@
       /**
        * Adds a component to the set of components owned by this manager.
        */
  -    private void setupComponent( final VfsComponent component )
  +    private void setupComponent( final Object component )
           throws FileSystemException
       {
           if ( !components.contains( component ) )
           {
  -            component.setLogger( log );
  -            component.setContext( context );
  -            component.init();
  +            if ( component instanceof VfsComponent )
  +            {
  +                final VfsComponent vfsComponent = (VfsComponent)component;
  +                vfsComponent.setLogger( log );
  +                vfsComponent.setContext( context );
  +                vfsComponent.init();
  +            }
               components.add( component );
           }
       }
   
       /**
  +     * Closes a component.
  +     */
  +    private void closeComponent( final Object component )
  +    {
  +        if ( component instanceof VfsComponent )
  +        {
  +            final VfsComponent vfsComponent = (VfsComponent)component;
  +            vfsComponent.close();
  +        }
  +    }
  +
  +    /**
        * Returns the file replicator.
        *
        * @return The file replicator.  Never returns null.
  @@ -186,20 +202,20 @@
           // only once).  Close the replicator last.
           for ( int i = 0; i < components.size(); i++ )
           {
  -            VfsComponent component = (VfsComponent)components.get( i );
  +            Object component = components.get( i );
               if ( component == fileReplicator )
               {
                   continue;
               }
  -            component.close();
  +            closeComponent( component );
           }
           if ( fileReplicator != null )
           {
  -            fileReplicator.close();
  +            closeComponent( fileReplicator );
           }
   
  -        this.components.clear();
  -        this.providers.clear();
  +        components.clear();
  +        providers.clear();
           localFileProvider = null;
           defaultProvider = null;
           fileReplicator = null;
  
  
  
  1.4       +43 -20    jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/impl/PrivilegedFileReplicator.java
  
  Index: PrivilegedFileReplicator.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/impl/PrivilegedFileReplicator.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- PrivilegedFileReplicator.java	21 Aug 2002 14:28:07 -0000	1.3
  +++ PrivilegedFileReplicator.java	22 Aug 2002 02:24:37 -0000	1.4
  @@ -19,6 +19,7 @@
   import org.apache.commons.vfs.FileSystemException;
   import org.apache.commons.vfs.provider.FileReplicator;
   import org.apache.commons.vfs.provider.FileSystemProviderContext;
  +import org.apache.commons.vfs.provider.VfsComponent;
   import org.apache.commons.logging.Log;
   
   /**
  @@ -29,16 +30,25 @@
    * @version $Revision$ $Date$
    */
   public class PrivilegedFileReplicator
  -    implements FileReplicator
  +    implements FileReplicator, VfsComponent
   {
       private static final Resources REZ =
           ResourceManager.getPackageResources( PrivilegedFileReplicator.class );
   
       private final FileReplicator replicator;
  +    private final VfsComponent replicatorComponent;
   
       public PrivilegedFileReplicator( FileReplicator replicator )
       {
           this.replicator = replicator;
  +        if ( replicator instanceof VfsComponent )
  +        {
  +            replicatorComponent = (VfsComponent)replicator;
  +        }
  +        else
  +        {
  +            replicatorComponent = null;
  +        }
       }
   
       /**
  @@ -46,7 +56,10 @@
        */
       public void setLogger( final Log logger )
       {
  -        replicator.setLogger( logger );
  +        if ( replicatorComponent != null  )
  +        {
  +            replicatorComponent.setLogger( logger );
  +        }
       }
   
       /**
  @@ -54,7 +67,10 @@
        */
       public void setContext( final FileSystemProviderContext context )
       {
  -        replicator.setContext( context );
  +        if ( replicatorComponent != null )
  +        {
  +            replicatorComponent.setContext( context );
  +        }
       }
   
       /**
  @@ -62,14 +78,28 @@
        */
       public void init() throws FileSystemException
       {
  -        try
  +        if ( replicatorComponent != null )
           {
  -            AccessController.doPrivileged( new InitAction() );
  +            try
  +            {
  +                AccessController.doPrivileged( new InitAction() );
  +            }
  +            catch ( final PrivilegedActionException e )
  +            {
  +                final String message = REZ.getString( "init-replicator.error" );
  +                throw new FileSystemException( message, e );
  +            }
           }
  -        catch ( final PrivilegedActionException e )
  +    }
  +
  +    /**
  +     * Closes the replicator.
  +     */
  +    public void close()
  +    {
  +        if ( replicatorComponent != null )
           {
  -            final String message = REZ.getString( "init-replicator.error" );
  -            throw new FileSystemException( message, e );
  +            AccessController.doPrivileged( new CloseAction() );
           }
       }
   
  @@ -91,14 +121,6 @@
           }
       }
   
  -    /**
  -     * Closes the replicator.
  -     */
  -    public void close()
  -    {
  -        AccessController.doPrivileged( new CloseAction() );
  -    }
  -
       /** An action that initialises the wrapped replicator. */
       private class InitAction implements PrivilegedExceptionAction
       {
  @@ -107,7 +129,7 @@
            */
           public Object run() throws Exception
           {
  -            replicator.init();
  +            replicatorComponent.init();
               return null;
           }
       }
  @@ -118,7 +140,8 @@
           private final FileObject srcFile;
           private final FileSelector selector;
   
  -        public ReplicateAction( final FileObject srcFile, final FileSelector selector )
  +        public ReplicateAction( final FileObject srcFile,
  +                                final FileSelector selector )
           {
               this.srcFile = srcFile;
               this.selector = selector;
  @@ -139,7 +162,7 @@
           /** Performs the action. */
           public Object run()
           {
  -            replicator.close();
  +            replicatorComponent.close();
               return null;
           }
       }
  
  
  
  1.5       +14 -5     jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/AbstractFileSystemProvider.java
  
  Index: AbstractFileSystemProvider.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/AbstractFileSystemProvider.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- AbstractFileSystemProvider.java	21 Aug 2002 14:28:07 -0000	1.4
  +++ AbstractFileSystemProvider.java	22 Aug 2002 02:24:37 -0000	1.5
  @@ -39,10 +39,15 @@
        */
       public void close()
       {
  +        // Close all the filesystems created by this provider
           for ( Iterator iterator = fileSystems.values().iterator(); iterator.hasNext(); )
           {
  -            FileSystem fileSystem = (FileSystem)iterator.next();
  -            fileSystem.close();
  +            Object fileSystem = iterator.next();
  +            if ( fileSystem instanceof VfsComponent )
  +            {
  +                final VfsComponent vfsComponent = (VfsComponent)fileSystem;
  +                vfsComponent.close();
  +            }
           }
           fileSystems.clear();
       }
  @@ -97,9 +102,13 @@
           throws FileSystemException
       {
           // Initialise
  -        fs.setLogger( getLogger() );
  -        fs.setContext( getContext() );
  -        fs.init();
  +        if ( fs instanceof VfsComponent )
  +        {
  +            VfsComponent vfsComponent = (VfsComponent)fs;
  +            vfsComponent.setLogger( getLogger() );
  +            vfsComponent.setContext( getContext() );
  +            vfsComponent.init();
  +        }
   
           // Add to the cache
           fileSystems.put( rootUri, fs );
  
  
  
  1.6       +2 -1      jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/FileProvider.java
  
  Index: FileProvider.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/FileProvider.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- FileProvider.java	21 Aug 2002 14:28:07 -0000	1.5
  +++ FileProvider.java	22 Aug 2002 02:24:37 -0000	1.6
  @@ -14,11 +14,12 @@
    * A file provider.  Each file provider is responsible for handling files for
    * a particular URI scheme.
    *
  + * <p>A file provider may also implement {@link VfsComponent}.
  + *
    * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
    * @version $Revision$ $Date$
    */
   public interface FileProvider
  -    extends VfsComponent
   {
       /**
        * Locates a file object, by absolute URI.
  
  
  
  1.5       +2 -1      jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/FileReplicator.java
  
  Index: FileReplicator.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/FileReplicator.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- FileReplicator.java	21 Aug 2002 14:28:07 -0000	1.4
  +++ FileReplicator.java	22 Aug 2002 02:24:37 -0000	1.5
  @@ -15,11 +15,12 @@
   /**
    * Responsible for making local replicas of files.
    *
  + * <p>A file replicator may also implement {@link VfsComponent}.
  + *
    * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
    * @version $Revision$ $Date$
    */
   public interface FileReplicator
  -    extends VfsComponent
   {
       /**
        * Creates a local copy of the file, and all its descendents.
  
  
  
  1.5       +5 -3      jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/FileSystem.java
  
  Index: FileSystem.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/FileSystem.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- FileSystem.java	21 Aug 2002 14:28:07 -0000	1.4
  +++ FileSystem.java	22 Aug 2002 02:24:37 -0000	1.5
  @@ -14,14 +14,15 @@
   /**
    * A file system.
    *
  + * <p>A file system can also implement {@link VfsComponent}.
  + *
    * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
    * @version $Revision$ $Date$
    */
   public interface FileSystem
  -    extends VfsComponent
   {
       /**
  -     * Returns the root of this file system.
  +     * Returns the root file of this file system.
        */
       FileObject getRoot() throws FileSystemException;
   
  @@ -69,7 +70,8 @@
        *      If the file is read-only, or is being read, or if the attribute
        *      is not supported, or on error setting the attribute.
        */
  -    void setAttribute( String attrName, Object value ) throws FileSystemException;
  +    void setAttribute( String attrName, Object value )
  +        throws FileSystemException;
   
       /**
        * Finds a file in this file system.
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>