KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > masterfs > filebasedfs > fileobjects > RootObj


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.masterfs.filebasedfs.fileobjects;
21
22 import org.netbeans.modules.masterfs.filebasedfs.utils.FSException;
23 import org.netbeans.modules.masterfs.filebasedfs.utils.FileInfo;
24 import org.openide.filesystems.*;
25 import org.openide.util.Utilities;
26
27 import java.io.FileNotFoundException JavaDoc;
28 import java.io.IOException JavaDoc;
29 import java.io.InputStream JavaDoc;
30 import java.io.OutputStream JavaDoc;
31 import java.util.Date JavaDoc;
32 import java.util.Enumeration JavaDoc;
33
34 public final class RootObj extends FileObject {
35     private BaseFileObj realRoot = null;
36
37     public RootObj(final BaseFileObj realRoot) {
38         this.realRoot = realRoot;
39     }
40
41     public final String JavaDoc getName() {
42         return "";//NOI18N
43
}
44
45     public final String JavaDoc getExt() {
46         return "";//NOI18N
47
}
48
49     public final FileSystem getFileSystem() throws FileStateInvalidException {
50         return getRealRoot().getFileSystem();
51     }
52
53     public final FileObject getParent() {
54         return null;
55     }
56
57     public final boolean isFolder() {
58         return true;
59     }
60
61     public final boolean isData() {
62         return !isFolder();
63     }
64
65     public final Date JavaDoc lastModified() {
66         return new Date JavaDoc(0);
67     }
68
69     public final boolean isRoot() {
70         return true;
71     }
72
73
74     /* Test whether the file is valid. The file can be invalid if it has been deserialized
75     * and the file no longer exists on disk; or if the file has been deleted.
76     *
77     * @return true if the file object is valid
78     */

79     public final boolean isValid() {
80         return true;
81     }
82
83     public final void rename(final FileLock lock, final String JavaDoc name, final String JavaDoc ext) throws IOException JavaDoc {
84         //throw new IOException(getPath());
85
FSException.io("EXC_CannotRenameRoot", getFileSystem().getDisplayName()); // NOI18N
86
}
87
88     public final void delete(final FileLock lock) throws IOException JavaDoc {
89         //throw new IOException(getPath());
90
FSException.io("EXC_CannotDeleteRoot", getFileSystem().getDisplayName()); // NOI18N
91
}
92
93     public final Object JavaDoc getAttribute(final String JavaDoc attrName) {
94         return null;
95     }
96
97     public final void setAttribute(final String JavaDoc attrName, final Object JavaDoc value) throws IOException JavaDoc {
98         throw new IOException JavaDoc(getPath());
99     }
100
101     public final Enumeration JavaDoc getAttributes() {
102         return new Enumeration JavaDoc() {
103             public boolean hasMoreElements() {
104                 return false;
105             }
106
107             public Object JavaDoc nextElement() {
108                 return null;
109             }
110         };
111     }
112
113     public final void addFileChangeListener(final FileChangeListener fcl) {
114     }
115
116     public final void removeFileChangeListener(final FileChangeListener fcl) {
117     }
118
119     public final long getSize() {
120         return 0;
121     }
122
123     public final InputStream JavaDoc getInputStream() throws FileNotFoundException JavaDoc {
124         throw new FileNotFoundException JavaDoc(getPath());
125     }
126
127     public final OutputStream JavaDoc getOutputStream(final FileLock lock) throws IOException JavaDoc {
128         throw new FileNotFoundException JavaDoc(getPath());
129     }
130
131     public final FileLock lock() throws IOException JavaDoc {
132         //throw new IOException(getPath());
133
FSException.io("EXC_CannotLockRoot"); // NOI18N
134
return null;
135     }
136
137     public final void setImportant(final boolean b) {
138     }
139
140     public final FileObject[] getChildren() {
141         return new FileObject[]{getRealRoot()};
142     }
143
144     public final FileObject getFileObject(final String JavaDoc name, final String JavaDoc ext) {
145         FileObject retVal = null;
146
147         if (name.equals(getRealRoot().getName())) {
148             final String JavaDoc ext2 = getRealRoot().getExt();
149             if (ext == null || ext.length() == 0) {
150                 retVal = (ext2 == null || ext2.length() == 0) ? getRealRoot() : null;
151             } else {
152                 retVal = (ext.equals(ext2)) ? getRealRoot() : null;
153             }
154         }
155
156         return retVal;
157     }
158
159     public final FileObject getFileObject(String JavaDoc relativePath) {
160         final FileInfo fInfo = new FileInfo(getRealRoot().getFileName().getFile());
161         FileObject retVal;
162
163         if ((!Utilities.isWindows()) || fInfo.isUNCFolder()) {
164             retVal = getRealRoot();
165             if (fInfo.isUNCFolder() && relativePath.startsWith("//") || relativePath.startsWith("\\\\")) {//NOI18N
166
relativePath = relativePath.substring(2);
167             }
168             retVal = retVal.getFileObject(relativePath);
169         } else {
170             retVal = super.getFileObject(relativePath);
171         }
172
173         return retVal;
174     }
175
176
177     public final FileObject createFolder(final String JavaDoc name) throws IOException JavaDoc {
178         throw new IOException JavaDoc(getPath());
179     }
180
181     public final FileObject createData(final String JavaDoc name, final String JavaDoc ext) throws IOException JavaDoc {
182         throw new IOException JavaDoc(getPath());
183     }
184
185     public final boolean isReadOnly() {
186         return true;
187     }
188
189     public final BaseFileObj getRealRoot() {
190         return realRoot;
191     }
192
193     public String JavaDoc toString() {
194         String JavaDoc retVal;
195         try {
196             FileSystem fileSystem = getFileSystem();
197             retVal = fileSystem.getDisplayName();
198         } catch (FileStateInvalidException e) {
199             retVal = super.toString();
200         }
201         return retVal;
202     }
203 }
204
Popular Tags