1 16 package org.apache.commons.vfs.provider; 17 18 import org.apache.commons.vfs.FileName; 19 import org.apache.commons.vfs.FileObject; 20 import org.apache.commons.vfs.FileSystem; 21 import org.apache.commons.vfs.FileSystemException; 22 import org.apache.commons.vfs.FileSystemOptions; 23 24 30 public abstract class AbstractLayeredFileProvider 31 extends AbstractFileProvider 32 implements FileProvider 33 { 34 public AbstractLayeredFileProvider() 35 { 36 super(); 37 setFileNameParser(LayeredFileNameParser.getInstance()); 38 } 39 40 43 public FileObject findFile(final FileObject baseFile, 44 final String uri, 45 final FileSystemOptions properties) throws FileSystemException 46 { 47 final LayeredFileName name = (LayeredFileName) parseUri(baseFile!=null?baseFile.getName():null, uri); 49 50 52 final FileName fileName = name.getOuterName(); 54 final FileObject file = getContext().resolveFile(baseFile, fileName.getURI(), properties); 55 56 final FileObject rootFile = createFileSystem(name.getScheme(), file, properties); 58 59 return rootFile.resolveFile(name.getPath()); 61 } 62 63 66 public synchronized FileObject createFileSystem(final String scheme, 67 final FileObject file, 68 final FileSystemOptions fileSystemOptions) 69 throws FileSystemException 70 { 71 final FileName rootName = file.getName(); 73 FileSystem fs = findFileSystem(rootName, null); 74 if (fs == null) 75 { 76 fs = doCreateFileSystem(scheme, file, fileSystemOptions); 78 addFileSystem(rootName, fs); 79 } 80 return fs.getRoot(); 81 } 82 83 91 protected abstract FileSystem doCreateFileSystem(final String scheme, 92 final FileObject file, 93 final FileSystemOptions fileSystemOptions) 94 throws FileSystemException; 95 96 } 97 | Popular Tags |