1 17 package org.eclipse.emf.common; 18 19 20 import java.io.IOException ; 21 import java.net.URL ; 22 23 import org.eclipse.core.runtime.Platform; 24 import org.eclipse.emf.common.util.ResourceLocator; 25 import org.eclipse.emf.common.util.URI; 26 27 28 40 public final class CommonPlugin extends EMFPlugin 41 { 42 45 public static final CommonPlugin INSTANCE = new CommonPlugin(); 46 47 50 private static Implementation plugin; 51 52 55 private CommonPlugin() 56 { 57 super(new ResourceLocator[] {}); 58 } 59 60 63 public ResourceLocator getPluginResourceLocator() 64 { 65 return plugin; 66 } 67 68 72 public static Implementation getPlugin() 73 { 74 return plugin; 75 } 76 77 80 public static URI asLocalURI(URI uri) 81 { 82 return plugin == null ? uri : Implementation.asLocalURI(uri); 83 } 84 85 88 public static URI resolve(URI uri) 89 { 90 return plugin == null ? uri : Implementation.resolve(uri); 91 } 92 93 96 public static Class loadClass(String pluginID, String className) throws ClassNotFoundException 97 { 98 return plugin == null ? Class.forName(className) : Implementation.loadClass(pluginID, className); 99 } 100 101 104 public static class Implementation extends EclipsePlugin 105 { 106 109 public Implementation() 110 { 111 super(); 112 113 plugin = this; 116 } 117 118 121 protected static URI asLocalURI(URI uri) 122 { 123 try 124 { 125 String fragment = uri.fragment(); 126 URL url = Platform.asLocalURL(new URL (uri.trimFragment().toString())); 127 return fix(url, fragment); 128 } 129 catch (IOException exception) 130 { 131 } 132 return uri; 133 } 134 135 138 protected static URI resolve(URI uri) 139 { 140 String fragment = uri.fragment(); 141 URI uriWithoutFragment = uri.trimFragment(); 142 String uriWithoutFragmentToString = uriWithoutFragment.toString(); 143 144 URL url = null; 145 try 146 { 147 url = Platform.resolve(new URL (uriWithoutFragmentToString)); 148 } 149 catch (IOException exception1) 150 { 151 try 154 { 155 uriWithoutFragmentToString = URI.decode(uriWithoutFragmentToString); 156 url = Platform.resolve(new URL (uriWithoutFragmentToString)); 157 } 158 catch (IOException exception2) 159 { 160 } 161 } 162 if (url != null) 163 { 164 try 165 { 166 return fix(url, fragment); 167 } 168 catch (IOException exception) 169 { 170 } 171 } 172 173 return uri; 174 } 175 176 protected static URI fix(URL url, String fragment) throws IOException 177 { 178 URI result = 183 "file".equalsIgnoreCase(url.getProtocol()) ? 184 URI.createFileURI(URI.decode(url.getFile())) : 185 URI.createURI(url.toString()); 186 if (fragment != null) 187 { 188 result = result.appendFragment(fragment); 189 } 190 return result; 191 } 192 193 196 public static Class loadClass(String pluginID, String className) throws ClassNotFoundException 197 { 198 return Platform.getBundle(pluginID).loadClass(className); 199 } 200 } 201 } 202 | Popular Tags |