View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.apache.commons.vfs2.cache;
18  
19  import java.util.List;
20  
21  import org.apache.commons.vfs2.FileContent;
22  import org.apache.commons.vfs2.FileObject;
23  import org.apache.commons.vfs2.FileSelector;
24  import org.apache.commons.vfs2.FileSystemException;
25  import org.apache.commons.vfs2.FileType;
26  import org.apache.commons.vfs2.NameScope;
27  import org.apache.commons.vfs2.impl.DecoratedFileObject;
28  
29  /**
30   * This decorator refreshes the fileObject data on every call.
31   */
32  public class OnCallRefreshFileObject extends DecoratedFileObject {
33  
34      public OnCallRefreshFileObject(final FileObject fileObject) {
35          super(fileObject);
36      }
37  
38      @Override
39      public void close() throws FileSystemException {
40          refresh();
41          super.close();
42      }
43  
44      @Override
45      public void copyFrom(final FileObject srcFile, final FileSelector selector) throws FileSystemException {
46          refresh();
47          super.copyFrom(srcFile, selector);
48      }
49  
50      @Override
51      public void createFile() throws FileSystemException {
52          refresh();
53          super.createFile();
54      }
55  
56      @Override
57      public void createFolder() throws FileSystemException {
58          refresh();
59          super.createFolder();
60      }
61  
62      @Override
63      public boolean delete() throws FileSystemException {
64          refresh();
65          return super.delete();
66      }
67  
68      @Override
69      public int delete(final FileSelector selector) throws FileSystemException {
70          refresh();
71          return super.delete(selector);
72      }
73  
74      @Override
75      public boolean exists() throws FileSystemException {
76          refresh();
77          return super.exists();
78      }
79  
80      @Override
81      public void findFiles(final FileSelector selector, final boolean depthwise, final List<FileObject> selected)
82              throws FileSystemException {
83          refresh();
84          super.findFiles(selector, depthwise, selected);
85      }
86  
87      @Override
88      public FileObject[] findFiles(final FileSelector selector) throws FileSystemException {
89          refresh();
90          return super.findFiles(selector);
91      }
92  
93      @Override
94      public FileObject getChild(final String name) throws FileSystemException {
95          refresh();
96          return super.getChild(name);
97      }
98  
99      @Override
100     public FileObject[] getChildren() throws FileSystemException {
101         refresh();
102         return super.getChildren();
103     }
104 
105     @Override
106     public FileContent getContent() throws FileSystemException {
107         refresh();
108         return super.getContent();
109     }
110 
111     @Override
112     public FileType getType() throws FileSystemException {
113         refresh();
114         return super.getType();
115     }
116 
117     @Override
118     public boolean isExecutable() throws FileSystemException {
119         refresh();
120         return super.isExecutable();
121     }
122 
123     @Override
124     public boolean isHidden() throws FileSystemException {
125         refresh();
126         return super.isHidden();
127     }
128 
129     @Override
130     public boolean isReadable() throws FileSystemException {
131         refresh();
132         return super.isReadable();
133     }
134 
135     @Override
136     public boolean isWriteable() throws FileSystemException {
137         refresh();
138         return super.isWriteable();
139     }
140 
141     @Override
142     public boolean setExecutable(final boolean executable, final boolean ownerOnly) throws FileSystemException {
143         refresh();
144         return super.setExecutable(executable, ownerOnly);
145     }
146 
147     @Override
148     public boolean setReadable(final boolean readable, final boolean ownerOnly) throws FileSystemException {
149         refresh();
150         return super.setReadable(readable, ownerOnly);
151     }
152 
153     @Override
154     public boolean setWritable(final boolean writable, final boolean ownerOnly) throws FileSystemException {
155         refresh();
156         return super.setWritable(writable, ownerOnly);
157     }
158 
159     @Override
160     public void moveTo(final FileObject destFile) throws FileSystemException {
161         refresh();
162         super.moveTo(destFile);
163     }
164 
165     @Override
166     public FileObject resolveFile(final String name, final NameScope scope) throws FileSystemException {
167         refresh();
168         return super.resolveFile(name, scope);
169     }
170 
171     @Override
172     public FileObject resolveFile(final String path) throws FileSystemException {
173         refresh();
174         return super.resolveFile(path);
175     }
176 }