diff options
author | Michael Koch <konqueror@gmx.de> | 2003-10-09 15:20:25 +0000 |
---|---|---|
committer | Michael Koch <mkoch@gcc.gnu.org> | 2003-10-09 15:20:25 +0000 |
commit | 69c7b8276916ac7807d34abc96c9fb64326995a5 (patch) | |
tree | 64e5408be7d1bc5085e67e4101c470e358bb484f | |
parent | cf48cabb7d0e568aa496e27859cef0ed10fbb25f (diff) | |
download | gcc-69c7b8276916ac7807d34abc96c9fb64326995a5.zip gcc-69c7b8276916ac7807d34abc96c9fb64326995a5.tar.gz gcc-69c7b8276916ac7807d34abc96c9fb64326995a5.tar.bz2 |
RMIClassLoader.java: Removed unused imports, little reformatings.
2003-10-09 Michael Koch <konqueror@gmx.de>
* java/rmi/server/RMIClassLoader.java:
Removed unused imports, little reformatings.
(getClassLoader): New method, implementation was part of old loadCLass
method.
(loadClass): Simplified by moving functionality to new method and
reworking the code a bit.
(getClassAnnotation): Merged documentation from classpath.
From-SVN: r72267
-rw-r--r-- | libjava/ChangeLog | 10 | ||||
-rw-r--r-- | libjava/java/rmi/server/RMIClassLoader.java | 154 |
2 files changed, 105 insertions, 59 deletions
diff --git a/libjava/ChangeLog b/libjava/ChangeLog index 8378a26..4a65d11 100644 --- a/libjava/ChangeLog +++ b/libjava/ChangeLog @@ -1,5 +1,15 @@ 2003-10-09 Michael Koch <konqueror@gmx.de> + * java/rmi/server/RMIClassLoader.java: + Removed unused imports, little reformatings. + (getClassLoader): New method, implementation was part of old loadCLass + method. + (loadClass): Simplified by moving functionality to new method and + reworking the code a bit. + (getClassAnnotation): Merged documentation from classpath. + +2003-10-09 Michael Koch <konqueror@gmx.de> + * java/math/BigInteger.java (add): Removed unused local variable len. diff --git a/libjava/java/rmi/server/RMIClassLoader.java b/libjava/java/rmi/server/RMIClassLoader.java index 20dd7f6..c618798 100644 --- a/libjava/java/rmi/server/RMIClassLoader.java +++ b/libjava/java/rmi/server/RMIClassLoader.java @@ -40,17 +40,11 @@ package java.rmi.server; import java.net.MalformedURLException; import java.net.URL; -import java.net.URLConnection; import java.net.URLClassLoader; -import java.io.IOException; -import java.io.DataInputStream; import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; import java.util.Hashtable; import java.util.Map; import java.util.StringTokenizer; -import java.util.WeakHashMap; /** @@ -106,6 +100,7 @@ public class RMIClassLoader //defaultAnnotation is got from system property // "java.rmi.server.defaultAnnotation" private static String defaultAnnotation; + //URL object for defaultAnnotation private static URL defaultCodebase; @@ -121,19 +116,19 @@ public class RMIClassLoader defaultAnnotation = System.getProperty ("java.rmi.server.defaultAnnotation"); try - { - if (defaultAnnotation != null) - defaultCodebase = new URL (defaultAnnotation); - } + { + if (defaultAnnotation != null) + defaultCodebase = new URL (defaultAnnotation); + } catch (Exception _) - { - defaultCodebase = null; - } + { + defaultCodebase = null; + } if (defaultCodebase != null) { - defaultLoader = new MyClassLoader(new URL[]{ defaultCodebase }, - null, defaultAnnotation); + defaultLoader = new MyClassLoader (new URL[] { defaultCodebase }, null, + defaultAnnotation); cacheLoaders.put(defaultAnnotation, defaultLoader); } } @@ -150,49 +145,87 @@ public class RMIClassLoader public static Class loadClass (String codebases, String name) throws MalformedURLException, ClassNotFoundException { - Class c = null; ClassLoader loader = Thread.currentThread().getContextClassLoader(); //try context class loader first try { - c = loader.loadClass(name); + return loader.loadClass (name); + } + catch (ClassNotFoundException e) + { + // class not found in the local classpath } - catch(ClassNotFoundException e) {} - - if (c != null) - return c; if (codebases.length() == 0) //=="" - loader = defaultLoader; - else { - loader = (ClassLoader)cacheLoaders.get(codebases); - if (loader == null) - { - //create an entry in cacheLoaders mapping a loader to codebases. - - // codebases are separated by " " - StringTokenizer tok = new StringTokenizer(codebases, " "); - ArrayList urls = new ArrayList(); - while (tok.hasMoreTokens()) - urls.add(new URL(tok.nextToken())); - - loader = new MyClassLoader((URL[])urls.toArray(new URL[urls.size()]), - null, codebases); - cacheLoaders.put(codebases, loader); - } + loader = defaultLoader; + } + else + { + loader = getClassLoader(codebases); + } + + if (loader == null) + { + //do not throw NullPointerException + throw new ClassNotFoundException ("Could not find class (" + name + + ") at codebase (" + codebases + ")"); } + + return loader.loadClass (name); + } - return loader.loadClass(name); + /** + * Gets a classloader for the given codebase and with the current + * context classloader as parent. + * + * @param codebases + * + * @return a classloader for the given codebase + * + * @throws MalformedURLException if the codebase contains a malformed URL + */ + private static ClassLoader getClassLoader (String codebases) + throws MalformedURLException + { + ClassLoader loader = (ClassLoader) cacheLoaders.get (codebases); + + if (loader == null) + { + //create an entry in cacheLoaders mapping a loader to codebases. + // codebases are separated by " " + StringTokenizer tok = new StringTokenizer (codebases, " "); + ArrayList urls = new ArrayList(); + + while (tok.hasMoreTokens()) + urls.add (new URL (tok.nextToken())); + + loader = new MyClassLoader ((URL[]) urls.toArray (new URL [urls.size()]), + null, codebases); + cacheLoaders.put (codebases, loader); + } + + return loader; } - - public static String getClassAnnotation(Class cl) + + /** + * Returns a string representation of the network location where a remote + * endpoint can get the class-definition of the given class. + * + * @param cl + * + * @return a space seperated list of URLs where the class-definition + * of cl may be found + */ + public static String getClassAnnotation (Class cl) { ClassLoader loader = cl.getClassLoader(); - if (loader == null || loader == ClassLoader.getSystemClassLoader()) + + if (loader == null + || loader == ClassLoader.getSystemClassLoader()) { - return null; //?? + return System.getProperty ("java.rmi.server.codebase"); } if (loader instanceof MyClassLoader) @@ -203,26 +236,29 @@ public class RMIClassLoader String s = (String) cacheAnnotations.get (loader); if (s != null) - { - return s; - } + return s; if (loader instanceof URLClassLoader) { - URL[] urls = ((URLClassLoader)loader).getURLs(); - if(urls.length == 0) - return null; - - StringBuffer annotation = new StringBuffer(64*urls.length); - for(int i = 0; i < urls.length; i++) - { - annotation.append(urls[i].toExternalForm()); - annotation.append(' '); - } - s = annotation.toString(); - cacheAnnotations.put(loader, s); + URL[] urls = ((URLClassLoader) loader).getURLs(); + + if (urls.length == 0) + return null; + + StringBuffer annotation = new StringBuffer (64 * urls.length); + + for (int i = 0; i < urls.length; i++) + { + annotation.append (urls [i].toExternalForm()); + annotation.append (' '); + } + + s = annotation.toString(); + cacheAnnotations.put (loader, s); + return s; } - return null; + + return System.getProperty ("java.rmi.server.codebase"); } /** |