1 11 package org.eclipse.core.internal.filesystem; 12 13 import java.net.URI ; 14 import java.util.HashMap ; 15 import org.eclipse.core.filesystem.*; 16 import org.eclipse.core.filesystem.provider.FileSystem; 17 import org.eclipse.core.runtime.*; 18 import org.eclipse.osgi.util.NLS; 19 20 24 public class InternalFileSystemCore implements IRegistryChangeListener { 25 private static final InternalFileSystemCore INSTANCE = new InternalFileSystemCore(); 26 27 34 private HashMap fileSystems; 35 36 40 public static InternalFileSystemCore getInstance() { 41 return INSTANCE; 42 } 43 44 47 private InternalFileSystemCore() { 48 super(); 49 RegistryFactory.getRegistry().addRegistryChangeListener(this); 50 } 51 52 59 public IFileSystem getFileSystem(String scheme) throws CoreException { 60 if (scheme == null) 61 throw new NullPointerException (); 62 final HashMap registry = getFileSystemRegistry(); 63 Object result = registry.get(scheme); 64 if (result == null) 65 Policy.error(EFS.ERROR_INTERNAL, NLS.bind(Messages.noFileSystem, scheme)); 66 if (result instanceof IFileSystem) 67 return (IFileSystem) result; 68 try { 69 IConfigurationElement element = (IConfigurationElement) result; 70 FileSystem fs = (FileSystem) element.createExecutableExtension("run"); fs.initialize(scheme); 72 registry.put(scheme, fs); 74 return fs; 75 } catch (CoreException e) { 76 registry.remove(scheme); 78 throw e; 79 } 80 } 81 82 87 public IFileSystem getLocalFileSystem() { 88 try { 89 return getFileSystem(EFS.SCHEME_FILE); 90 } catch (CoreException e) { 91 throw new Error (e); 93 } 94 } 95 96 103 public IFileStore getStore(URI uri) throws CoreException { 104 final String scheme = uri.getScheme(); 105 if (scheme == null) 106 Policy.error(EFS.ERROR_INTERNAL, Messages.noScheme + uri); 107 return getFileSystem(scheme).getStore(uri); 108 } 109 110 114 private synchronized HashMap getFileSystemRegistry() { 115 if (fileSystems == null) { 116 fileSystems = new HashMap (); 117 IExtensionPoint point = RegistryFactory.getRegistry().getExtensionPoint(EFS.PI_FILE_SYSTEM, EFS.PT_FILE_SYSTEMS); 118 IExtension[] extensions = point.getExtensions(); 119 for (int i = 0; i < extensions.length; i++) { 120 IConfigurationElement[] elements = extensions[i].getConfigurationElements(); 121 for (int j = 0; j < elements.length; j++) { 122 if ("filesystem".equals(elements[j].getName())) { String scheme = elements[j].getAttribute("scheme"); if (scheme != null) 125 fileSystems.put(scheme, elements[j]); 126 } 127 } 128 } 129 } 130 return fileSystems; 131 } 132 133 137 public void registryChanged(IRegistryChangeEvent event) { 138 IExtensionDelta[] changes = event.getExtensionDeltas(EFS.PI_FILE_SYSTEM, EFS.PT_FILE_SYSTEMS); 139 if (changes.length == 0) 140 return; 141 synchronized (this) { 142 fileSystems = null; 144 } 145 } 146 147 151 public IFileSystem getNullFileSystem() { 152 try { 153 return getFileSystem(EFS.SCHEME_NULL); 154 } catch (CoreException e) { 155 throw new Error (e); 157 } 158 } 159 } | Popular Tags |