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/10/31 11:35:18 UTC
cvs commit: jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs FileListener.java FileSystem.java Resources.properties
adammurdoch 2002/10/31 02:35:18
Modified: vfs/src/java/org/apache/commons/vfs/provider
AbstractFileObject.java AbstractFileSystem.java
vfs/src/java/org/apache/commons/vfs FileListener.java
FileSystem.java Resources.properties
Log:
- Added FileSystem.addJunction() and removeJunction(). Doesn' do anything yet.
- FileListeners can throw Exceptions.
- Made AbstractFileObject.handleCreate() and handleDelete() protected, so that
subclass can notify that the file it has been created or deleted.
Revision Changes Path
1.17 +16 -10 jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/AbstractFileObject.java
Index: AbstractFileObject.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/AbstractFileObject.java,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -r1.16 -r1.17
--- AbstractFileObject.java 27 Oct 2002 08:16:20 -0000 1.16
+++ AbstractFileObject.java 31 Oct 2002 10:35:18 -0000 1.17
@@ -122,7 +122,7 @@
* <p>Called when this file is closed, or its type changes. Note that
* the file object may be reused later, so should be able to be reattached.
*/
- protected void doDetach()
+ protected void doDetach() throws FileSystemException
{
}
@@ -137,7 +137,7 @@
* Determines if this file can be read. Is only called if {@link #doGetType}
* does not return null. This implementation always returns true.
*/
- protected boolean doIsReadable() throws FileSystemException
+ protected boolean doIsReadable() throws Exception
{
return true;
}
@@ -147,7 +147,7 @@
* {@link #doGetType} does not return null. This implementation always
* returns true.
*/
- protected boolean doIsWriteable() throws FileSystemException
+ protected boolean doIsWriteable() throws Exception
{
return true;
}
@@ -910,14 +910,20 @@
* Detaches this file, invaliating all cached info. This will force
* a call to {@link #doAttach} next time this file is used.
*/
- protected void detach()
+ protected void detach() throws FileSystemException
{
if ( attached )
{
- doDetach();
- attached = false;
- type = null;
- children = null;
+ try
+ {
+ doDetach();
+ }
+ finally
+ {
+ attached = false;
+ type = null;
+ children = null;
+ }
}
}
@@ -968,7 +974,7 @@
* Called when this file is created. Updates cached info and notifies
* the parent and file system.
*/
- private void handleCreate( final FileType newType )
+ protected void handleCreate( final FileType newType )
{
// Fix up state
type = newType;
@@ -985,7 +991,7 @@
* Called when this file is deleted. Updates cached info and notifies
* subclasses, parent and file system.
*/
- private void handleDelete()
+ protected void handleDelete()
{
// Fix up state
type = null;
1.12 +77 -13 jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/AbstractFileSystem.java
Index: AbstractFileSystem.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/AbstractFileSystem.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- AbstractFileSystem.java 25 Oct 2002 03:59:09 -0000 1.11
+++ AbstractFileSystem.java 31 Oct 2002 10:35:18 -0000 1.12
@@ -64,6 +64,7 @@
import org.apache.commons.vfs.FileSystem;
import org.apache.commons.vfs.FileListener;
import org.apache.commons.vfs.FileChangeEvent;
+import org.apache.commons.vfs.util.Messages;
/**
* A partial {@link org.apache.commons.vfs.FileSystem} implementation.
@@ -186,6 +187,24 @@
}
/**
+ * Adds a junction to this file system.
+ */
+ public void addJunction( final FileName junctionPoint,
+ final FileObject targetFile )
+ throws FileSystemException
+ {
+ throw new FileSystemException( "vfs.provider/junctions-not-supported.error", rootName );
+ }
+
+ /**
+ * Removes a junction from this file system.
+ */
+ public void removeJuntion( final FileName junctionPoint ) throws FileSystemException
+ {
+ throw new FileSystemException( "vfs.provider/junctions-not-supported.error", rootName );
+ }
+
+ /**
* Adds a listener on a file in this file system.
*/
public void addListener( final FileObject file,
@@ -218,17 +237,7 @@
*/
protected void fireFileCreated( final FileObject file )
{
- final FileChangeEvent event = new FileChangeEvent( file );
- final ArrayList listeners = (ArrayList)listenerMap.get( file.getName() );
- if ( listeners != null )
- {
- final int count = listeners.size();
- for ( int i = 0; i < count; i++ )
- {
- final FileListener listener = (FileListener)listeners.get( i );
- listener.fileCreated( event );
- }
- }
+ fireEvent( new CreateEvent( file ) );
}
/**
@@ -236,7 +245,15 @@
*/
protected void fireFileDeleted( final FileObject file )
{
- final FileChangeEvent event = new FileChangeEvent( file );
+ fireEvent( new DeleteEvent( file ) );
+ }
+
+ /**
+ * Fires an event.
+ */
+ private void fireEvent( final ChangeEvent event )
+ {
+ final FileObject file = event.getFile();
final ArrayList listeners = (ArrayList)listenerMap.get( file.getName() );
if ( listeners != null )
{
@@ -244,8 +261,55 @@
for ( int i = 0; i < count; i++ )
{
final FileListener listener = (FileListener)listeners.get( i );
- listener.fileDeleted( event );
+ try
+ {
+ event.notify( listener );
+ }
+ catch ( final Exception e )
+ {
+ final String message = Messages.getString( "vfs.provider/notify-listener.warn", file );
+ getLogger().warn( message, e );
+ }
}
+ }
+ }
+
+ /** A change event that knows how to notify a listener. */
+ private abstract static class ChangeEvent extends FileChangeEvent
+ {
+ public ChangeEvent( final FileObject file )
+ {
+ super( file );
+ }
+
+ public abstract void notify( final FileListener listener ) throws Exception;
+ }
+
+ /** File creation event. */
+ private static class CreateEvent extends ChangeEvent
+ {
+ public CreateEvent( final FileObject file )
+ {
+ super( file );
+ }
+
+ public void notify( final FileListener listener ) throws Exception
+ {
+ listener.fileCreated( this );
+ }
+ }
+
+ /** File deletion event. */
+ private static class DeleteEvent extends ChangeEvent
+ {
+ public DeleteEvent( final FileObject file )
+ {
+ super( file );
+ }
+
+ public void notify( final FileListener listener ) throws Exception
+ {
+ listener.fileDeleted( this );
}
}
}
1.2 +3 -3 jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/FileListener.java
Index: FileListener.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/FileListener.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- FileListener.java 25 Oct 2002 03:59:09 -0000 1.1
+++ FileListener.java 31 Oct 2002 10:35:18 -0000 1.2
@@ -66,10 +66,10 @@
/**
* Called when a file is created.
*/
- void fileCreated( FileChangeEvent event );
+ void fileCreated( FileChangeEvent event ) throws Exception;
/**
* Called when a file is deleted.
*/
- void fileDeleted( FileChangeEvent event );
+ void fileDeleted( FileChangeEvent event ) throws Exception;
}
1.6 +28 -4 jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/FileSystem.java
Index: FileSystem.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/FileSystem.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- FileSystem.java 25 Oct 2002 03:59:09 -0000 1.5
+++ FileSystem.java 31 Oct 2002 10:35:18 -0000 1.6
@@ -56,9 +56,7 @@
package org.apache.commons.vfs;
/**
- * A file system.
- *
- * <p>A file system can also implement {@link org.apache.commons.vfs.provider.VfsComponent}.
+ * A file system, made up of a hierarchy of files.
*
* @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
* @version $Revision$ $Date$
@@ -152,4 +150,30 @@
* @param listener The listener to remove.
*/
void removeListener( FileObject file, FileListener listener );
+
+ /**
+ * Adds a junction to this file system. A junction is a link that attaches
+ * the supplied file to a point in this file system, making it look like
+ * part of the file system.
+ *
+ * @param junctionPoint The point in this file system to add the junction.
+ * @param targetFile The file to link to.
+ *
+ * @throws FileSystemException
+ * If this file system does not support junctions, or the junction
+ * point or target file is invalid (the file system may not support
+ * nested junctions, for example).
+ */
+ void addJunction( FileName junctionPoint, FileObject targetFile )
+ throws FileSystemException;
+
+ /**
+ * Removes a junction from this file system.
+ *
+ * @param junctionPoint The junction to remove.
+ *
+ * @throws FileSystemException
+ * On error removing the junction.
+ */
+ void removeJuntion( FileName junctionPoint ) throws FileSystemException;
}
1.10 +1 -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.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- Resources.properties 27 Oct 2002 08:16:20 -0000 1.9
+++ Resources.properties 31 Oct 2002 10:35:18 -0000 1.10
@@ -56,6 +56,7 @@
# AbstractFileSystem
vfs.provider/junctions-not-supported.error=Junctions not supported for file system "{0}".
+vfs.provider/notify-listener.warn=Could not notify listener of change to "{0}".
# UriParser
vfs.provider/missing-double-slashes.error=Expecting // to follow the scheme in URI "{0}".
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>