1 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 ; 28 import java.io.IOException ; 29 import java.io.InputStream ; 30 import java.io.OutputStream ; 31 import java.util.Date ; 32 import java.util.Enumeration ; 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 getName() { 42 return ""; } 44 45 public final String getExt() { 46 return ""; } 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 lastModified() { 66 return new Date (0); 67 } 68 69 public final boolean isRoot() { 70 return true; 71 } 72 73 74 79 public final boolean isValid() { 80 return true; 81 } 82 83 public final void rename(final FileLock lock, final String name, final String ext) throws IOException { 84 FSException.io("EXC_CannotRenameRoot", getFileSystem().getDisplayName()); } 87 88 public final void delete(final FileLock lock) throws IOException { 89 FSException.io("EXC_CannotDeleteRoot", getFileSystem().getDisplayName()); } 92 93 public final Object getAttribute(final String attrName) { 94 return null; 95 } 96 97 public final void setAttribute(final String attrName, final Object value) throws IOException { 98 throw new IOException (getPath()); 99 } 100 101 public final Enumeration getAttributes() { 102 return new Enumeration () { 103 public boolean hasMoreElements() { 104 return false; 105 } 106 107 public Object 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 getInputStream() throws FileNotFoundException { 124 throw new FileNotFoundException (getPath()); 125 } 126 127 public final OutputStream getOutputStream(final FileLock lock) throws IOException { 128 throw new FileNotFoundException (getPath()); 129 } 130 131 public final FileLock lock() throws IOException { 132 FSException.io("EXC_CannotLockRoot"); 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 name, final String ext) { 145 FileObject retVal = null; 146 147 if (name.equals(getRealRoot().getName())) { 148 final String 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 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("\\\\")) { 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 name) throws IOException { 178 throw new IOException (getPath()); 179 } 180 181 public final FileObject createData(final String name, final String ext) throws IOException { 182 throw new IOException (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 toString() { 194 String 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 |