KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > core > filesystem > EFS


1 /*******************************************************************************
2  * Copyright (c) 2005, 2007 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  * Martin Oberhuber (Wind River) - [170317] add symbolic link support to API
11  *******************************************************************************/

12 package org.eclipse.core.filesystem;
13
14 import java.net.URI JavaDoc;
15 import org.eclipse.core.filesystem.provider.FileInfo;
16 import org.eclipse.core.internal.filesystem.InternalFileSystemCore;
17 import org.eclipse.core.runtime.CoreException;
18 import org.eclipse.core.runtime.IProgressMonitor;
19
20 /**
21  * This class is the main entry point for clients of the Eclipse file system API. This
22  * class has factory methods for obtaining instances of file systems and file
23  * stores, and provides constants for option values and error codes.
24  * <p>
25  * This class is not intended to be instantiated or subclassed.
26  * </p>
27  * @since org.eclipse.core.filesystem 1.0
28  */

29 public class EFS {
30     /**
31      * The unique identifier constant (value "<code>org.eclipse.core.filesystem</code>")
32      * of the Core file system plug-in.
33      */

34     public static final String JavaDoc PI_FILE_SYSTEM = "org.eclipse.core.filesystem"; //$NON-NLS-1$
35

36     /**
37      * The simple identifier constant (value "<code>filesystems</code>") of
38      * the extension point of the Core file system plug-in where plug-ins declare
39      * file system implementations.
40      */

41     public static final String JavaDoc PT_FILE_SYSTEMS = "filesystems"; //$NON-NLS-1$
42

43     /**
44      * A constant known to be zero (0), used in operations which
45      * take bit flags to indicate that "no bits are set". This value is
46      * also used as a default value in cases where a file system attribute
47      * cannot be computed.
48      *
49      * @see IFileInfo#getLength()
50      * @see IFileInfo#getLastModified()
51      */

52     public static final int NONE = 0;
53
54     /**
55      * Option flag constant (value 1 &lt;&lt;0) indicating a file opened
56      * for appending data to the end.
57      *
58      * @see IFileStore#openOutputStream(int, IProgressMonitor)
59      */

60     public static final int APPEND = 1 << 0;
61
62     /**
63      * Option flag constant (value 1 &lt;&lt;1) indicating that existing
64      * files may be overwritten.
65      *
66      * @see IFileStore#copy(IFileStore, int, IProgressMonitor)
67      * @see IFileStore#move(IFileStore, int, IProgressMonitor)
68      */

69     public static final int OVERWRITE = 1 << 1;
70
71     /**
72      * Option flag constant (value 1 &lt;&lt;2) indicating that an
73      * operation acts on a single file or directory, and not its parents
74      * or children.
75      *
76      * @see IFileStore#copy(IFileStore, int, IProgressMonitor)
77      * @see IFileStore#mkdir(int, IProgressMonitor)
78      */

79     public static final int SHALLOW = 1 << 2;
80
81     /**
82      * Option flag constant (value 1 &lt;&lt;10) indicating that a
83      * file's attributes should be updated.
84      *
85      * @see IFileStore#putInfo(IFileInfo, int, IProgressMonitor)
86      */

87     public static final int SET_ATTRIBUTES = 1 << 10;
88
89     /**
90      * Option flag constant (value 1 &lt;&lt;11) indicating that a
91      * file's last modified time should be updated.
92      *
93      * @see IFileStore#putInfo(IFileInfo, int, IProgressMonitor)
94      */

95     public static final int SET_LAST_MODIFIED = 1 << 11;
96
97     /**
98      * Option flag constant (value 1 &lt;&lt;12) indicating that
99      * a cached representation of a file should be returned.
100      *
101      * @see IFileStore#toLocalFile(int, IProgressMonitor)
102      */

103     public static final int CACHE = 1 << 12;
104
105     /**
106      * Attribute constant (value 1 &lt;&lt;1) indicating that a
107      * file is read only.
108      *
109      * @see IFileStore#fetchInfo()
110      * @see IFileStore#putInfo(IFileInfo, int, IProgressMonitor)
111      * @see IFileInfo#getAttribute(int)
112      * @see IFileInfo#setAttribute(int, boolean)
113      */

114     public static final int ATTRIBUTE_READ_ONLY = 1 << 1;
115
116     /**
117      * Attribute constant (value 1 &lt;&lt;2) indicating that a
118      * file is a executable.
119      *
120      * @see IFileStore#fetchInfo()
121      * @see IFileStore#putInfo(IFileInfo, int, IProgressMonitor)
122      * @see IFileInfo#getAttribute(int)
123      * @see IFileInfo#setAttribute(int, boolean)
124      */

125     public static final int ATTRIBUTE_EXECUTABLE = 1 << 2;
126
127     /**
128      * Attribute constant (value 1 &lt;&lt;3) indicating that a
129      * file is an archive.
130      *
131      * @see IFileStore#fetchInfo()
132      * @see IFileStore#putInfo(IFileInfo, int, IProgressMonitor)
133      * @see IFileInfo#getAttribute(int)
134      * @see IFileInfo#setAttribute(int, boolean)
135      */

136     public static final int ATTRIBUTE_ARCHIVE = 1 << 3;
137
138     /**
139      * Attribute constant (value 1 &lt;&lt;4) indicating that a
140      * file is hidden.
141      *
142      * @see IFileStore#fetchInfo()
143      * @see IFileStore#putInfo(IFileInfo, int, IProgressMonitor)
144      * @see IFileInfo#getAttribute(int)
145      * @see IFileInfo#setAttribute(int, boolean)
146      */

147     public static final int ATTRIBUTE_HIDDEN = 1 << 4;
148
149     /**
150      * Attribute constant (value 1 &lt;&lt;5) indicating that a
151      * file is a symbolic link.
152      * </p>
153      * <p>
154      * If this attribute is <code>true</code> for a given {@link IFileInfo}
155      * instance, a String value may be associated with the attribute
156      * holding the symbolic link target. This link target can be
157      * retrieved with {@link IFileInfo#getStringAttribute(int)} with attribute
158      * type {@link #ATTRIBUTE_LINK_TARGET}.
159      * </p>
160      * <p>
161      * Symbolic links are handled transparently, as implemented by the
162      * underlying operating system. This means, that all other attributes
163      * of a {@link IFileInfo} apply to the link target instead of the link.
164      * Reading or writing a file, or changing attributes applies to the
165      * link target and not the link itself. In case a symbolic link points
166      * to another symbolic link, the chain of links is transparently followed
167      * and operations apply to the actual file or directory being referenced
168      * by the chain of symbolic links.
169      * </p>
170      * <p>
171      * Broken symbolic links (which do not reference any valid file or directory)
172      * are being returned by {@link IFileStore#childInfos(int, IProgressMonitor)},
173      * but {@link IFileInfo#exists()} returns <code>false</code> for these.
174      * Operations like reading or writing on broken symbolic links throw
175      * a "file not found" exception.
176      * </p>
177      *
178      * @see IFileStore#fetchInfo()
179      * @see IFileStore#putInfo(IFileInfo, int, IProgressMonitor)
180      * @see IFileInfo#getAttribute(int)
181      * @see IFileInfo#setAttribute(int, boolean)
182      * @since org.eclipse.core.filesystem 1.1
183      */

184     public static final int ATTRIBUTE_SYMLINK = 1 << 5;
185
186     /**
187      * Attribute constant (value 1 &lt;&lt;6) for a string attribute indicating the
188      * target file name of a symbolic link.
189      * </p>
190      * <p>
191      * Note that setting the link target attribute does not cause a symbolic
192      * link to be created, or changed to link to a different file. Rather, this
193      * attribute is set by file system implementations based on the current
194      * state of a link.
195      * </p>
196      *
197      * @see IFileInfo#getStringAttribute(int)
198      * @see FileInfo#setStringAttribute(int, String)
199      * @see #ATTRIBUTE_SYMLINK
200      * @since org.eclipse.core.filesystem 1.1
201      */

202     public static final int ATTRIBUTE_LINK_TARGET = 1 << 6;
203
204     /**
205      * Scheme constant (value "file") indicating the local file system scheme.
206      * @see EFS#getLocalFileSystem()
207      */

208     public static final String JavaDoc SCHEME_FILE = "file"; //$NON-NLS-1$
209

210     /**
211      * Scheme constant (value "null") indicating the null file system scheme.
212      * @see EFS#getNullFileSystem()
213      */

214     public static final String JavaDoc SCHEME_NULL = "null"; //$NON-NLS-1$
215

216     /*
217      * Status code definitions
218      */

219     // Errors [266-298]
220
/** Status code constant (value 268) indicating a store unexpectedly
221      * exists on the file system.
222      * Severity: error. Category: file system.
223      */

224     public static final int ERROR_EXISTS = 268;
225
226     /** Status code constant (value 269) indicating a store unexpectedly
227      * does not exist on the file system.
228      * Severity: error. Category: file system.
229      */

230     public static final int ERROR_NOT_EXISTS = 269;
231
232     /** Status code constant (value 270) indicating the file system location for
233      * a store could not be computed.
234      * Severity: error. Category: file system.
235      */

236     public static final int ERROR_NO_LOCATION = 270;
237
238     /** Status code constant (value 271) indicating an error occurred while
239      * reading from the file system.
240      * Severity: error. Category: file system.
241      */

242     public static final int ERROR_READ = 271;
243
244     /** Status code constant (value 272) indicating an error occurred while
245      * writing to the file system.
246      * Severity: error. Category: file system.
247      */

248     public static final int ERROR_WRITE = 272;
249
250     /** Status code constant (value 273) indicating an error occurred while
251      * deleting from the file system.
252      * Severity: error. Category: file system.
253      */

254     public static final int ERROR_DELETE = 273;
255
256     /** Status code constant (value 275) indicating this file system is not case
257      * sensitive and a file that differs only in case unexpectedly exists on
258      * the file system.
259      * Severity: error. Category: file system.
260      */

261     public static final int ERROR_CASE_VARIANT_EXISTS = 275;
262
263     /** Status code constant (value 276) indicating a file exists in the
264      * file system but is not of the expected type (file instead of directory,
265      * or vice-versa).
266      * Severity: error. Category: file system.
267      */

268     public static final int ERROR_WRONG_TYPE = 276;
269
270     /** Status code constant (value 277) indicating that the parent
271      * file in the file system is marked as read-only.
272      * Severity: error. Category: file system.
273      */

274     public static final int ERROR_PARENT_READ_ONLY = 277;
275
276     /** Status code constant (value 279) indicating that the
277      * file in the file system is marked as read-only.
278      * Severity: error. Category: file system.
279      */

280     public static final int ERROR_READ_ONLY = 279;
281
282     /** Status code constant (value 566) indicating an error internal has occurred.
283      * Severity: error. Category: internal.
284      */

285     public static final int ERROR_INTERNAL = 566;
286
287     /**
288      * Creates an empty file information object. The resulting information
289      * will represent a non-existent file with no name and no attributes set.
290      *
291      * @see IFileStore#putInfo(IFileInfo, int, IProgressMonitor)
292      * @return an empty file information object.
293      */

294     public static IFileInfo createFileInfo() {
295         return new FileInfo();
296     }
297
298     /**
299      * Returns a file system corresponding to the given scheme.
300      *
301      * @param scheme The file system URI scheme
302      * @return The corresponding file system for the given scheme
303      * @exception CoreException if this method fails. Reasons include:
304      * <ul>
305      * <li>There is no registered file system for the given URI scheme.</li>
306      * <li>There was a failure initializing the file system.</li>
307      * </ul>
308      */

309     public static IFileSystem getFileSystem(String JavaDoc scheme) throws CoreException {
310         return InternalFileSystemCore.getInstance().getFileSystem(scheme);
311     }
312
313     /**
314      * Returns the local file system.
315      *
316      * @return The local file system
317      */

318     public static IFileSystem getLocalFileSystem() {
319         return InternalFileSystemCore.getInstance().getLocalFileSystem();
320     }
321
322     /**
323      * Returns the null file system. The null file system can be used
324      * to represent a non-existent or unresolved file system. An example
325      * of a null file system is a file system whose location is relative to an undefined
326      * variable, or a system whose scheme is unknown.
327      * <p>
328      * Basic handle-based queries can be performed on the null file system, but all
329      * operations that actually require file system access will fail.
330      *
331      * @return The null file system
332      */

333     public static IFileSystem getNullFileSystem() {
334         return InternalFileSystemCore.getInstance().getNullFileSystem();
335     }
336
337     /**
338      * Returns the file store corresponding to the provided URI.
339      *
340      * @param uri The URI of the file store to return
341      * @return The file store
342      * @exception CoreException if this method fails. Reasons include:
343      * <ul>
344      * <li>There is no registered file system for the given URI scheme.</li>
345      * <li>The URI syntax was not in the appropriate form for that scheme.</li>
346      * <li>There was a failure initializing the file system.</li>
347      * </ul>
348      */

349     public static IFileStore getStore(URI JavaDoc uri) throws CoreException {
350         return InternalFileSystemCore.getInstance().getStore(uri);
351     }
352
353     /**
354      * This class is not intended to be instantiated.
355      */

356     private EFS() {
357         super();
358     }
359 }
360
Popular Tags