1 11 package org.eclipse.core.internal.resources; 12 13 14 import java.net.URI ; 15 import java.util.*; 16 import org.eclipse.core.filesystem.URIUtil; 17 import org.eclipse.core.internal.utils.FileUtil; 18 import org.eclipse.core.resources.*; 19 import org.eclipse.core.runtime.*; 20 21 public class WorkspaceRoot extends Container implements IWorkspaceRoot { 22 27 private final Map projectTable = Collections.synchronizedMap(new HashMap(16)); 28 29 32 private final IPath workspaceLocation; 33 34 protected WorkspaceRoot(IPath path, Workspace container) { 35 super(path, container); 36 Assert.isTrue(path.equals(Path.ROOT)); 37 workspaceLocation = FileUtil.canonicalPath(Platform.getLocation()); 38 Assert.isNotNull(workspaceLocation); 39 } 40 41 44 public void delete(boolean deleteContent, boolean force, IProgressMonitor monitor) throws CoreException { 45 int updateFlags = force ? IResource.FORCE : IResource.NONE; 46 updateFlags |= deleteContent ? IResource.ALWAYS_DELETE_PROJECT_CONTENT : IResource.NEVER_DELETE_PROJECT_CONTENT; 47 delete(updateFlags, monitor); 48 } 49 50 53 public void delete(boolean force, IProgressMonitor monitor) throws CoreException { 54 int updateFlags = force ? IResource.FORCE : IResource.NONE; 55 delete(updateFlags, monitor); 56 } 57 58 61 public boolean exists(int flags, boolean checkType) { 62 return true; 63 } 64 65 68 public IContainer[] findContainersForLocation(IPath location) { 69 return findContainersForLocationURI(URIUtil.toURI(location.makeAbsolute())); 70 } 71 72 75 public IContainer[] findContainersForLocationURI(URI location) { 76 if (!location.isAbsolute()) 77 throw new IllegalArgumentException (); 78 return (IContainer[]) getLocalManager().allResourcesFor(location, false); 79 } 80 81 84 public IFile[] findFilesForLocation(IPath location) { 85 return findFilesForLocationURI(URIUtil.toURI(location.makeAbsolute())); 86 } 87 88 91 public IFile[] findFilesForLocationURI(URI location) { 92 if (!location.isAbsolute()) 93 throw new IllegalArgumentException (); 94 return (IFile[]) getLocalManager().allResourcesFor(location, true); 95 } 96 97 100 public IContainer getContainerForLocation(IPath location) { 101 return getLocalManager().containerForLocation(location); 102 } 103 104 107 public String getDefaultCharset(boolean checkImplicit) { 108 if (checkImplicit) 109 return ResourcesPlugin.getEncoding(); 110 String enc = ResourcesPlugin.getPlugin().getPluginPreferences().getString(ResourcesPlugin.PREF_ENCODING); 111 return enc == null || enc.length() == 0 ? null : enc; 112 } 113 114 117 public IFile getFileForLocation(IPath location) { 118 return getLocalManager().fileForLocation(location); 119 } 120 121 124 public long getLocalTimeStamp() { 125 return IResource.NULL_STAMP; 126 } 127 128 131 public IPath getLocation() { 132 return workspaceLocation; 133 } 134 135 138 public String getName() { 139 return ""; } 141 142 145 public IContainer getParent() { 146 return null; 147 } 148 149 152 public IProject getProject() { 153 return null; 154 } 155 156 159 public IProject getProject(String name) { 160 Project result = (Project) projectTable.get(name); 162 if (result == null) { 163 IPath projectPath = new Path(null, name).makeAbsolute(); 164 String message = "Path for project must have only one segment."; Assert.isLegal(projectPath.segmentCount() == ICoreConstants.PROJECT_SEGMENT_LENGTH, message); 166 String canonicalName = projectPath.lastSegment(); 168 result = (Project) projectTable.get(canonicalName); 169 if (result != null) 170 return result; 171 result = new Project(projectPath, workspace); 172 projectTable.put(canonicalName, result); 173 } 174 return result; 175 } 176 177 180 public IPath getProjectRelativePath() { 181 return Path.EMPTY; 182 } 183 184 187 public IProject[] getProjects() { 188 IResource[] roots = getChildren(IResource.NONE); 189 IProject[] result = new IProject[roots.length]; 190 System.arraycopy(roots, 0, result, 0, roots.length); 191 return result; 192 } 193 194 197 public int getType() { 198 return IResource.ROOT; 199 } 200 201 public void internalSetLocal(boolean flag, int depth) throws CoreException { 202 if (depth == IResource.DEPTH_ZERO) 204 return; 205 if (depth == IResource.DEPTH_ONE) 206 depth = IResource.DEPTH_ZERO; 207 IResource[] children = getChildren(IResource.NONE); 210 for (int i = 0; i < children.length; i++) 211 ((Resource) children[i]).internalSetLocal(flag, depth); 212 } 213 214 217 public boolean isLinked(int options) { 218 return false; } 220 221 225 public boolean isLocal(int depth) { 226 return isLocal(-1, depth); 228 } 229 230 234 public boolean isLocal(int flags, int depth) { 235 if (depth == DEPTH_ZERO) 237 return true; 238 if (depth == DEPTH_ONE) 239 depth = DEPTH_ZERO; 240 IResource[] children = getChildren(IResource.NONE); 243 for (int i = 0; i < children.length; i++) 244 if (!children[i].isLocal(depth)) 245 return false; 246 return true; 247 } 248 249 252 public boolean isPhantom() { 253 return false; 254 } 255 256 261 public void setDefaultCharset(String charset) { 262 Preferences resourcesPreferences = ResourcesPlugin.getPlugin().getPluginPreferences(); 264 if (charset != null) 265 resourcesPreferences.setValue(ResourcesPlugin.PREF_ENCODING, charset); 266 else 267 resourcesPreferences.setToDefault(ResourcesPlugin.PREF_ENCODING); 268 } 269 270 273 public long setLocalTimeStamp(long value) { 274 if (value < 0) 275 throw new IllegalArgumentException ("Illegal time stamp: " + value); return value; 278 } 279 280 284 public void setReadOnly(boolean readonly) { 285 } 287 288 291 public void touch(IProgressMonitor monitor) { 292 } 294 } 295 | Popular Tags |