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