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.impl;
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  
28  /**
29   * This decorator synchronize all access to the FileObject.
30   */
31  public class SynchronizedFileObject extends DecoratedFileObject
32  {
33      public SynchronizedFileObject(final FileObject fileObject)
34      {
35          super(fileObject);
36      }
37  
38      @Override
39      public void close() throws FileSystemException
40      {
41          synchronized (this)
42          {
43              super.close();
44          }
45      }
46  
47      @Override
48      public void copyFrom(final FileObject srcFile, final FileSelector selector) throws FileSystemException
49      {
50          synchronized (this)
51          {
52              super.copyFrom(srcFile, selector);
53          }
54      }
55  
56      @Override
57      public void createFile() throws FileSystemException
58      {
59          synchronized (this)
60          {
61              super.createFile();
62          }
63      }
64  
65      @Override
66      public void createFolder() throws FileSystemException
67      {
68          synchronized (this)
69          {
70              super.createFolder();
71          }
72      }
73  
74      @Override
75      public boolean delete() throws FileSystemException
76      {
77          synchronized (this)
78          {
79              return super.delete();
80          }
81      }
82  
83      @Override
84      public int delete(final FileSelector selector) throws FileSystemException
85      {
86          synchronized (this)
87          {
88              return super.delete(selector);
89          }
90      }
91  
92      @Override
93      public boolean exists() throws FileSystemException
94      {
95          synchronized (this)
96          {
97              return super.exists();
98          }
99      }
100 
101     @Override
102     public void findFiles(final FileSelector selector, final boolean depthwise, final List<FileObject> selected)
103             throws FileSystemException
104     {
105         synchronized (this)
106         {
107             super.findFiles(selector, depthwise, selected);
108         }
109     }
110 
111     @Override
112     public FileObject[] findFiles(final FileSelector selector) throws FileSystemException
113     {
114         synchronized (this)
115         {
116             return super.findFiles(selector);
117         }
118     }
119 
120     @Override
121     public FileObject getChild(final String name) throws FileSystemException
122     {
123         synchronized (this)
124         {
125             return super.getChild(name);
126         }
127     }
128 
129     @Override
130     public FileObject[] getChildren() throws FileSystemException
131     {
132         synchronized (this)
133         {
134             return super.getChildren();
135         }
136     }
137 
138     @Override
139     public FileContent getContent() throws FileSystemException
140     {
141         synchronized (this)
142         {
143             return super.getContent();
144         }
145     }
146 
147     @Override
148     public FileType getType() throws FileSystemException
149     {
150         synchronized (this)
151         {
152             return super.getType();
153         }
154     }
155 
156     @Override
157     public boolean isHidden() throws FileSystemException
158     {
159         synchronized (this)
160         {
161             return super.isHidden();
162         }
163     }
164 
165     @Override
166     public boolean isReadable() throws FileSystemException
167     {
168         synchronized (this)
169         {
170             return super.isReadable();
171         }
172     }
173 
174     @Override
175     public boolean isWriteable() throws FileSystemException
176     {
177         synchronized (this)
178         {
179             return super.isWriteable();
180         }
181     }
182 
183     @Override
184     public boolean isExecutable() throws FileSystemException
185     {
186         synchronized (this)
187         {
188             return super.isExecutable();
189         }
190     }
191 
192     @Override
193     public boolean setReadable(final boolean readable, final boolean ownerOnly) throws FileSystemException
194     {
195         synchronized (this)
196         {
197             return super.setReadable(readable, ownerOnly);
198         }
199     }
200 
201     @Override
202     public boolean setWritable(final boolean writable, final boolean ownerOnly) throws FileSystemException
203     {
204         synchronized (this)
205         {
206             return super.setWritable(writable, ownerOnly);
207         }
208     }
209 
210     @Override
211     public boolean setExecutable(final boolean executable, final boolean ownerOnly) throws FileSystemException
212     {
213         synchronized (this)
214         {
215             return super.setExecutable(executable, ownerOnly);
216         }
217     }
218 
219     @Override
220     public void moveTo(final FileObject destFile) throws FileSystemException
221     {
222         synchronized (this)
223         {
224             super.moveTo(destFile);
225         }
226     }
227 
228     @Override
229     public FileObject resolveFile(final String name, final NameScope scope) throws FileSystemException
230     {
231         synchronized (this)
232         {
233             return super.resolveFile(name, scope);
234         }
235     }
236 
237     @Override
238     public FileObject resolveFile(final String path) throws FileSystemException
239     {
240         synchronized (this)
241         {
242             return super.resolveFile(path);
243         }
244     }
245 }