01: /*
02: LoaderGenerator - tool for generated xml, sql and doml file needed for Octopus.
03: Copyright (C) 2003 Together
04: This library is free software; you can redistribute it and/or
05: modify it under the terms of the GNU Lesser General Public
06: License as published by the Free Software Foundation; either
07: version 2.1 of the License, or (at your option) any later version.
08: This library is distributed in the hope that it will be useful,
09: but WITHOUT ANY WARRANTY; without even the implied warranty of
10: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11: Lesser General Public License for more details.
12: You should have received a copy of the GNU Lesser General Public
13: License along with this library; if not, write to the Free Software
14: Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15: */
16:
17: package org.webdocwf.util.loader.generator;
18:
19: import java.io.*;
20: import java.net.*;
21: import java.lang.reflect.*;
22:
23: /**
24: *
25: * GeneratorClassLoader class load new files into class loader
26: * @author Radoslav Dutina
27: * @version 1.0
28: */
29: public class GeneratorClassLoader {
30:
31: private static final Class[] parameters = new Class[] { URL.class };
32:
33: /**
34: * This methdod adding the file object to class loader
35: * @param s defines the string representation of file path
36: * @throws IOException
37: */
38: public static void addFile(String s) throws IOException {
39:
40: File f = new File(s);
41:
42: addFile(f);
43:
44: } //end method
45:
46: /**
47: * This method adding the file object to class loader
48: * @param f defines the url of file object
49: * @throws IOException
50: */
51: public static void addFile(File f) throws IOException {
52:
53: addURL(f.toURL());
54:
55: } //end method
56:
57: /**
58: * This method adding the file object to class loader
59: * @param u defines the url object
60: * @throws IOException
61: */
62: public static void addURL(URL u) throws IOException {
63:
64: URLClassLoader sysloader = (URLClassLoader) ClassLoader
65: .getSystemClassLoader();
66:
67: Class sysclass = URLClassLoader.class;
68:
69: try {
70:
71: Method method = sysclass.getDeclaredMethod("addURL",
72: parameters);
73:
74: method.setAccessible(true);
75:
76: method.invoke(sysloader, new Object[] { u });
77:
78: } catch (Throwable t) {
79:
80: t.printStackTrace();
81:
82: throw new IOException(
83: "Error, could not add URL to system classloader");
84:
85: } //end try catch
86:
87: } //end method
88:
89: } //end class
|