1 11 package org.eclipse.jdt.internal.debug.ui.snippeteditor; 12 13 14 import java.lang.reflect.InvocationTargetException ; 15 import java.lang.reflect.Method ; 16 import java.net.MalformedURLException ; 17 import java.net.URL ; 18 import java.net.URLClassLoader ; 19 import java.net.URLDecoder ; 20 import java.security.CodeSource ; 21 import java.security.ProtectionDomain ; 22 23 26 public class ScrapbookMain { 27 28 public static void main(String [] args) { 29 30 URL [] urls= getClasspath(args); 31 if (urls == null) return; 32 33 while (true) { 34 try { 35 evalLoop(urls); 36 } catch (ClassNotFoundException e) { 37 return; 38 } catch (NoSuchMethodException e) { 39 return; 40 } catch (InvocationTargetException e) { 41 return; 42 } catch (IllegalAccessException e) { 43 return; 44 } 45 } 46 47 } 48 49 static void evalLoop(URL [] urls) throws ClassNotFoundException , NoSuchMethodException , InvocationTargetException , IllegalAccessException { 50 51 ClassLoader cl= new URLClassLoader (urls, null); 52 Class clazz= cl.loadClass("org.eclipse.jdt.internal.debug.ui.snippeteditor.ScrapbookMain1"); Method method= clazz.getDeclaredMethod("eval", new Class [] {Class .class}); method.invoke(null, new Object [] {ScrapbookMain.class}); 55 } 56 57 public static void nop() { 58 try { 59 Thread.sleep(100); 60 } catch(InterruptedException e) { 61 } 62 } 63 64 65 static URL [] getClasspath(String [] urlStrings) { 66 67 URL [] urls= new URL [urlStrings.length + 1]; 70 71 for (int i = 0; i < urlStrings.length; i++) { 72 try { 73 urls[i + 1] = new URL (URLDecoder.decode(urlStrings[i])); 74 } catch (MalformedURLException e) { 75 return null; 76 } 77 } 78 79 ProtectionDomain pd = ScrapbookMain.class.getProtectionDomain(); 80 if (pd == null) return null; 81 CodeSource cs = pd.getCodeSource(); 82 if (cs == null) return null; 83 urls[0] = cs.getLocation(); 84 85 return urls; 86 } 87 } 88 | Popular Tags |