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.FileSystemConfigBuilder; 22 import org.apache.commons.vfs.FileSystemException; 23 import org.apache.commons.vfs.FileSystemOptions; 24 import org.apache.commons.vfs.provider.local.GenericFileNameParser; 25 26 import java.util.Iterator ; 27 import java.util.Map ; 28 import java.util.TreeMap ; 29 30 36 public abstract class AbstractFileProvider 37 extends AbstractVfsContainer 38 implements FileProvider 39 { 40 private FileNameParser parser; 41 42 public AbstractFileProvider() 43 { 44 parser = GenericFileNameParser.getInstance(); 45 } 46 47 protected FileNameParser getFileNameParser() 48 { 49 return parser; 50 } 51 52 protected void setFileNameParser(FileNameParser parser) 53 { 54 this.parser = parser; 55 } 56 57 61 private final Map fileSystems = new TreeMap (); 63 64 67 public void close() 68 { 69 synchronized (fileSystems) 70 { 71 fileSystems.clear(); 72 } 73 74 super.close(); 75 } 76 77 80 public FileObject createFileSystem(final String scheme, final FileObject file, final FileSystemOptions properties) 81 throws FileSystemException 82 { 83 throw new FileSystemException("vfs.provider/not-layered-fs.error", scheme); 85 } 86 87 91 protected void addFileSystem(final Comparable key, final FileSystem fs) 92 throws FileSystemException 93 { 94 addComponent(fs); 96 97 FileSystemKey treeKey = new FileSystemKey(key, fs.getFileSystemOptions()); 98 ((AbstractFileSystem) fs).setCacheKey(treeKey); 99 100 synchronized (fileSystems) 101 { 102 fileSystems.put(treeKey, fs); 103 } 104 } 105 106 111 protected FileSystem findFileSystem(final Comparable key, final FileSystemOptions fileSystemProps) 112 { 113 FileSystemKey treeKey = new FileSystemKey(key, fileSystemProps); 114 115 synchronized (fileSystems) 116 { 117 return (FileSystem) fileSystems.get(treeKey); 118 } 119 } 120 121 public FileSystemConfigBuilder getConfigBuilder() 122 { 123 return null; 124 } 125 126 public void freeUnusedResources() 127 { 128 Object [] item; 129 synchronized (fileSystems) 130 { 131 item = fileSystems.values().toArray(); 132 } 133 for (int i = 0; i < item.length; ++i) 134 { 135 AbstractFileSystem fs = (AbstractFileSystem) item[i]; 136 if (fs.isReleaseable()) 137 { 138 fs.closeCommunicationLink(); 139 } 140 } 141 } 142 143 public void closeFileSystem(final FileSystem filesystem) 144 { 145 AbstractFileSystem fs = (AbstractFileSystem) filesystem; 146 147 synchronized (fileSystems) 148 { 149 fileSystems.remove(fs.getCacheKey()); 150 } 151 152 removeComponent(fs); 153 fs.close(); 154 } 155 156 162 public FileName parseUri(FileName base, String uri) throws FileSystemException 163 { 164 if (getFileNameParser() != null) 165 { 166 return getFileNameParser().parseUri(getContext(), base, uri); 167 } 168 169 throw new FileSystemException("vfs.provider/filename-parser-missing.error"); 170 } 172 } 173 | Popular Tags |