This is the mail archive of the java-patches@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

FYI: Patch: java.rmi.server.RMIClassLoader


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi list,


I commited the attached patch to trunk to merge RMIClassLoader more 
with classpath. Only one more commit is needed to merge it fully.


Michael
- -- 
Homepage: http://www.worldforge.org/
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.3 (GNU/Linux)

iD8DBQE/hX3zWSOgCCdjSDsRAkhpAJ91gxARbP4YeZj5TwwAb0Ia7w/HlACeN7zd
OPK3jrnkl9Mx5iv2z1XM4v8=
=7Sqs
-----END PGP SIGNATURE-----
Index: ChangeLog
===================================================================
RCS file: /cvs/gcc/gcc/libjava/ChangeLog,v
retrieving revision 1.2228
diff -u -b -B -r1.2228 ChangeLog
--- ChangeLog	9 Oct 2003 13:13:05 -0000	1.2228
+++ ChangeLog	9 Oct 2003 15:00:28 -0000
@@ -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.
 
Index: java/rmi/server/RMIClassLoader.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/rmi/server/RMIClassLoader.java,v
retrieving revision 1.7
diff -u -b -B -r1.7 RMIClassLoader.java
--- java/rmi/server/RMIClassLoader.java	26 Sep 2003 20:03:28 -0000	1.7
+++ java/rmi/server/RMIClassLoader.java	9 Oct 2003 15:00:28 -0000
@@ -40,17 +40,11 @@
 
 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;
 
 
 /**
@@ -132,8 +127,8 @@
 
     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 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);
+        loader = getClassLoader(codebases);
+      }
+
 	if (loader == null)
 	  {
-	    //create an entry in cacheLoaders mapping a loader to codebases.
+        //do not throw NullPointerException
+        throw new ClassNotFoundException ("Could not find class (" + name +
+                                          ") at codebase (" + codebases + ")");
+      }
             
+    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, " "); 
+        StringTokenizer tok = new StringTokenizer (codebases, " ");
 	    ArrayList urls = new ArrayList();
+      
 	    while (tok.hasMoreTokens())
-	      urls.add(new URL(tok.nextToken()));
+          urls.add (new URL (tok.nextToken()));
   
-	    loader = new MyClassLoader((URL[])urls.toArray(new URL[urls.size()]),
+        loader = new MyClassLoader ((URL[]) urls.toArray (new URL [urls.size()]),
 					null, codebases);
-	    cacheLoaders.put(codebases, loader);
-	  }
+        cacheLoaders.put (codebases, loader);
       }
 
-    return loader.loadClass(name);
+    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 @@
     String s = (String) cacheAnnotations.get (loader);
 
     if (s != null)
-      {
         return s;
-      }
 
     if (loader instanceof URLClassLoader)
       {
-	URL[] urls = ((URLClassLoader)loader).getURLs();
-	if(urls.length == 0)
+        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++)
+        StringBuffer annotation = new StringBuffer (64 * urls.length);
+
+        for (int i = 0; i < urls.length; i++)
 	  {
-	    annotation.append(urls[i].toExternalForm());
-	    annotation.append(' ');
+            annotation.append (urls [i].toExternalForm());
+            annotation.append (' ');
 	  }
+
 	s = annotation.toString();
-	cacheAnnotations.put(loader, s);
+        cacheAnnotations.put (loader, s);
+        return s;
       }
-    return null;
+
+    return System.getProperty ("java.rmi.server.codebase");
   }
 
   /**

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]