KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > core > filesystem > provider > FileSystem


1 /*******************************************************************************
2  * Copyright (c) 2005, 2006 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  *******************************************************************************/

11 package org.eclipse.core.filesystem.provider;
12
13 import java.net.URI JavaDoc;
14 import java.net.URISyntaxException JavaDoc;
15 import org.eclipse.core.filesystem.*;
16 import org.eclipse.core.runtime.*;
17
18 /**
19  * The common superclass for all file system implementations. Instances
20  * of this class are provided using the <tt>org.eclipse.core.filesystem.filesystems</tt>
21  * extension point.
22  * <p>
23  * On creation, the <code>setInitializationData</code> method is called with
24  * any parameter data specified in the declaring plug-in's manifest.
25  * </p>
26  * <p>
27  * Clients may subclass this class.
28  * </p>
29  * @since org.eclipse.core.filesystem 1.0
30  */

31 public abstract class FileSystem extends PlatformObject implements IFileSystem {
32     private String JavaDoc scheme;
33
34     /**
35      * Creates a new file system instance.
36      */

37     public FileSystem() {
38         super();
39     }
40
41     /**
42      * This is the default implementation of {@link IFileSystem#attributes()}.
43      * This implementation always returns <code>0</code>.
44      * Subclasses may override this method.
45      *
46      * @return The attributes supported by this file system
47      * @see IFileSystem#attributes()
48      */

49     public int attributes() {
50         return 0;
51     }
52
53     /**
54      * This is the default implementation of {@link IFileSystem#canDelete()}.
55      * This implementation always returns <code>false</code>.
56      * Subclasses may override this method.
57      *
58      * @return <code>true</code> if this file system supports deletion, and
59      * <code>false</code> otherwise.
60      * @see IFileSystem#canDelete()
61      */

62     public boolean canDelete() {
63         return false;
64     }
65
66     /**
67      * This is the default implementation of {@link IFileSystem#canWrite()}.
68      * This implementation always returns <code>false</code>.
69      * Subclasses may override this method.
70      *
71      * @return <code>true</code> if this file system allows modification, and
72      * <code>false</code> otherwise.
73      * @see IFileSystem#canWrite()
74      */

75     public boolean canWrite() {
76         return false;
77     }
78
79     /*
80      * (non-Javadoc)
81      * @see org.eclipse.core.filesystem.IFileSystem#getScheme()
82      */

83     public final String JavaDoc getScheme() {
84         return scheme;
85     }
86
87     /**
88      * This is the default implementation of {@link IFileSystem#getStore(IPath)}.
89      * This implementation forwards to {@link IFileSystem#getStore(URI)},
90      * assuming that the provided path corresponds to the path component of the
91      * URI for the file store.
92      * <p>
93      * Subclasses may override this method. If it is not possible to create a file
94      * store corresponding to the provided path for this file system, a file store
95      * belonging to the null file system should be returned
96      * </p>
97      *
98      * @param path A path to a file store within the scheme of this file system.
99      * @return A handle to a file store in this file system
100      * @see IFileSystem#getStore(IPath)
101      * @see EFS#getNullFileSystem()
102      */

103     public IFileStore getStore(IPath path) {
104         try {
105             return getStore(new URI JavaDoc(scheme, path.toString(), null));
106         } catch (URISyntaxException JavaDoc e) {
107             return EFS.getNullFileSystem().getStore(path);
108         }
109     }
110
111     /**
112      * Subclasses must implement this method to satisfy the contract
113      * of {@link IFileSystem#getStore(URI)}. If it is not possible to create a file
114      * store corresponding to the provided URI for this file system, a file store
115      * belonging to the null file system should be returned
116      */

117     public abstract IFileStore getStore(URI JavaDoc uri);
118
119     /**
120      * The default implementation of
121      * {@link IFileSystem#fetchFileTree(IFileStore, IProgressMonitor)}.
122      * This default implementation always returns <code>null</code>. Subclasses
123      * that can efficiently provide an {@link IFileTree} rooted at the given file store
124      * should override.
125      */

126     public IFileTree fetchFileTree(IFileStore root, IProgressMonitor monitor) {
127         return null;
128     }
129
130     /**
131      * {@inheritDoc}
132      * <p>
133      * This default implementation always returns <code>null</code>.
134      * Subclasses may override to provide a concrete mapping from local
135      * files to an IFileStore in their file system.
136      */

137     public IFileStore fromLocalFile(java.io.File JavaDoc file) {
138         return null;
139     }
140
141     /**
142      * Initializes this file system instance with the provided scheme.
143      * <p>
144      * This method is called by the platform immediately after the
145      * file system instance is created. This method must not be
146      * called by clients.
147      *
148      * @param aScheme The scheme of the file system.
149      */

150     public final void initialize(String JavaDoc aScheme) {
151         if (aScheme == null)
152             throw new NullPointerException JavaDoc();
153         //scheme cannot be changed after creation
154
if (this.scheme != null)
155             throw new IllegalStateException JavaDoc("File system already initialized"); //$NON-NLS-1$
156
this.scheme = aScheme;
157     }
158
159     /**
160      * This is the default implementation of {@link IFileSystem#isCaseSensitive()}.
161      * This implementation always returns <code>true</code>. Subclasses may override this method.
162      *
163      * @return <code>true</code> if this file system is case sensitive, and
164      * <code>false</code> otherwise.
165      * @see IFileSystem#isCaseSensitive()
166      */

167     public boolean isCaseSensitive() {
168         return true;
169     }
170 }
171
Popular Tags