KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > debug > ui > snippeteditor > ScrapbookMain


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.jdt.internal.debug.ui.snippeteditor;
12
13
14 import java.lang.reflect.InvocationTargetException JavaDoc;
15 import java.lang.reflect.Method JavaDoc;
16 import java.net.MalformedURLException JavaDoc;
17 import java.net.URL JavaDoc;
18 import java.net.URLClassLoader JavaDoc;
19 import java.net.URLDecoder JavaDoc;
20 import java.security.CodeSource JavaDoc;
21 import java.security.ProtectionDomain JavaDoc;
22
23 /**
24  * Support class for launching a snippet evaluation
25  */

26 public class ScrapbookMain {
27     
28     public static void main(String JavaDoc[] args) {
29
30         URL JavaDoc[] urls= getClasspath(args);
31         if (urls == null) return;
32         
33         while (true) {
34             try {
35                 evalLoop(urls);
36             } catch (ClassNotFoundException JavaDoc e) {
37                 return;
38             } catch (NoSuchMethodException JavaDoc e) {
39                 return;
40             } catch (InvocationTargetException JavaDoc e) {
41                 return;
42             } catch (IllegalAccessException JavaDoc e) {
43                 return;
44             }
45         }
46     
47     }
48     
49     static void evalLoop(URL JavaDoc[] urls) throws ClassNotFoundException JavaDoc, NoSuchMethodException JavaDoc, InvocationTargetException JavaDoc, IllegalAccessException JavaDoc {
50
51         ClassLoader JavaDoc cl= new URLClassLoader JavaDoc(urls, null);
52         Class JavaDoc clazz= cl.loadClass("org.eclipse.jdt.internal.debug.ui.snippeteditor.ScrapbookMain1"); //$NON-NLS-1$
53
Method JavaDoc method= clazz.getDeclaredMethod("eval", new Class JavaDoc[] {Class JavaDoc.class}); //$NON-NLS-1$
54
method.invoke(null, new Object JavaDoc[] {ScrapbookMain.class});
55     }
56     
57     public static void nop() {
58         try {
59             Thread.sleep(100);
60         } catch(InterruptedException JavaDoc e) {
61         }
62     }
63     
64     
65     static URL JavaDoc[] getClasspath(String JavaDoc[] urlStrings) {
66         
67         //The URL Strings MUST be properly encoded
68
//using URLEncoder...see ScrapbookLauncher for details
69
URL JavaDoc[] urls= new URL JavaDoc[urlStrings.length + 1];
70         
71         for (int i = 0; i < urlStrings.length; i++) {
72             try {
73                 urls[i + 1] = new URL JavaDoc(URLDecoder.decode(urlStrings[i]));
74             } catch (MalformedURLException JavaDoc e) {
75                 return null;
76             }
77         }
78
79         ProtectionDomain JavaDoc pd = ScrapbookMain.class.getProtectionDomain();
80         if (pd == null) return null;
81         CodeSource JavaDoc cs = pd.getCodeSource();
82         if (cs == null) return null;
83         urls[0] = cs.getLocation();
84
85         return urls;
86     }
87 }
88
Popular Tags