KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > core > internal > filesystem > local > LocalFileSystem


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  * Martin Oberhuber (Wind River) - [183137] liblocalfile for solaris-sparc
12  * Martin Oberhuber (Wind River) - [184433] liblocalfile for Linux x86_64
13  * Martin Oberhuber (Wind River) - [184534] get attributes from native lib
14  *******************************************************************************/

15 package org.eclipse.core.internal.filesystem.local;
16
17 import java.io.File JavaDoc;
18 import java.net.URI JavaDoc;
19 import org.eclipse.core.filesystem.*;
20 import org.eclipse.core.filesystem.provider.FileSystem;
21 import org.eclipse.core.runtime.IPath;
22 import org.eclipse.osgi.service.environment.Constants;
23
24 /**
25  * File system provider for the "file" scheme. This file system provides access to
26  * the local file system that is available via java.io.File.
27  */

28 public class LocalFileSystem extends FileSystem {
29     /**
30      * Cached constant indicating if the current OS is Mac OSX
31      */

32     static final boolean MACOSX = LocalFileSystem.getOS().equals(Constants.OS_MACOSX);
33
34     /**
35      * Whether the current file system is case sensitive
36      */

37     private static final boolean caseSensitive = MACOSX ? false : new java.io.File JavaDoc("a").compareTo(new java.io.File JavaDoc("A")) != 0; //$NON-NLS-1$ //$NON-NLS-2$
38

39     /**
40      * The attributes of this file system. The initial value of -1 is used
41      * to indicate that the attributes have not yet been computed.
42      */

43     private int attributes = -1;
44     /**
45      * The singleton instance of this file system.
46      */

47     private static IFileSystem instance;
48
49     /**
50      * Returns the instance of this file system
51      *
52      * @return The instance of this file system.
53      */

54     public static IFileSystem getInstance() {
55         return instance;
56     }
57
58     /**
59      * Returns the current OS. This is equivalent to Platform.getOS(), but
60      * is tolerant of the platform runtime not being present.
61      */

62     static String JavaDoc getOS() {
63         return System.getProperty("osgi.os", ""); //$NON-NLS-1$ //$NON-NLS-2$
64
}
65
66     /**
67      * Creates a new local file system.
68      */

69     public LocalFileSystem() {
70         super();
71         instance = this;
72     }
73
74     /*
75      * (non-Javadoc)
76      * @see org.eclipse.core.filesystem.IFileSystem#attributes()
77      */

78     public int attributes() {
79         if (attributes != -1)
80             return attributes;
81         attributes = 0;
82         if (!LocalFileNatives.usingNatives())
83             return attributes;
84         
85         //try to query supported attributes from native lib impl
86
int nativeAttributes = LocalFileNatives.attributes();
87         if (nativeAttributes >= 0) {
88             attributes = nativeAttributes;
89             return attributes;
90         }
91
92         //fallback for older lib: compute attributes as known before
93
//all known platforms with native implementation support the read only flag
94
attributes |= EFS.ATTRIBUTE_READ_ONLY;
95
96         //this must be kept in sync with the actual native implementations.
97
String JavaDoc os = getOS();
98         String JavaDoc arch = System.getProperty("osgi.arch", ""); //$NON-NLS-1$ //$NON-NLS-2$
99
if (os.equals(Constants.OS_WIN32))
100             attributes |= EFS.ATTRIBUTE_ARCHIVE | EFS.ATTRIBUTE_HIDDEN;
101         else if (os.equals(Constants.OS_LINUX) || (os.equals(Constants.OS_SOLARIS) && arch.equals(Constants.ARCH_SPARC)))
102             attributes |= EFS.ATTRIBUTE_EXECUTABLE | EFS.ATTRIBUTE_SYMLINK | EFS.ATTRIBUTE_LINK_TARGET;
103         else if (os.equals(Constants.OS_MACOSX) || os.equals(Constants.OS_HPUX) || os.equals(Constants.OS_QNX))
104             attributes |= EFS.ATTRIBUTE_EXECUTABLE;
105         return attributes;
106     }
107
108     /*
109      * (non-Javadoc)
110      * @see org.eclipse.core.filesystem.IFileSystem#canDelete()
111      */

112     public boolean canDelete() {
113         return true;
114     }
115
116     /*
117      * (non-Javadoc)
118      * @see org.eclipse.core.filesystem.IFileSystem#canWrite()
119      */

120     public boolean canWrite() {
121         return true;
122     }
123
124     /*
125      * (non-Javadoc)
126      * @see org.eclipse.core.filesystem.IFileSystem#fromLocalFile(java.io.File)
127      */

128     public IFileStore fromLocalFile(File JavaDoc file) {
129         return new LocalFile(file);
130     }
131
132     /*
133      * (non-Javadoc)
134      * @see org.eclipse.core.filesystem.IFileSystem#getStore(org.eclipse.core.runtime.IPath)
135      */

136     public IFileStore getStore(IPath path) {
137         return new LocalFile(path.toFile());
138     }
139
140     /*
141      * (non-Javadoc)
142      * @see org.eclipse.core.filesystem.IFileSystem#getStore(java.net.URI)
143      */

144     public IFileStore getStore(URI JavaDoc uri) {
145         return new LocalFile(new File JavaDoc(uri.getSchemeSpecificPart()));
146     }
147
148     /*
149      * (non-Javadoc)
150      * @see org.eclipse.core.filesystem.IFileSystem#isCaseSensitive()
151      */

152     public boolean isCaseSensitive() {
153         return caseSensitive;
154     }
155 }
156
Popular Tags