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.impl; 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; 027 028/** 029 * This decorator synchronizes all access to the FileObject. 030 */ 031public class SynchronizedFileObject extends DecoratedFileObject { 032 033 /** 034 * Constructs a new instance. 035 * 036 * @param fileObject The FileObject to decorate. 037 */ 038 public SynchronizedFileObject(final FileObject fileObject) { 039 super(fileObject); 040 } 041 042 @Override 043 public void close() throws FileSystemException { 044 synchronized (this) { 045 super.close(); 046 } 047 } 048 049 @Override 050 public void copyFrom(final FileObject srcFile, final FileSelector selector) throws FileSystemException { 051 synchronized (this) { 052 super.copyFrom(srcFile, selector); 053 } 054 } 055 056 @Override 057 public void createFile() throws FileSystemException { 058 synchronized (this) { 059 super.createFile(); 060 } 061 } 062 063 @Override 064 public void createFolder() throws FileSystemException { 065 synchronized (this) { 066 super.createFolder(); 067 } 068 } 069 070 @Override 071 public boolean delete() throws FileSystemException { 072 synchronized (this) { 073 return super.delete(); 074 } 075 } 076 077 @Override 078 public int delete(final FileSelector selector) throws FileSystemException { 079 synchronized (this) { 080 return super.delete(selector); 081 } 082 } 083 084 @Override 085 public boolean exists() throws FileSystemException { 086 synchronized (this) { 087 return super.exists(); 088 } 089 } 090 091 @Override 092 public FileObject[] findFiles(final FileSelector selector) throws FileSystemException { 093 synchronized (this) { 094 return super.findFiles(selector); 095 } 096 } 097 098 @Override 099 public void findFiles(final FileSelector selector, final boolean depthwise, final List<FileObject> selected) 100 throws FileSystemException { 101 synchronized (this) { 102 super.findFiles(selector, depthwise, selected); 103 } 104 } 105 106 @Override 107 public FileObject getChild(final String name) throws FileSystemException { 108 synchronized (this) { 109 return super.getChild(name); 110 } 111 } 112 113 @Override 114 public FileObject[] getChildren() throws FileSystemException { 115 synchronized (this) { 116 return super.getChildren(); 117 } 118 } 119 120 @Override 121 public FileContent getContent() throws FileSystemException { 122 synchronized (this) { 123 return super.getContent(); 124 } 125 } 126 127 @Override 128 public FileType getType() throws FileSystemException { 129 synchronized (this) { 130 return super.getType(); 131 } 132 } 133 134 @Override 135 public boolean isExecutable() throws FileSystemException { 136 synchronized (this) { 137 return super.isExecutable(); 138 } 139 } 140 141 @Override 142 public boolean isHidden() throws FileSystemException { 143 synchronized (this) { 144 return super.isHidden(); 145 } 146 } 147 148 @Override 149 public boolean isReadable() throws FileSystemException { 150 synchronized (this) { 151 return super.isReadable(); 152 } 153 } 154 155 @Override 156 public boolean isWriteable() throws FileSystemException { 157 synchronized (this) { 158 return super.isWriteable(); 159 } 160 } 161 162 @Override 163 public void moveTo(final FileObject destFile) throws FileSystemException { 164 synchronized (this) { 165 super.moveTo(destFile); 166 } 167 } 168 169 @Override 170 public FileObject resolveFile(final String path) throws FileSystemException { 171 synchronized (this) { 172 return super.resolveFile(path); 173 } 174 } 175 176 @Override 177 public FileObject resolveFile(final String name, final NameScope scope) throws FileSystemException { 178 synchronized (this) { 179 return super.resolveFile(name, scope); 180 } 181 } 182 183 @Override 184 public boolean setExecutable(final boolean executable, final boolean ownerOnly) throws FileSystemException { 185 synchronized (this) { 186 return super.setExecutable(executable, ownerOnly); 187 } 188 } 189 190 @Override 191 public boolean setReadable(final boolean readable, final boolean ownerOnly) throws FileSystemException { 192 synchronized (this) { 193 return super.setReadable(readable, ownerOnly); 194 } 195 } 196 197 @Override 198 public boolean setWritable(final boolean writable, final boolean ownerOnly) throws FileSystemException { 199 synchronized (this) { 200 return super.setWritable(writable, ownerOnly); 201 } 202 } 203}