35 |
this exception to your version of the library, but you are not |
this exception to your version of the library, but you are not |
36 |
obligated to do so. If you do not wish to do so, delete this |
obligated to do so. If you do not wish to do so, delete this |
37 |
exception statement from your version. */ |
exception statement from your version. */ |
38 |
|
|
39 |
package java.rmi.server; |
package java.rmi.server; |
40 |
|
|
41 |
import java.net.MalformedURLException; |
import java.net.MalformedURLException; |
153 |
|
|
154 |
private static Map cacheLoaders; //map annotations to loaders |
private static Map cacheLoaders; //map annotations to loaders |
155 |
private static Map cacheAnnotations; //map loaders to annotations |
private static Map cacheAnnotations; //map loaders to annotations |
156 |
|
|
157 |
|
//defaultAnnotation is got from system property |
158 |
|
// "java.rmi.server.defaultAnnotation" |
159 |
private static String defaultAnnotation; |
private static String defaultAnnotation; |
160 |
|
|
161 |
//URL object for defaultAnnotation |
//URL object for defaultAnnotation |
173 |
defaultAnnotation = System.getProperty ("java.rmi.server.defaultAnnotation"); |
defaultAnnotation = System.getProperty ("java.rmi.server.defaultAnnotation"); |
174 |
|
|
175 |
try |
try |
176 |
{ |
{ |
177 |
if (defaultAnnotation != null) |
if (defaultAnnotation != null) |
178 |
defaultCodebase = new URL (defaultAnnotation); |
defaultCodebase = new URL (defaultAnnotation); |
179 |
} |
} |
180 |
catch (Exception _) |
catch (Exception _) |
181 |
{ |
{ |
182 |
defaultCodebase = null; |
defaultCodebase = null; |
183 |
} |
} |
184 |
|
|
185 |
if (defaultCodebase != null) |
if (defaultCodebase != null) |
186 |
{ |
{ |
207 |
ClassLoader loader = Thread.currentThread().getContextClassLoader(); |
ClassLoader loader = Thread.currentThread().getContextClassLoader(); |
208 |
|
|
209 |
//try context class loader first |
//try context class loader first |
210 |
try |
try |
211 |
{ |
{ |
212 |
return loader.loadClass (name); |
return loader.loadClass (name); |
213 |
} |
} |
214 |
catch (ClassNotFoundException e) |
catch (ClassNotFoundException e) |
215 |
{ |
{ |
216 |
// class not found in the local classpath |
// class not found in the local classpath |
217 |
} |
} |
218 |
|
|
219 |
if (codebases.length() == 0) //=="" |
if (codebases.length() == 0) //=="" |
220 |
{ |
{ |
271 |
|
|
272 |
return loader; |
return loader; |
273 |
} |
} |
274 |
|
|
275 |
/** |
/** |
276 |
* Returns a string representation of the network location where a remote |
* Returns a string representation of the network location where a remote |
277 |
* endpoint can get the class-definition of the given class. |
* endpoint can get the class-definition of the given class. |
284 |
public static String getClassAnnotation (Class cl) |
public static String getClassAnnotation (Class cl) |
285 |
{ |
{ |
286 |
ClassLoader loader = cl.getClassLoader(); |
ClassLoader loader = cl.getClassLoader(); |
287 |
|
|
288 |
if ((loader == null) |
if (loader == null |
289 |
|| (loader == ClassLoader.getSystemClassLoader())) |
|| loader == ClassLoader.getSystemClassLoader()) |
290 |
{ |
{ |
291 |
return System.getProperty ("java.rmi.server.codebase"); |
return System.getProperty ("java.rmi.server.codebase"); |
292 |
} |
} |
299 |
String s = (String) cacheAnnotations.get (loader); |
String s = (String) cacheAnnotations.get (loader); |
300 |
|
|
301 |
if (s != null) |
if (s != null) |
302 |
{ |
return s; |
|
return s; |
|
|
} |
|
303 |
|
|
304 |
if (loader instanceof URLClassLoader) |
if (loader instanceof URLClassLoader) |
305 |
{ |
{ |
306 |
URL[] urls = ((URLClassLoader) loader).getURLs(); |
URL[] urls = ((URLClassLoader) loader).getURLs(); |
307 |
|
|
308 |
if (urls.length == 0) |
if (urls.length == 0) |
309 |
{ |
return null; |
|
return null; |
|
|
} |
|
310 |
|
|
311 |
StringBuffer annotation = new StringBuffer (64 * urls.length); |
StringBuffer annotation = new StringBuffer (64 * urls.length); |
312 |
|
|