KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > ccm > util > URLClassLoader


1 /*====================================================================
2
3 OpenCCM: The Open CORBA Component Model Platform
4 Copyright (C) 2000-2002 USTL - LIFL - GOAL
5 Contact: openccm-team@objectweb.org
6
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or any later version.
11
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public
18 License along with this library; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20 USA
21
22 Initial developer(s): Philippe Merle, Raphael Marvie.
23 Contributor(s): Christophe Demarey, Sylvain Leblanc.
24
25 ====================================================================*/

26
27 package org.objectweb.ccm.util;
28
29 /**
30  * This class provides an extended URLClassLoader.
31  *
32  * @author <a HREF="mailto:Philippe.Merle@lifl.fr">Philippe Merle</a>
33  * <a HREF="mailto:Raphael.Marvie@lifl.fr">Raphael Marvie</a>
34  *
35  * @version 0.3
36  */

37
38 public class URLClassLoader
39        extends java.net.URLClassLoader JavaDoc
40 {
41     // ==================================================================
42
//
43
// Internal state.
44
//
45
// ==================================================================
46

47     // ==================================================================
48
//
49
// Constructor.
50
//
51
// ==================================================================
52

53     /**
54      ** The default constructor.
55      **/

56     public
57     URLClassLoader()
58     {
59         super(new java.net.URL JavaDoc[0], Thread.currentThread().getContextClassLoader());
60     }
61
62     /**
63      ** The constructor.
64      **
65      ** @param urls The list of initial URLs.
66      **/

67     public
68     URLClassLoader(java.net.URL JavaDoc urls[])
69     {
70         super(urls, Thread.currentThread().getContextClassLoader());
71     }
72
73     // ==================================================================
74
//
75
// Internal methods.
76
//
77
// ==================================================================
78

79     // ==================================================================
80
//
81
// Public methods.
82
//
83
// ==================================================================
84

85     /**
86      ** Add an URL into the list of URLs of this URLClassLoader.
87      **
88      ** @param url The URL to add.
89      **/

90     public void
91     addURL(java.net.URL JavaDoc url)
92     {
93         super.addURL(url);
94     }
95
96     /**
97      ** Call a static class method.
98      **
99      ** @param entrypt The entry point i.e. 'class_name.method_name'.
100      ** @param args The method arguments.
101      **
102      ** @return The result of the called static class method.
103      **/

104     public Object JavaDoc
105     callStaticClassMethod(String JavaDoc entrypt,
106         Object JavaDoc[] args)
107     throws java.lang.ClassNotFoundException JavaDoc,
108            java.lang.NoSuchMethodException JavaDoc,
109            java.lang.reflect.InvocationTargetException JavaDoc,
110            java.lang.IllegalAccessException JavaDoc
111     {
112         // extract the class name and the method name.
113
int idx = entrypt.lastIndexOf('.');
114         java.lang.String JavaDoc class_name = entrypt.substring(0, idx);
115         java.lang.String JavaDoc method_name = entrypt.substring(idx+1);
116
117         // Search the class.
118
java.lang.Class JavaDoc theClass = super.loadClass(class_name);
119
120         // Search the static method.
121
java.lang.reflect.Method JavaDoc theMethod = theClass.getMethod(method_name, new java.lang.Class JavaDoc[0]);
122
123         try
124         {
125             // Call the static method.
126
return theMethod.invoke(null, args);
127         }
128         catch(java.lang.NullPointerException JavaDoc exc)
129     {
130             throw new java.lang.NoSuchMethodException JavaDoc(entrypt + " is not a static method!!!");
131         }
132     }
133 }
134
Popular Tags