KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > vfs > cache > DefaultFilesCache


1 /*
2  * Copyright 2002-2005 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.commons.vfs.cache;
17
18 import org.apache.commons.vfs.FileName;
19 import org.apache.commons.vfs.FileObject;
20 import org.apache.commons.vfs.FileSystem;
21
22 import java.util.HashMap JavaDoc;
23 import java.util.Map JavaDoc;
24 import java.util.TreeMap JavaDoc;
25
26 /**
27  * A {@link org.apache.commons.vfs.FilesCache} implementation.<br>
28  * This implementation caches every file for the complete lifetime of the used {@link org.apache.commons.vfs.FileSystemManager}.
29  *
30  * @author <a HREF="mailto:imario@apache.org">Mario Ivankovits</a>
31  */

32 public class DefaultFilesCache extends AbstractFilesCache
33 {
34     private final Map JavaDoc filesystemCache = new HashMap JavaDoc(10);
35
36     public void putFile(final FileObject file)
37     {
38         Map JavaDoc files = getOrCreateFilesystemCache(file.getFileSystem());
39         files.put(file.getName(), file);
40     }
41
42     public FileObject getFile(final FileSystem filesystem, final FileName name)
43     {
44         Map JavaDoc files = getOrCreateFilesystemCache(filesystem);
45         return (FileObject) files.get(name);
46     }
47
48     public void clear(FileSystem filesystem)
49     {
50         Map JavaDoc files = getOrCreateFilesystemCache(filesystem);
51         files.clear();
52     }
53
54     protected Map JavaDoc getOrCreateFilesystemCache(FileSystem filesystem)
55     {
56         Map JavaDoc files = (Map JavaDoc) filesystemCache.get(filesystem);
57         if (files == null)
58         {
59             files = new TreeMap JavaDoc();
60             filesystemCache.put(filesystem, files);
61         }
62
63         return files;
64     }
65
66     public void close()
67     {
68         super.close();
69
70         filesystemCache.clear();
71     }
72
73     public void removeFile(FileSystem filesystem, FileName name)
74     {
75         Map JavaDoc files = getOrCreateFilesystemCache(filesystem);
76         files.remove(name);
77     }
78
79     public void touchFile(FileObject file)
80     {
81     }
82 }
83
Popular Tags