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/11/01 04:25:51 UTC
cvs commit: jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider AbstractVfsContainer.java AbstractFileSystemProvider.java
adammurdoch 2002/10/31 19:25:51
Modified: vfs/src/java/org/apache/commons/vfs/provider
AbstractFileSystemProvider.java
Added: vfs/src/java/org/apache/commons/vfs/provider
AbstractVfsContainer.java
Log:
Extract and generalise the file system lifecycle stuff from AbstractFileSystemProvider, into
new AbstractVfsContainer.
Revision Changes Path
1.12 +4 -21 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.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- AbstractFileSystemProvider.java 28 Oct 2002 02:05:06 -0000 1.11
+++ AbstractFileSystemProvider.java 1 Nov 2002 03:25:51 -0000 1.12
@@ -70,7 +70,7 @@
* @version $Revision$ $Date$
*/
public abstract class AbstractFileSystemProvider
- extends AbstractVfsComponent
+ extends AbstractVfsContainer
implements FileProvider
{
/**
@@ -84,17 +84,8 @@
*/
public void close()
{
- // Close all the filesystems created by this provider
- for ( Iterator iterator = fileSystems.values().iterator(); iterator.hasNext(); )
- {
- Object fileSystem = iterator.next();
- if ( fileSystem instanceof VfsComponent )
- {
- final VfsComponent vfsComponent = (VfsComponent)fileSystem;
- vfsComponent.close();
- }
- }
fileSystems.clear();
+ super.close();
}
/**
@@ -109,21 +100,13 @@
/**
* Adds a file system to those cached by this provider. The file system
- * may implement {@link VfsComponent}.
+ * may implement {@link VfsComponent}, in which case it is initialised.
*/
protected void addFileSystem( final Object key, final FileSystem fs )
throws FileSystemException
{
- // Initialise
- if ( fs instanceof VfsComponent )
- {
- VfsComponent vfsComponent = (VfsComponent)fs;
- vfsComponent.setLogger( getLogger() );
- vfsComponent.setContext( getContext() );
- vfsComponent.init();
- }
-
// Add to the cache
+ addComponent( fs );
fileSystems.put( key, fs );
}
1.1 jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/AbstractVfsContainer.java
Index: AbstractVfsContainer.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 apache@apache.org.
*
* 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.provider;
import java.util.ArrayList;
import org.apache.commons.vfs.FileSystemException;
/**
* A {@link VfsComponent} that contains a set of sub-components.
*
* @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
* @version $Revision: 1.1 $ $Date: 2002/11/01 03:25:51 $
*/
public abstract class AbstractVfsContainer
extends AbstractVfsComponent
{
/** The components contained by this component. */
private final ArrayList components = new ArrayList();
/**
* Adds a sub-component to this component. If the sub-component implements
* {@link VfsComponent}, it is initialised. All sub-components are closed
* when this component is closed.
*/
protected void addComponent( final Object component )
throws FileSystemException
{
if ( ! components.contains( component ) )
{
// Initialise
if ( component instanceof VfsComponent )
{
VfsComponent vfsComponent = (VfsComponent)component;
vfsComponent.setLogger( getLogger() );
vfsComponent.setContext( getContext() );
vfsComponent.init();
}
// Keep track of component, to close it later
components.add( component );
}
}
/**
* Closes the sub-components of this component.
*/
public void close()
{
// Close all components
final int count = components.size();
for ( int i = 0; i < count; i++ )
{
final Object component = components.get( i );
if ( component instanceof VfsComponent )
{
final VfsComponent vfsComponent = (VfsComponent)component;
vfsComponent.close();
}
}
components.clear();
}
}
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>