1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package net.sf.jameleon.ui;
20
21 import java.io.File;
22 import java.net.URL;
23 import java.net.URLClassLoader;
24 import java.util.Iterator;
25 import java.util.HashSet;
26 import java.util.Set;
27
28 import net.sf.jameleon.util.Configurator;
29
30 public class Utils{
31
32 public static ClassLoader createClassLoader(){
33 Configurator.clearInstance();
34 Utils utils = new Utils();
35 URL[] urls = utils.getURLS();
36 Configurator.clearInstance();
37 return new URLClassLoader(urls, Thread.currentThread().getContextClassLoader());
38 }
39
40 private URL[] getURLS(){
41 Set urlsS = getEntriesForClasspath();
42 URL[] urls = new URL[urlsS.size()];
43 Iterator it = urlsS.iterator();
44 for (int i = 0; it.hasNext(); i++) {
45 urls[i] = (URL) it.next();
46 }
47 return urls;
48 }
49
50 private Set getEntriesForClasspath(){
51 Set fileNames = Configurator.getInstance().getKeysStartingWith("classpath.entry");
52 return getURLS(fileNames);
53 }
54
55 private Set getURLS(Set fileNames){
56 Set urls = new HashSet();
57 Iterator it = fileNames.iterator();
58 String value;
59 File f;
60 while (it.hasNext()) {
61 value = Configurator.getInstance().getValue((String)it.next());
62 f = new File(value);
63 if (f.exists()) {
64 try{
65 urls.add(f.toURL());
66 }catch(Exception e){
67 System.err.println("Couldn't add "+value);
68 }
69 }
70 }
71 return urls;
72 }
73
74 }