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          super(fileObject);
35      }
36  
37      @Override
38      public void close() throws FileSystemException {
39          synchronized (this) {
40              super.close();
41          }
42      }
43  
44      @Override
45      public void copyFrom(final FileObject srcFile, final FileSelector selector) throws FileSystemException {
46          synchronized (this) {
47              super.copyFrom(srcFile, selector);
48          }
49      }
50  
51      @Override
52      public void createFile() throws FileSystemException {
53          synchronized (this) {
54              super.createFile();
55          }
56      }
57  
58      @Override
59      public void createFolder() throws FileSystemException {
60          synchronized (this) {
61              super.createFolder();
62          }
63      }
64  
65      @Override
66      public boolean delete() throws FileSystemException {
67          synchronized (this) {
68              return super.delete();
69          }
70      }
71  
72      @Override
73      public int delete(final FileSelector selector) throws FileSystemException {
74          synchronized (this) {
75              return super.delete(selector);
76          }
77      }
78  
79      @Override
80      public boolean exists() throws FileSystemException {
81          synchronized (this) {
82              return super.exists();
83          }
84      }
85  
86      @Override
87      public void findFiles(final FileSelector selector, final boolean depthwise, final List<FileObject> selected)
88              throws FileSystemException {
89          synchronized (this) {
90              super.findFiles(selector, depthwise, selected);
91          }
92      }
93  
94      @Override
95      public FileObject[] findFiles(final FileSelector selector) throws FileSystemException {
96          synchronized (this) {
97              return super.findFiles(selector);
98          }
99      }
100 
101     @Override
102     public FileObject getChild(final String name) throws FileSystemException {
103         synchronized (this) {
104             return super.getChild(name);
105         }
106     }
107 
108     @Override
109     public FileObject[] getChildren() throws FileSystemException {
110         synchronized (this) {
111             return super.getChildren();
112         }
113     }
114 
115     @Override
116     public FileContent getContent() throws FileSystemException {
117         synchronized (this) {
118             return super.getContent();
119         }
120     }
121 
122     @Override
123     public FileType getType() throws FileSystemException {
124         synchronized (this) {
125             return super.getType();
126         }
127     }
128 
129     @Override
130     public boolean isHidden() throws FileSystemException {
131         synchronized (this) {
132             return super.isHidden();
133         }
134     }
135 
136     @Override
137     public boolean isReadable() throws FileSystemException {
138         synchronized (this) {
139             return super.isReadable();
140         }
141     }
142 
143     @Override
144     public boolean isWriteable() throws FileSystemException {
145         synchronized (this) {
146             return super.isWriteable();
147         }
148     }
149 
150     @Override
151     public boolean isExecutable() throws FileSystemException {
152         synchronized (this) {
153             return super.isExecutable();
154         }
155     }
156 
157     @Override
158     public boolean setReadable(final boolean readable, final boolean ownerOnly) throws FileSystemException {
159         synchronized (this) {
160             return super.setReadable(readable, ownerOnly);
161         }
162     }
163 
164     @Override
165     public boolean setWritable(final boolean writable, final boolean ownerOnly) throws FileSystemException {
166         synchronized (this) {
167             return super.setWritable(writable, ownerOnly);
168         }
169     }
170 
171     @Override
172     public boolean setExecutable(final boolean executable, final boolean ownerOnly) throws FileSystemException {
173         synchronized (this) {
174             return super.setExecutable(executable, ownerOnly);
175         }
176     }
177 
178     @Override
179     public void moveTo(final FileObject destFile) throws FileSystemException {
180         synchronized (this) {
181             super.moveTo(destFile);
182         }
183     }
184 
185     @Override
186     public FileObject resolveFile(final String name, final NameScope scope) throws FileSystemException {
187         synchronized (this) {
188             return super.resolveFile(name, scope);
189         }
190     }
191 
192     @Override
193     public FileObject resolveFile(final String path) throws FileSystemException {
194         synchronized (this) {
195             return super.resolveFile(path);
196         }
197     }
198 }