You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by im...@apache.org on 2006/03/30 21:16:27 UTC
svn commit: r390219 - in /jakarta/commons/proper/vfs/trunk/src:
java/org/apache/commons/vfs/ java/org/apache/commons/vfs/cache/
java/org/apache/commons/vfs/impl/ java/org/apache/commons/vfs/provider/
java/org/apache/commons/vfs/util/ test/org/apache/co...
Author: imario
Date: Thu Mar 30 11:16:24 2006
New Revision: 390219
URL: http://svn.apache.org/viewcvs?rev=390219&view=rev
Log:
added cacheStrategy to fileSystemManager
Added:
jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/CacheStrategy.java (with props)
jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/cache/OnCallRefreshFileObject.java (with props)
jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/impl/DecoratedFileObject.java (with props)
jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/util/FileObjectUtils.java (with props)
jakarta/commons/proper/vfs/trunk/src/test/org/apache/commons/vfs/test/ProviderCacheStrategyTests.java (with props)
Modified:
jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/FileObject.java
jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/FileSystemManager.java
jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/Resources.properties
jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/cache/LRUFilesCache.java
jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/impl/DefaultFileSystemManager.java
jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/AbstractFileObject.java
jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/AbstractFileSystem.java
jakarta/commons/proper/vfs/trunk/src/test/org/apache/commons/vfs/test/AbstractProviderTestCase.java
jakarta/commons/proper/vfs/trunk/src/test/org/apache/commons/vfs/test/AbstractTestSuite.java
jakarta/commons/proper/vfs/trunk/src/test/org/apache/commons/vfs/test/ProviderTestSuite.java
Added: jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/CacheStrategy.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/CacheStrategy.java?rev=390219&view=auto
==============================================================================
--- jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/CacheStrategy.java (added)
+++ jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/CacheStrategy.java Thu Mar 30 11:16:24 2006
@@ -0,0 +1,64 @@
+/*
+ * Copyright 2002-2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.vfs;
+
+/**
+ * An enumerated type to deal with the various cache strategies.
+ *
+ * @author <a href="mailto:imario@apache.org">Mario Ivankovits</a>
+ * @version $Revision$ $Date$
+ */
+public final class CacheStrategy
+{
+ /**
+ * Deal with cached data manually. Call {@link FileObject#refresh()} to refresh the object data.
+ */
+ public static final CacheStrategy MANUAL = new CacheStrategy("manual");
+
+ /**
+ * Refresh the data every time you request a file from {@link FileSystemManager#resolveFile}
+ */
+ public static final CacheStrategy ON_RESOLVE = new CacheStrategy("onresolve");
+
+ /**
+ * Refresh the data every time you call a method on the fileObject.
+ * You'll use this only if you really need the latest info as this setting is a major performance loss.
+ */
+ public static final CacheStrategy ON_CALL = new CacheStrategy("oncall");
+
+ private final String name;
+
+ private CacheStrategy(final String name)
+ {
+ this.name = name;
+ }
+
+ /**
+ * Returns the name of the scope.
+ */
+ public String toString()
+ {
+ return name;
+ }
+
+ /**
+ * Returns the name of the scope.
+ */
+ public String getName()
+ {
+ return name;
+ }
+}
Propchange: jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/CacheStrategy.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/CacheStrategy.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/CacheStrategy.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/FileObject.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/FileObject.java?rev=390219&r1=390218&r2=390219&view=diff
==============================================================================
--- jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/FileObject.java (original)
+++ jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/FileObject.java Thu Mar 30 11:16:24 2006
@@ -308,4 +308,19 @@
* @see FileContent#close
*/
public void close() throws FileSystemException;
+
+ /**
+ * This will prepare the fileObject to get resynchronized with the underlaying filesystem if required
+ */
+ public void refresh() throws FileSystemException;
+
+ /**
+ * check if the fileObject is attaced
+ */
+ public boolean isAttached();
+
+ /**
+ * check if someone reads/write to this file
+ */
+ public boolean isContentOpen();
}
Modified: jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/FileSystemManager.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/FileSystemManager.java?rev=390219&r1=390218&r2=390219&view=diff
==============================================================================
--- jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/FileSystemManager.java (original)
+++ jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/FileSystemManager.java Thu Mar 30 11:16:24 2006
@@ -70,7 +70,7 @@
/**
* Returns the base file used to resolve relative paths.
*/
- FileObject getBaseFile() throws FileSystemException;
+ public FileObject getBaseFile() throws FileSystemException;
/**
* Locates a file by name. Equivalent to calling
@@ -80,7 +80,7 @@
* @return The file. Never returns null.
* @throws FileSystemException On error parsing the file name.
*/
- FileObject resolveFile(String name)
+ public FileObject resolveFile(String name)
throws FileSystemException;
/**
@@ -92,7 +92,7 @@
* @return The file. Never returns null.
* @throws FileSystemException On error parsing the file name.
*/
- FileObject resolveFile(String name, FileSystemOptions fileSystemOptions)
+ public FileObject resolveFile(String name, FileSystemOptions fileSystemOptions)
throws FileSystemException;
/**
@@ -109,7 +109,7 @@
* @return The file. Never returns null.
* @throws FileSystemException On error parsing the file name.
*/
- FileObject resolveFile(FileObject baseFile, String name)
+ public FileObject resolveFile(FileObject baseFile, String name)
throws FileSystemException;
/**
@@ -122,7 +122,7 @@
* @return The file. Never returns null.
* @throws FileSystemException On error parsing the file name.
*/
- FileObject resolveFile(File baseFile, String name)
+ public FileObject resolveFile(File baseFile, String name)
throws FileSystemException;
/**
@@ -134,7 +134,7 @@
* @return A {@link FileName} object representing the resolved file name.
* @throws FileSystemException If the name is invalid.
*/
- FileName resolveName(final FileName root, final String name) throws FileSystemException;
+ public FileName resolveName(final FileName root, final String name) throws FileSystemException;
/**
* Resolves a name, relative to the "root" file name. Refer to {@link NameScope}
@@ -146,7 +146,7 @@
* @return A {@link FileName} object representing the resolved file name.
* @throws FileSystemException If the name is invalid.
*/
- FileName resolveName(final FileName root, String name, NameScope scope)
+ public FileName resolveName(final FileName root, String name, NameScope scope)
throws FileSystemException;
/**
@@ -157,7 +157,7 @@
* returns null.
* @throws FileSystemException On error converting the file.
*/
- FileObject toFileObject(File file)
+ public FileObject toFileObject(File file)
throws FileSystemException;
/**
@@ -170,7 +170,7 @@
* @return The root file of the new file system.
* @throws FileSystemException On error creating the file system.
*/
- FileObject createFileSystem(String provider, FileObject file)
+ public FileObject createFileSystem(String provider, FileObject file)
throws FileSystemException;
/**
@@ -181,7 +181,7 @@
* @return The root file of the new file system.
* @throws FileSystemException On error creating the file system.
*/
- FileObject createFileSystem(FileObject file)
+ public FileObject createFileSystem(FileObject file)
throws FileSystemException;
/**
@@ -191,7 +191,7 @@
* @param rootUri The root URI to use for the new file system. Can be null.
* @return The root file of the new file system.
*/
- FileObject createVirtualFileSystem(String rootUri)
+ public FileObject createVirtualFileSystem(String rootUri)
throws FileSystemException;
/**
@@ -201,31 +201,36 @@
* @param rootFile The root file to backs the file system.
* @return The root of the new file system.
*/
- FileObject createVirtualFileSystem(FileObject rootFile)
+ public FileObject createVirtualFileSystem(FileObject rootFile)
throws FileSystemException;
/**
* Returns a streamhandler factory to enable URL lookup using this
* FileSystemManager.
*/
- URLStreamHandlerFactory getURLStreamHandlerFactory();
+ public URLStreamHandlerFactory getURLStreamHandlerFactory();
/**
* Determines if a layered file system can be created for a given file.
*
* @param file The file to check for.
*/
- boolean canCreateFileSystem(FileObject file) throws FileSystemException;
+ public boolean canCreateFileSystem(FileObject file) throws FileSystemException;
/**
* Get the cache used to cache fileobjects.
*/
- FilesCache getFilesCache();
+ public FilesCache getFilesCache();
+
+ /**
+ * Get the cache strategy used
+ */
+ public CacheStrategy getCacheStrategy();
/**
* The class to use to determine the content-type (mime-type)
*/
- FileContentInfoFactory getFileContentInfoFactory();
+ public FileContentInfoFactory getFileContentInfoFactory();
/**
* Get the schemes currently available.
Modified: jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/Resources.properties
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/Resources.properties?rev=390219&r1=390218&r2=390219&view=diff
==============================================================================
--- jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/Resources.properties (original)
+++ jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/Resources.properties Thu Mar 30 11:16:24 2006
@@ -40,6 +40,7 @@
vfs.provider/check-is-writeable.error=Could not determine if file "{0}" is writeable.
vfs.provider/check-is-readable.error=Could not determine if file "{0}" is readable.
vfs.provider/get-url.error=Could not create URL for "{0}".
+vfs.provider/resync.error=Could not resync "{0}".
vfs.provider/close.error=Could not close "{0}".
vfs.provider/read.error=Could not read file "{0}".
vfs.provider/random-access.error=Could not read/write file "{0}".
@@ -245,4 +246,7 @@
vfs.tasks/mkdir.create-folder.info=Creating directory "{0}".
# Selectors
-vfs.selectors/filefilter.missing.error=Configure a fileFilter or override accept();
\ No newline at end of file
+vfs.selectors/filefilter.missing.error=Configure a fileFilter or override accept();
+
+# Utils
+vfs.util/find-abstract-file-object.error=Object didnt extend from AbstractFileObject. Object "{0}"
\ No newline at end of file
Modified: jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/cache/LRUFilesCache.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/cache/LRUFilesCache.java?rev=390219&r1=390218&r2=390219&view=diff
==============================================================================
--- jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/cache/LRUFilesCache.java (original)
+++ jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/cache/LRUFilesCache.java Thu Mar 30 11:16:24 2006
@@ -15,6 +15,9 @@
*/
package org.apache.commons.vfs.cache;
+import java.util.HashMap;
+import java.util.Map;
+
import org.apache.commons.collections.map.AbstractLinkedMap;
import org.apache.commons.collections.map.LRUMap;
import org.apache.commons.logging.Log;
@@ -24,12 +27,8 @@
import org.apache.commons.vfs.FileSystem;
import org.apache.commons.vfs.FileSystemException;
import org.apache.commons.vfs.VfsLog;
-import org.apache.commons.vfs.provider.AbstractFileObject;
import org.apache.commons.vfs.util.Messages;
-import java.util.HashMap;
-import java.util.Map;
-
/**
* This implementation caches every file using {@link LRUMap}.<br>
* The default constructor uses a LRU size of 100 per filesystem.
@@ -61,7 +60,8 @@
{
synchronized (LRUFilesCache.this)
{
- AbstractFileObject file = (AbstractFileObject) linkEntry.getValue();
+ FileObject file = (FileObject) linkEntry.getValue();
+
// System.err.println(">>> " + size() + " check removeLRU:" + linkEntry.getKey().toString());
if (file.isAttached() || file.isContentOpen())
Added: jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/cache/OnCallRefreshFileObject.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/cache/OnCallRefreshFileObject.java?rev=390219&view=auto
==============================================================================
--- jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/cache/OnCallRefreshFileObject.java (added)
+++ jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/cache/OnCallRefreshFileObject.java Thu Mar 30 11:16:24 2006
@@ -0,0 +1,154 @@
+/*
+ * Copyright 2002-2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.vfs.cache;
+
+import java.util.List;
+
+import org.apache.commons.vfs.FileContent;
+import org.apache.commons.vfs.FileObject;
+import org.apache.commons.vfs.FileSelector;
+import org.apache.commons.vfs.FileSystemException;
+import org.apache.commons.vfs.FileType;
+import org.apache.commons.vfs.NameScope;
+import org.apache.commons.vfs.impl.DecoratedFileObject;
+
+/**
+ * This decorator refreshes the fileObject data on every call
+ *
+ * @author <a href="mailto:imario@apache.org">Mario Ivankovits</a>
+ * @version $Revision$ $Date$
+ */
+public class OnCallRefreshFileObject extends DecoratedFileObject
+{
+ public OnCallRefreshFileObject(FileObject fileObject)
+ {
+ super(fileObject);
+ }
+
+ public void close() throws FileSystemException
+ {
+ refresh();
+ super.close();
+ }
+
+ public void copyFrom(FileObject srcFile, FileSelector selector) throws FileSystemException
+ {
+ refresh();
+ super.copyFrom(srcFile, selector);
+ }
+
+ public void createFile() throws FileSystemException
+ {
+ refresh();
+ super.createFile();
+ }
+
+ public void createFolder() throws FileSystemException
+ {
+ refresh();
+ super.createFolder();
+ }
+
+ public boolean delete() throws FileSystemException
+ {
+ refresh();
+ return super.delete();
+ }
+
+ public int delete(FileSelector selector) throws FileSystemException
+ {
+ refresh();
+ return super.delete(selector);
+ }
+
+ public boolean exists() throws FileSystemException
+ {
+ refresh();
+ return super.exists();
+ }
+
+ public void findFiles(FileSelector selector, boolean depthwise, List selected) throws FileSystemException
+ {
+ refresh();
+ super.findFiles(selector, depthwise, selected);
+ }
+
+ public FileObject[] findFiles(FileSelector selector) throws FileSystemException
+ {
+ refresh();
+ return super.findFiles(selector);
+ }
+
+ public FileObject getChild(String name) throws FileSystemException
+ {
+ refresh();
+ return super.getChild(name);
+ }
+
+ public FileObject[] getChildren() throws FileSystemException
+ {
+ refresh();
+ return super.getChildren();
+ }
+
+ public FileContent getContent() throws FileSystemException
+ {
+ refresh();
+ return super.getContent();
+ }
+
+ public FileType getType() throws FileSystemException
+ {
+ refresh();
+ return super.getType();
+ }
+
+ public boolean isHidden() throws FileSystemException
+ {
+ refresh();
+ return super.isHidden();
+ }
+
+ public boolean isReadable() throws FileSystemException
+ {
+ refresh();
+ return super.isReadable();
+ }
+
+ public boolean isWriteable() throws FileSystemException
+ {
+ refresh();
+ return super.isWriteable();
+ }
+
+ public void moveTo(FileObject destFile) throws FileSystemException
+ {
+ refresh();
+ super.moveTo(destFile);
+ }
+
+ public FileObject resolveFile(String name, NameScope scope) throws FileSystemException
+ {
+ refresh();
+ return super.resolveFile(name, scope);
+ }
+
+ public FileObject resolveFile(String path) throws FileSystemException
+ {
+ refresh();
+ return super.resolveFile(path);
+ }
+}
Propchange: jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/cache/OnCallRefreshFileObject.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/cache/OnCallRefreshFileObject.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/cache/OnCallRefreshFileObject.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/impl/DecoratedFileObject.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/impl/DecoratedFileObject.java?rev=390219&view=auto
==============================================================================
--- jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/impl/DecoratedFileObject.java (added)
+++ jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/impl/DecoratedFileObject.java Thu Mar 30 11:16:24 2006
@@ -0,0 +1,190 @@
+/*
+ * Copyright 2002-2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.vfs.impl;
+
+import java.net.URL;
+import java.util.List;
+
+import org.apache.commons.vfs.FileContent;
+import org.apache.commons.vfs.FileName;
+import org.apache.commons.vfs.FileObject;
+import org.apache.commons.vfs.FileSelector;
+import org.apache.commons.vfs.FileSystem;
+import org.apache.commons.vfs.FileSystemException;
+import org.apache.commons.vfs.FileType;
+import org.apache.commons.vfs.NameScope;
+
+/**
+ * Base class to build a fileObject decoration
+ *
+ * @author <a href="mailto:imario@apache.org">Mario Ivankovits</a>
+ * @version $Revision$ $Date$
+ */
+public class DecoratedFileObject implements FileObject
+{
+ final FileObject decoratedFileObject;
+
+ public DecoratedFileObject(FileObject decoratedFileObject)
+ {
+ super();
+ this.decoratedFileObject = decoratedFileObject;
+ }
+
+ public boolean canRenameTo(FileObject newfile)
+ {
+ return decoratedFileObject.canRenameTo(newfile);
+ }
+
+ public void close() throws FileSystemException
+ {
+ decoratedFileObject.close();
+ }
+
+ public void copyFrom(FileObject srcFile, FileSelector selector) throws FileSystemException
+ {
+ decoratedFileObject.copyFrom(srcFile, selector);
+ }
+
+ public void createFile() throws FileSystemException
+ {
+ decoratedFileObject.createFile();
+ }
+
+ public void createFolder() throws FileSystemException
+ {
+ decoratedFileObject.createFolder();
+ }
+
+ public boolean delete() throws FileSystemException
+ {
+ return decoratedFileObject.delete();
+ }
+
+ public int delete(FileSelector selector) throws FileSystemException
+ {
+ return decoratedFileObject.delete(selector);
+ }
+
+ public boolean exists() throws FileSystemException
+ {
+ return decoratedFileObject.exists();
+ }
+
+ public void findFiles(FileSelector selector, boolean depthwise, List selected) throws FileSystemException
+ {
+ decoratedFileObject.findFiles(selector, depthwise, selected);
+ }
+
+ public FileObject[] findFiles(FileSelector selector) throws FileSystemException
+ {
+ return decoratedFileObject.findFiles(selector);
+ }
+
+ public FileObject getChild(String name) throws FileSystemException
+ {
+ return decoratedFileObject.getChild(name);
+ }
+
+ public FileObject[] getChildren() throws FileSystemException
+ {
+ return decoratedFileObject.getChildren();
+ }
+
+ public FileContent getContent() throws FileSystemException
+ {
+ return decoratedFileObject.getContent();
+ }
+
+ public FileSystem getFileSystem()
+ {
+ return decoratedFileObject.getFileSystem();
+ }
+
+ public FileName getName()
+ {
+ return decoratedFileObject.getName();
+ }
+
+ public FileObject getParent() throws FileSystemException
+ {
+ return decoratedFileObject.getParent();
+ }
+
+ public FileType getType() throws FileSystemException
+ {
+ return decoratedFileObject.getType();
+ }
+
+ public URL getURL() throws FileSystemException
+ {
+ return decoratedFileObject.getURL();
+ }
+
+ public boolean isHidden() throws FileSystemException
+ {
+ return decoratedFileObject.isHidden();
+ }
+
+ public boolean isReadable() throws FileSystemException
+ {
+ return decoratedFileObject.isReadable();
+ }
+
+ public boolean isWriteable() throws FileSystemException
+ {
+ return decoratedFileObject.isWriteable();
+ }
+
+ public void moveTo(FileObject destFile) throws FileSystemException
+ {
+ decoratedFileObject.moveTo(destFile);
+ }
+
+ public FileObject resolveFile(String name, NameScope scope) throws FileSystemException
+ {
+ return decoratedFileObject.resolveFile(name, scope);
+ }
+
+ public FileObject resolveFile(String path) throws FileSystemException
+ {
+ return decoratedFileObject.resolveFile(path);
+ }
+
+ public void refresh() throws FileSystemException
+ {
+ decoratedFileObject.refresh();
+ }
+
+ public FileObject getDecoratedFileObject()
+ {
+ return decoratedFileObject;
+ }
+
+ public boolean isAttached()
+ {
+ return decoratedFileObject.isAttached();
+ }
+
+ public boolean isContentOpen()
+ {
+ return decoratedFileObject.isContentOpen();
+ }
+
+ public String toString()
+ {
+ return decoratedFileObject.toString();
+ }
+}
\ No newline at end of file
Propchange: jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/impl/DecoratedFileObject.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/impl/DecoratedFileObject.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/impl/DecoratedFileObject.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/impl/DefaultFileSystemManager.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/impl/DefaultFileSystemManager.java?rev=390219&r1=390218&r2=390219&view=diff
==============================================================================
--- jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/impl/DefaultFileSystemManager.java (original)
+++ jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/impl/DefaultFileSystemManager.java Thu Mar 30 11:16:24 2006
@@ -16,6 +16,7 @@
package org.apache.commons.vfs.impl;
import org.apache.commons.logging.Log;
+import org.apache.commons.vfs.CacheStrategy;
import org.apache.commons.vfs.FileContentInfoFactory;
import org.apache.commons.vfs.FileName;
import org.apache.commons.vfs.FileObject;
@@ -93,6 +94,11 @@
private FilesCache filesCache;
/**
+ * The cache strategy
+ */
+ private CacheStrategy fileCacheStrategy;
+
+ /**
* The class to use to determine the content-type (mime-type)
*/
private FileContentInfoFactory fileContentInfoFactory;
@@ -225,7 +231,7 @@
/**
* Sets the filesCache implementation used to cache files
*/
- public void setFilesCache(FilesCache filesCache) throws FileSystemException
+ public void setFilesCache(final FilesCache filesCache) throws FileSystemException
{
if (init)
{
@@ -236,6 +242,35 @@
}
/**
+ * <p>
+ * Set the cache strategy to use when dealing with file object data.
+ * You can set it only once before the FileSystemManager is initialized.
+ * <p />
+ * <p>
+ * The default is {@link CacheStrategy#ON_RESOLVE}
+ * </p>
+ *
+ * @throws FileSystemException if this is not possible. e.g. it is already set.
+ */
+ public void setCacheStrategy(final CacheStrategy fileCacheStrategy) throws FileSystemException
+ {
+ if (init)
+ {
+ throw new FileSystemException("vfs.impl/already-inited.error");
+ }
+
+ this.fileCacheStrategy = fileCacheStrategy;
+ }
+
+ /**
+ * Get the cache strategy used
+ */
+ public CacheStrategy getCacheStrategy()
+ {
+ return fileCacheStrategy;
+ }
+
+ /**
* get the fileContentInfoFactory used to determine the infos of a file content.
*/
public FileContentInfoFactory getFileContentInfoFactory()
@@ -364,6 +399,11 @@
if (fileContentInfoFactory == null)
{
fileContentInfoFactory = new FileContentInfoFilenameFactory();
+ }
+
+ if (fileCacheStrategy == null)
+ {
+ fileCacheStrategy = CacheStrategy.ON_RESOLVE;
}
setupComponent(filesCache);
Modified: jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/AbstractFileObject.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/AbstractFileObject.java?rev=390219&r1=390218&r2=390219&view=diff
==============================================================================
--- jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/AbstractFileObject.java (original)
+++ jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/AbstractFileObject.java Thu Mar 30 11:16:24 2006
@@ -28,6 +28,7 @@
import org.apache.commons.vfs.NameScope;
import org.apache.commons.vfs.RandomAccessContent;
import org.apache.commons.vfs.Selectors;
+import org.apache.commons.vfs.util.FileObjectUtils;
import org.apache.commons.vfs.util.RandomAccessMode;
import java.io.IOException;
@@ -69,7 +70,7 @@
// Cached info
private boolean attached;
private FileType type;
- private AbstractFileObject parent;
+ private FileObject parent;
// Changed to hold only the name of the children and let the object
// go into the global files cache
@@ -500,7 +501,7 @@
// Locate the parent of this file
if (parent == null)
{
- parent = (AbstractFileObject) fs.resolveFile(name.getParent());
+ parent = (FileObject) fs.resolveFile(name.getParent());
}
}
return parent;
@@ -996,6 +997,22 @@
}
/**
+ * This will prepare the fileObject to get resynchronized with the underlaying filesystem if required
+ */
+ public void refresh() throws FileSystemException
+ {
+ // Detach from the file
+ try
+ {
+ detach();
+ }
+ catch (final Exception e)
+ {
+ throw new FileSystemException("vfs.provider/resync.error", name, e);
+ }
+ }
+
+ /**
* Closes this file, and its content.
*/
public void close() throws FileSystemException
@@ -1383,7 +1400,7 @@
if (parent != null)
{
- parent.childrenChanged(childName, newType);
+ FileObjectUtils.getAbstractFileObject(parent).childrenChanged(childName, newType);
}
}
Modified: jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/AbstractFileSystem.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/AbstractFileSystem.java?rev=390219&r1=390218&r2=390219&view=diff
==============================================================================
--- jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/AbstractFileSystem.java (original)
+++ jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/AbstractFileSystem.java Thu Mar 30 11:16:24 2006
@@ -17,6 +17,7 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.apache.commons.vfs.CacheStrategy;
import org.apache.commons.vfs.Capability;
import org.apache.commons.vfs.FileListener;
import org.apache.commons.vfs.FileName;
@@ -28,6 +29,7 @@
import org.apache.commons.vfs.FileSystemOptions;
import org.apache.commons.vfs.FilesCache;
import org.apache.commons.vfs.VfsLog;
+import org.apache.commons.vfs.cache.OnCallRefreshFileObject;
import org.apache.commons.vfs.events.AbstractFileChangeEvent;
import org.apache.commons.vfs.events.ChangedEvent;
import org.apache.commons.vfs.events.CreateEvent;
@@ -295,6 +297,8 @@
{
throw new FileSystemException("vfs.provider/resolve-file.error", name, e);
}
+
+ file = decorateFileObject(file);
// imario@apache.org ==> use putFileToCache
if (useCache)
@@ -303,10 +307,28 @@
}
// files.put(name, file);
}
+
+ /**
+ * resync the file information if requested
+ */
+ if (getFileSystemManager().getCacheStrategy().equals(CacheStrategy.ON_RESOLVE))
+ {
+ file.refresh();
+ }
return file;
}
- /**
+ protected FileObject decorateFileObject(FileObject file)
+ {
+ if (getFileSystemManager().getCacheStrategy().equals(CacheStrategy.ON_CALL))
+ {
+ return new OnCallRefreshFileObject(file);
+ }
+
+ return file;
+ }
+
+ /**
* Creates a temporary local copy of a file and its descendents.
*/
public File replicateFile(final FileObject file,
Added: jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/util/FileObjectUtils.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/util/FileObjectUtils.java?rev=390219&view=auto
==============================================================================
--- jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/util/FileObjectUtils.java (added)
+++ jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/util/FileObjectUtils.java Thu Mar 30 11:16:24 2006
@@ -0,0 +1,76 @@
+/*
+ * Copyright 2002-2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.vfs.util;
+
+import org.apache.commons.vfs.FileObject;
+import org.apache.commons.vfs.FileSystemException;
+import org.apache.commons.vfs.impl.DecoratedFileObject;
+import org.apache.commons.vfs.provider.AbstractFileObject;
+
+/**
+ * Stuff to get some strange things from an FileObject
+ *
+ * @author <a href="mailto:imario@apache.org">Mario Ivankovits</a>
+ * @version $Revision$ $Date$
+ */
+public class FileObjectUtils
+{
+ private FileObjectUtils()
+ {
+ }
+
+ /**
+ * get access to the base object even if decorated
+ */
+ public static AbstractFileObject getAbstractFileObject(final FileObject fileObject) throws FileSystemException
+ {
+ Object searchObject = fileObject;
+ while (searchObject instanceof DecoratedFileObject)
+ {
+ searchObject = ((DecoratedFileObject) searchObject).getDecoratedFileObject();
+ }
+ if (searchObject instanceof AbstractFileObject)
+ {
+ return (AbstractFileObject) searchObject;
+ }
+
+ throw new FileSystemException("vfs.util/find-abstract-file-object.error");
+ }
+
+ /**
+ * check if the given FileObject is instance of given class argument
+ */
+ public static boolean isInstanceOf(final FileObject fileObject, final Class wantedClass) throws FileSystemException
+ {
+ Object searchObject = fileObject;
+ while (searchObject instanceof DecoratedFileObject)
+ {
+ if (wantedClass.isInstance(searchObject))
+ {
+ return true;
+ }
+
+ searchObject = ((DecoratedFileObject) searchObject).getDecoratedFileObject();
+ }
+
+ if (wantedClass.isInstance(searchObject))
+ {
+ return true;
+ }
+
+ return false;
+ }
+}
Propchange: jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/util/FileObjectUtils.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/util/FileObjectUtils.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/util/FileObjectUtils.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: jakarta/commons/proper/vfs/trunk/src/test/org/apache/commons/vfs/test/AbstractProviderTestCase.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/vfs/trunk/src/test/org/apache/commons/vfs/test/AbstractProviderTestCase.java?rev=390219&r1=390218&r2=390219&view=diff
==============================================================================
--- jakarta/commons/proper/vfs/trunk/src/test/org/apache/commons/vfs/test/AbstractProviderTestCase.java (original)
+++ jakarta/commons/proper/vfs/trunk/src/test/org/apache/commons/vfs/test/AbstractProviderTestCase.java Thu Mar 30 11:16:24 2006
@@ -16,6 +16,7 @@
package org.apache.commons.vfs.test;
import org.apache.commons.AbstractVfsTestCase;
+import org.apache.commons.vfs.CacheStrategy;
import org.apache.commons.vfs.Capability;
import org.apache.commons.vfs.FileContent;
import org.apache.commons.vfs.FileObject;
@@ -23,6 +24,7 @@
import org.apache.commons.vfs.FileType;
import org.apache.commons.vfs.impl.DefaultFileSystemManager;
import org.apache.commons.vfs.provider.AbstractFileSystem;
+import org.apache.commons.vfs.provider.local.DefaultLocalFileProvider;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
@@ -48,6 +50,7 @@
private FileObject readFolder;
private FileObject writeFolder;
private DefaultFileSystemManager manager;
+ private ProviderTestConfig providerConfig;
private Method method;
// Expected contents of "file1.txt"
@@ -68,11 +71,13 @@
* Configures this test.
*/
public void setConfig(final DefaultFileSystemManager manager,
+ final ProviderTestConfig providerConfig,
final FileObject baseFolder,
final FileObject readFolder,
final FileObject writeFolder)
{
this.manager = manager;
+ this.providerConfig = providerConfig;
this.baseFolder = baseFolder;
this.readFolder = readFolder;
this.writeFolder = writeFolder;
@@ -87,6 +92,22 @@
}
/**
+ * creates a new uninitialized file system manager
+ * @throws Exception
+ */
+ protected DefaultFileSystemManager createManager() throws Exception
+ {
+ DefaultFileSystemManager fs = new DefaultFileSystemManager();
+ fs.setFilesCache(getProviderConfig().getFilesCache());
+ getProviderConfig().prepare(fs);
+ if (!fs.hasProvider("file"))
+ {
+ fs.addProvider("file", new DefaultLocalFileProvider());
+ }
+ return fs;
+ }
+
+ /**
* Returns the base test folder. This is the parent of both the read
* test and write test folders.
*/
@@ -94,8 +115,16 @@
{
return baseFolder;
}
-
+
/**
+ * get the provider configuration
+ */
+ public ProviderTestConfig getProviderConfig()
+ {
+ return providerConfig;
+ }
+
+ /**
* Returns the read test folder.
*/
protected FileObject getReadFolder()
Modified: jakarta/commons/proper/vfs/trunk/src/test/org/apache/commons/vfs/test/AbstractTestSuite.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/vfs/trunk/src/test/org/apache/commons/vfs/test/AbstractTestSuite.java?rev=390219&r1=390218&r2=390219&view=diff
==============================================================================
--- jakarta/commons/proper/vfs/trunk/src/test/org/apache/commons/vfs/test/AbstractTestSuite.java (original)
+++ jakarta/commons/proper/vfs/trunk/src/test/org/apache/commons/vfs/test/AbstractTestSuite.java Thu Mar 30 11:16:24 2006
@@ -168,7 +168,7 @@
if (test instanceof AbstractProviderTestCase)
{
final AbstractProviderTestCase providerTestCase = (AbstractProviderTestCase) test;
- providerTestCase.setConfig(manager, baseFolder, readFolder, writeFolder);
+ providerTestCase.setConfig(manager, providerConfig, baseFolder, readFolder, writeFolder);
}
}
}
Added: jakarta/commons/proper/vfs/trunk/src/test/org/apache/commons/vfs/test/ProviderCacheStrategyTests.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/vfs/trunk/src/test/org/apache/commons/vfs/test/ProviderCacheStrategyTests.java?rev=390219&view=auto
==============================================================================
--- jakarta/commons/proper/vfs/trunk/src/test/org/apache/commons/vfs/test/ProviderCacheStrategyTests.java (added)
+++ jakarta/commons/proper/vfs/trunk/src/test/org/apache/commons/vfs/test/ProviderCacheStrategyTests.java Thu Mar 30 11:16:24 2006
@@ -0,0 +1,145 @@
+/*
+ * Copyright 2002-20056 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.vfs.test;
+
+import org.apache.commons.vfs.CacheStrategy;
+import org.apache.commons.vfs.Capability;
+import org.apache.commons.vfs.FileObject;
+import org.apache.commons.vfs.Selectors;
+import org.apache.commons.vfs.impl.DefaultFileSystemManager;
+
+/**
+ * Test the cache stragey
+ *
+ * @author <a href="mailto:imario@apache.org">Mario Ivankovits</a>
+ */
+public class ProviderCacheStrategyTests
+ extends AbstractProviderTestCase
+{
+ /**
+ * Returns the capabilities required by the tests of this test case.
+ */
+ protected Capability[] getRequiredCaps()
+ {
+ return new Capability[]
+ {
+ Capability.CREATE,
+ Capability.GET_TYPE,
+ Capability.LIST_CHILDREN,
+ };
+ }
+
+ /**
+ * Test the manual cache strategy
+ */
+ public void testManualCache() throws Exception
+ {
+ FileObject scratchFolder = getWriteFolder();
+ scratchFolder.delete(Selectors.EXCLUDE_SELF);
+
+ DefaultFileSystemManager fs = createManager();
+ fs.setCacheStrategy(CacheStrategy.MANUAL);
+ fs.init();
+
+ FileObject cachedFolder = fs.resolveFile(scratchFolder.getName().getURI());
+
+ FileObject[] fos = cachedFolder.getChildren();
+ assertContainsNot(fos, "file1.txt");
+
+ scratchFolder.resolveFile("file1.txt").createFile();
+
+ fos = cachedFolder.getChildren();
+ assertContainsNot(fos, "file1.txt");
+
+ cachedFolder.refresh();
+ fos = cachedFolder.getChildren();
+ assertContains(fos, "file1.txt");
+ }
+
+ /**
+ * Test the on_resolve strategy
+ */
+ public void testOnResolveCache() throws Exception
+ {
+ FileObject scratchFolder = getWriteFolder();
+ scratchFolder.delete(Selectors.EXCLUDE_SELF);
+
+ DefaultFileSystemManager fs = createManager();
+ fs.setCacheStrategy(CacheStrategy.ON_RESOLVE);
+ fs.init();
+
+ FileObject cachedFolder = fs.resolveFile(scratchFolder.getName().getURI());
+
+ FileObject[] fos = cachedFolder.getChildren();
+ assertContainsNot(fos, "file1.txt");
+
+ scratchFolder.resolveFile("file1.txt").createFile();
+
+ fos = cachedFolder.getChildren();
+ assertContainsNot(fos, "file1.txt");
+
+ cachedFolder = fs.resolveFile(scratchFolder.getName().getURI());
+ fos = cachedFolder.getChildren();
+ assertContains(fos, "file1.txt");
+ }
+
+ /**
+ * Test the on_call strategy
+ */
+ public void testOnCallCache() throws Exception
+ {
+ FileObject scratchFolder = getWriteFolder();
+ scratchFolder.delete(Selectors.EXCLUDE_SELF);
+
+ DefaultFileSystemManager fs = createManager();
+ fs.setCacheStrategy(CacheStrategy.ON_CALL);
+ fs.init();
+
+ FileObject cachedFolder = fs.resolveFile(scratchFolder.getName().getURI());
+
+ FileObject[] fos = cachedFolder.getChildren();
+ assertContainsNot(fos, "file1.txt");
+
+ scratchFolder.resolveFile("file1.txt").createFile();
+
+ fos = cachedFolder.getChildren();
+ assertContains(fos, "file1.txt");
+ }
+
+ public void assertContainsNot(FileObject[] fos, String string)
+ {
+ for (int i = 0; i<fos.length; i++)
+ {
+ if (string.equals(fos[i].getName().getBaseName()))
+ {
+ fail(string + " should not be seen");
+ }
+ }
+ }
+
+ public void assertContains(FileObject[] fos, String string)
+ {
+ for (int i = 0; i<fos.length; i++)
+ {
+ if (string.equals(fos[i].getName().getBaseName()))
+ {
+ return;
+ }
+ }
+
+ fail(string + " should be seen");
+ }
+}
Propchange: jakarta/commons/proper/vfs/trunk/src/test/org/apache/commons/vfs/test/ProviderCacheStrategyTests.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: jakarta/commons/proper/vfs/trunk/src/test/org/apache/commons/vfs/test/ProviderCacheStrategyTests.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: jakarta/commons/proper/vfs/trunk/src/test/org/apache/commons/vfs/test/ProviderCacheStrategyTests.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: jakarta/commons/proper/vfs/trunk/src/test/org/apache/commons/vfs/test/ProviderTestSuite.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/vfs/trunk/src/test/org/apache/commons/vfs/test/ProviderTestSuite.java?rev=390219&r1=390218&r2=390219&view=diff
==============================================================================
--- jakarta/commons/proper/vfs/trunk/src/test/org/apache/commons/vfs/test/ProviderTestSuite.java (original)
+++ jakarta/commons/proper/vfs/trunk/src/test/org/apache/commons/vfs/test/ProviderTestSuite.java Thu Mar 30 11:16:24 2006
@@ -48,6 +48,7 @@
*/
protected void addBaseTests() throws Exception
{
+ addTests(ProviderCacheStrategyTests.class);
addTests(UriTests.class);
addTests(NamingTests.class);
addTests(ContentTests.class);
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org