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      {
36          super(fileObject);
37      }
38  
39      @Override
40      public void close() throws FileSystemException
41      {
42          refresh();
43          super.close();
44      }
45  
46      @Override
47      public void copyFrom(final FileObject srcFile, final FileSelector selector) throws FileSystemException
48      {
49          refresh();
50          super.copyFrom(srcFile, selector);
51      }
52  
53      @Override
54      public void createFile() throws FileSystemException
55      {
56          refresh();
57          super.createFile();
58      }
59  
60      @Override
61      public void createFolder() throws FileSystemException
62      {
63          refresh();
64          super.createFolder();
65      }
66  
67      @Override
68      public boolean delete() throws FileSystemException
69      {
70          refresh();
71          return super.delete();
72      }
73  
74      @Override
75      public int delete(final FileSelector selector) throws FileSystemException
76      {
77          refresh();
78          return super.delete(selector);
79      }
80  
81      @Override
82      public boolean exists() throws FileSystemException
83      {
84          refresh();
85          return super.exists();
86      }
87  
88      @Override
89      public void findFiles(final FileSelector selector, final boolean depthwise, final List<FileObject> selected)
90          throws FileSystemException
91      {
92          refresh();
93          super.findFiles(selector, depthwise, selected);
94      }
95  
96      @Override
97      public FileObject[] findFiles(final FileSelector selector) throws FileSystemException
98      {
99          refresh();
100         return super.findFiles(selector);
101     }
102 
103     @Override
104     public FileObject getChild(final String name) throws FileSystemException
105     {
106         refresh();
107         return super.getChild(name);
108     }
109 
110     @Override
111     public FileObject[] getChildren() throws FileSystemException
112     {
113         refresh();
114         return super.getChildren();
115     }
116 
117     @Override
118     public FileContent getContent() throws FileSystemException
119     {
120         refresh();
121         return super.getContent();
122     }
123 
124     @Override
125     public FileType getType() throws FileSystemException
126     {
127         refresh();
128         return super.getType();
129     }
130 
131     @Override
132     public boolean isExecutable() throws FileSystemException
133     {
134         refresh();
135         return super.isExecutable();
136     }
137 
138     @Override
139     public boolean isHidden() throws FileSystemException
140     {
141         refresh();
142         return super.isHidden();
143     }
144 
145     @Override
146     public boolean isReadable() throws FileSystemException
147     {
148         refresh();
149         return super.isReadable();
150     }
151 
152     @Override
153     public boolean isWriteable() throws FileSystemException
154     {
155         refresh();
156         return super.isWriteable();
157     }
158 
159     @Override
160     public boolean setExecutable(final boolean executable, final boolean ownerOnly) throws FileSystemException
161     {
162         refresh();
163         return super.setExecutable(executable, ownerOnly);
164     }
165 
166     @Override
167     public boolean setReadable(final boolean readable, final boolean ownerOnly) throws FileSystemException
168     {
169         refresh();
170         return super.setReadable(readable, ownerOnly);
171     }
172 
173     @Override
174     public boolean setWritable(final boolean writable, final boolean ownerOnly) throws FileSystemException
175     {
176         refresh();
177         return super.setWritable(writable, ownerOnly);
178     }
179 
180     @Override
181     public void moveTo(final FileObject destFile) throws FileSystemException
182     {
183         refresh();
184         super.moveTo(destFile);
185     }
186 
187     @Override
188     public FileObject resolveFile(final String name, final NameScope scope) throws FileSystemException
189     {
190         refresh();
191         return super.resolveFile(name, scope);
192     }
193 
194     @Override
195     public FileObject resolveFile(final String path) throws FileSystemException
196     {
197         refresh();
198         return super.resolveFile(path);
199     }
200 }