OSDN Git Service

2005-06-04 Anthony Green <green@redhat.com>
authorgreen <green@138bc75d-0d04-0410-961f-82ee72b054a4>
Sat, 4 Jun 2005 11:23:29 +0000 (11:23 +0000)
committergreen <green@138bc75d-0d04-0410-961f-82ee72b054a4>
Sat, 4 Jun 2005 11:23:29 +0000 (11:23 +0000)
        * java/net/URLClassLoader.java: import gnu.gcj.Core,
        and gnu.java.net.protocol.core.CoreInputStream.
        (CureURLLoader): New class.
        (CoreResource): New class.
        (addURLImpl): Add special treatment for the "core" protocol.
        * gnu/gcj/natCore.cc (find): New method.
        * gnu/gcj/Core.java (find): New method.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@100582 138bc75d-0d04-0410-961f-82ee72b054a4

libjava/ChangeLog
libjava/gnu/gcj/Core.java
libjava/gnu/gcj/natCore.cc
libjava/java/net/URLClassLoader.java

index 9c3960c..0b18f79 100644 (file)
@@ -1,3 +1,13 @@
+2005-06-04  Anthony Green  <green@redhat.com>
+
+       * java/net/URLClassLoader.java: import gnu.gcj.Core,
+       and gnu.java.net.protocol.core.CoreInputStream.
+       (CureURLLoader): New class.
+       (CoreResource): New class.
+       (addURLImpl): Add special treatment for the "core" protocol.
+       * gnu/gcj/natCore.cc (find): New method.
+       * gnu/gcj/Core.java (find): New method.
+
 2005-06-03  Keith Seitz  <keiths@redhat.com>
 
        * gnu/classpath/jdwp/transport/ITransport.java: New file.
index 80d623c..d3c358e 100644 (file)
@@ -12,6 +12,9 @@ public class Core
 {
   public native static Core create (String name) throws java.io.IOException;
 
+  // Same as create, except returns null if not found.
+  public native static Core find (String name);
+
   public RawData ptr;
   public int length;
 
index bb3fd57..d084b25 100644 (file)
@@ -104,6 +104,13 @@ _Jv_create_core (_Jv_core_chain *node, jstring name)
 }
 
 gnu::gcj::Core *
+gnu::gcj::Core::find (jstring name)
+{
+  gnu::gcj::Core *core = _Jv_create_core (root, name);
+  return core;
+}
+
+gnu::gcj::Core *
 gnu::gcj::Core::create (jstring name)
 {
   gnu::gcj::Core *core = _Jv_create_core (root, name);
index 4b95998..e0a9389 100644 (file)
@@ -63,7 +63,8 @@ import java.util.jar.JarEntry;
 import java.util.jar.JarFile;
 import java.util.jar.Manifest;
 import gnu.gcj.runtime.SharedLibHelper;
-
+import gnu.gcj.Core;
+import gnu.java.net.protocol.core.CoreInputStream;
 
 /**
  * A secure class loader that can load classes and resources from
@@ -677,6 +678,66 @@ public class URLClassLoader extends SecureClassLoader
     }
   }
 
+  /**
+   * A <code>CoreURLLoader</code> is a type of <code>URLLoader</code>
+   * only loading from core url.
+   */
+  static final class CoreURLLoader extends URLLoader
+  {
+    private String dir;
+
+    CoreURLLoader(URLClassLoader classloader, URL url)
+    {
+      super(classloader, url);
+      dir = baseURL.getFile();
+    }
+
+    /** get resource with the name "name" in the core url */
+    Resource getResource(String name)
+    {
+      Core core = Core.find (dir + name);
+      if (core != null)
+        return new CoreResource(this, name, core);
+      return null;
+    }
+  }
+
+  static final class CoreResource extends Resource
+  {
+    final Core core;
+
+    CoreResource(CoreURLLoader loader, String name, Core core)
+    {
+      super(loader, name);
+      this.core = core;
+    }
+
+    InputStream getInputStream() throws IOException
+    {
+      return new CoreInputStream(core);
+    }
+
+    public int getLength()
+    {
+      return core.length;
+    }
+
+    public URL getURL()
+    {
+      try
+        {
+          return new URL(loader.baseURL, name,
+                         loader.classloader.getURLStreamHandler("core"));
+        }
+      catch (MalformedURLException e)
+        {
+          InternalError ie = new InternalError();
+          ie.initCause(e);
+          throw ie;
+        }
+    }
+  }
+
   // Constructors
 
   /**
@@ -842,6 +903,8 @@ public class URLClassLoader extends SecureClassLoader
               loader = new JarURLLoader(this, newUrl);
             else if ("file".equals(protocol))
               loader = new FileURLLoader(this, newUrl);
+           else if ("core".equals(protocol))
+             loader = new CoreURLLoader(this, newUrl);
             else
               loader = new RemoteURLLoader(this, newUrl);