| 1 | |
package org.webslinger.commons.vfs.flat; |
| 2 | |
|
| 3 | |
import java.util.Arrays; |
| 4 | |
import java.util.Collection; |
| 5 | |
import java.util.HashMap; |
| 6 | |
import java.util.Map; |
| 7 | |
|
| 8 | |
import org.apache.commons.vfs.FileObject; |
| 9 | |
import org.apache.commons.vfs.FileSystemException; |
| 10 | |
import org.apache.commons.vfs.operations.FileOperation; |
| 11 | |
import org.apache.commons.vfs.operations.FileOperationProvider; |
| 12 | |
|
| 13 | |
import org.webslinger.commons.vfs.operations.AttributeValueOperation; |
| 14 | |
import org.webslinger.commons.vfs.operations.RealFileOperationProvider; |
| 15 | |
import org.webslinger.commons.vfs.operations.FileOperationFactory; |
| 16 | |
|
| 17 | 1 | public class FlatFileOperationProvider extends RealFileOperationProvider<FlatFileObject> { |
| 18 | 1 | private static final Map<Class, FileOperationFactory<FlatFileObject>> factories = new HashMap<Class, FileOperationFactory<FlatFileObject>>(); |
| 19 | |
static { |
| 20 | 2 | factories.put(AttributeValueOperation.class, new FileOperationFactory<FlatFileObject>() { |
| 21 | |
public FileOperation getFileOperation(final FlatFileObject file) throws FileSystemException { |
| 22 | 1 | return file.ATTRIBUTE_VALUE_OPERATION; |
| 23 | |
} |
| 24 | |
}); |
| 25 | 1 | } |
| 26 | |
|
| 27 | |
public FlatFileOperationProvider() { |
| 28 | 47 | super(FlatFileObject.class); |
| 29 | 47 | } |
| 30 | |
|
| 31 | |
public void collectOperations(Collection operationsList, FileObject file) throws FileSystemException { |
| 32 | 1 | super.collectOperations(operationsList, file); |
| 33 | 1 | operationsList.addAll(factories.keySet()); |
| 34 | 1 | } |
| 35 | |
|
| 36 | |
public FileOperation getOperation(FileObject file, Class operationClass) throws FileSystemException { |
| 37 | 1 | FileOperationFactory<FlatFileObject> factory = factories.get(operationClass); |
| 38 | 1 | if (factory == null) return super.getOperation(file, operationClass); |
| 39 | 1 | return factory.getFileOperation((FlatFileObject) file); |
| 40 | |
} |
| 41 | |
|
| 42 | |
protected void collectRealOperations(Collection<Class<? extends FileOperation>> operationsList, FlatFileObject file) throws FileSystemException { |
| 43 | 1 | collectOperationsWorker(operationsList, file.getRealFile()); |
| 44 | 1 | } |
| 45 | |
|
| 46 | |
protected FileOperation getRealOperation(FlatFileObject file, Class<? extends FileOperation> operationClass) throws FileSystemException { |
| 47 | 0 | return getOperationWorker(file.getRealFile(), operationClass); |
| 48 | |
} |
| 49 | |
} |