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 synchronizes all access to the FileObject.
30   */
31  public class SynchronizedFileObject extends DecoratedFileObject {
32  
33      /**
34       * Constructs a new instance.
35       *
36       * @param fileObject The FileObject to decorate.
37       */
38      public SynchronizedFileObject(final FileObject fileObject) {
39          super(fileObject);
40      }
41  
42      @Override
43      public void close() throws FileSystemException {
44          synchronized (this) {
45              super.close();
46          }
47      }
48  
49      @Override
50      public void copyFrom(final FileObject srcFile, final FileSelector selector) throws FileSystemException {
51          synchronized (this) {
52              super.copyFrom(srcFile, selector);
53          }
54      }
55  
56      @Override
57      public void createFile() throws FileSystemException {
58          synchronized (this) {
59              super.createFile();
60          }
61      }
62  
63      @Override
64      public void createFolder() throws FileSystemException {
65          synchronized (this) {
66              super.createFolder();
67          }
68      }
69  
70      @Override
71      public boolean delete() throws FileSystemException {
72          synchronized (this) {
73              return super.delete();
74          }
75      }
76  
77      @Override
78      public int delete(final FileSelector selector) throws FileSystemException {
79          synchronized (this) {
80              return super.delete(selector);
81          }
82      }
83  
84      @Override
85      public boolean exists() throws FileSystemException {
86          synchronized (this) {
87              return super.exists();
88          }
89      }
90  
91      @Override
92      public FileObject[] findFiles(final FileSelector selector) throws FileSystemException {
93          synchronized (this) {
94              return super.findFiles(selector);
95          }
96      }
97  
98      @Override
99      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 }