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