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 034 /** 035 * Constructs a new instance to decorate the given file object. 036 * 037 * @param fileObject The decorated. 038 */ 039 public OnCallRefreshFileObject(final FileObject fileObject) { 040 super(fileObject); 041 } 042 043 @Override 044 public void close() throws FileSystemException { 045 refresh(); 046 super.close(); 047 } 048 049 @Override 050 public void copyFrom(final FileObject srcFile, final FileSelector selector) throws FileSystemException { 051 refresh(); 052 super.copyFrom(srcFile, selector); 053 } 054 055 @Override 056 public void createFile() throws FileSystemException { 057 refresh(); 058 super.createFile(); 059 } 060 061 @Override 062 public void createFolder() throws FileSystemException { 063 refresh(); 064 super.createFolder(); 065 } 066 067 @Override 068 public boolean delete() throws FileSystemException { 069 refresh(); 070 return super.delete(); 071 } 072 073 @Override 074 public int delete(final FileSelector selector) throws FileSystemException { 075 refresh(); 076 return super.delete(selector); 077 } 078 079 @Override 080 public boolean exists() throws FileSystemException { 081 refresh(); 082 return super.exists(); 083 } 084 085 @Override 086 public FileObject[] findFiles(final FileSelector selector) throws FileSystemException { 087 refresh(); 088 return super.findFiles(selector); 089 } 090 091 @Override 092 public void findFiles(final FileSelector selector, final boolean depthwise, final List<FileObject> selected) 093 throws FileSystemException { 094 refresh(); 095 super.findFiles(selector, depthwise, selected); 096 } 097 098 @Override 099 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}