001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.commons.vfs2.cache;
018
019import java.util.List;
020
021import org.apache.commons.vfs2.FileContent;
022import org.apache.commons.vfs2.FileObject;
023import org.apache.commons.vfs2.FileSelector;
024import org.apache.commons.vfs2.FileSystemException;
025import org.apache.commons.vfs2.FileType;
026import org.apache.commons.vfs2.NameScope;
027import org.apache.commons.vfs2.impl.DecoratedFileObject;
028
029/**
030 * This decorator refreshes the fileObject data on every call.
031 */
032public class OnCallRefreshFileObject extends DecoratedFileObject {
033    public OnCallRefreshFileObject(final FileObject fileObject) {
034        super(fileObject);
035    }
036
037    @Override
038    public void close() throws FileSystemException {
039        refresh();
040        super.close();
041    }
042
043    @Override
044    public void copyFrom(final FileObject srcFile, final FileSelector selector) throws FileSystemException {
045        refresh();
046        super.copyFrom(srcFile, selector);
047    }
048
049    @Override
050    public void createFile() throws FileSystemException {
051        refresh();
052        super.createFile();
053    }
054
055    @Override
056    public void createFolder() throws FileSystemException {
057        refresh();
058        super.createFolder();
059    }
060
061    @Override
062    public boolean delete() throws FileSystemException {
063        refresh();
064        return super.delete();
065    }
066
067    @Override
068    public int delete(final FileSelector selector) throws FileSystemException {
069        refresh();
070        return super.delete(selector);
071    }
072
073    @Override
074    public boolean exists() throws FileSystemException {
075        refresh();
076        return super.exists();
077    }
078
079    @Override
080    public void findFiles(final FileSelector selector, final boolean depthwise, final List<FileObject> selected)
081            throws FileSystemException {
082        refresh();
083        super.findFiles(selector, depthwise, selected);
084    }
085
086    @Override
087    public FileObject[] findFiles(final FileSelector selector) throws FileSystemException {
088        refresh();
089        return super.findFiles(selector);
090    }
091
092    @Override
093    public FileObject getChild(final String name) throws FileSystemException {
094        refresh();
095        return super.getChild(name);
096    }
097
098    @Override
099    public FileObject[] getChildren() throws FileSystemException {
100        refresh();
101        return super.getChildren();
102    }
103
104    @Override
105    public FileContent getContent() throws FileSystemException {
106        refresh();
107        return super.getContent();
108    }
109
110    @Override
111    public FileType getType() throws FileSystemException {
112        refresh();
113        return super.getType();
114    }
115
116    @Override
117    public boolean isExecutable() throws FileSystemException {
118        refresh();
119        return super.isExecutable();
120    }
121
122    @Override
123    public boolean isHidden() throws FileSystemException {
124        refresh();
125        return super.isHidden();
126    }
127
128    @Override
129    public boolean isReadable() throws FileSystemException {
130        refresh();
131        return super.isReadable();
132    }
133
134    @Override
135    public boolean isWriteable() throws FileSystemException {
136        refresh();
137        return super.isWriteable();
138    }
139
140    @Override
141    public boolean setExecutable(final boolean executable, final boolean ownerOnly) throws FileSystemException {
142        refresh();
143        return super.setExecutable(executable, ownerOnly);
144    }
145
146    @Override
147    public boolean setReadable(final boolean readable, final boolean ownerOnly) throws FileSystemException {
148        refresh();
149        return super.setReadable(readable, ownerOnly);
150    }
151
152    @Override
153    public boolean setWritable(final boolean writable, final boolean ownerOnly) throws FileSystemException {
154        refresh();
155        return super.setWritable(writable, ownerOnly);
156    }
157
158    @Override
159    public void moveTo(final FileObject destFile) throws FileSystemException {
160        refresh();
161        super.moveTo(destFile);
162    }
163
164    @Override
165    public FileObject resolveFile(final String name, final NameScope scope) throws FileSystemException {
166        refresh();
167        return super.resolveFile(name, scope);
168    }
169
170    @Override
171    public FileObject resolveFile(final String path) throws FileSystemException {
172        refresh();
173        return super.resolveFile(path);
174    }
175}