aboutsummaryrefslogtreecommitdiff
path: root/libjava/gnu/gcj/runtime/VMClassLoader.java
blob: ae0a0ebb20a5aba72816d67c56d162abda7f96f0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/* Copyright (C) 1999  Free Software Foundation

   This file is part of libgcj.

This software is copyrighted work licensed under the terms of the
Libgcj License.  Please consult the file "LIBGCJ_LICENSE" for
details.  */

/* Author: Kresten Krab Thorup <krab@gnu.org>  */

package gnu.gcj.runtime;

import java.io.*;
import java.util.StringTokenizer;
import java.net.URL;

final class VMClassLoader extends java.net.URLClassLoader
{
  private VMClassLoader ()
  {	
    super (init());
  }

  private static URL[] init() 
  {
    StringTokenizer st
	= new StringTokenizer (System.getProperty ("java.class.path", "."),
			       System.getProperty ("path.separator", ":"));

    java.util.Vector p = new java.util.Vector();
    while (st.hasMoreElements ()) 
      {  
	String e = st.nextToken ();
	try
	  {
	    if (e.endsWith(".jar") || e.endsWith (".zip"))
	      p.addElement(new URL("jar", "", -1, "file:///"+e+"!/"));
	    else if (e.endsWith ("/"))
	      p.addElement (new URL("file", "", -1, e));
	    else if (new File (e).isDirectory ())
	      p.addElement (new URL("file", "", -1, e + "/"));
	    else
	      /* Ignore path element. */;
	  } 
	catch (java.net.MalformedURLException x)
	  {
	    /* Ignore this path element */
	  }
      }

    URL[] urls = new URL[p.size()];
    p.copyInto (urls);
    return urls;
  }

  /** This is overridden to search the internal hash table, which 
   * will only search existing linked-in classes.   This will make
   * the default implementation of loadClass (in ClassLoader) work right.
   */
  protected final native Class findSystemClass(String name) 
    throws java.lang.ClassNotFoundException, java.lang.LinkageError;

  // Return the sole VMClassLoader.
  private static synchronized VMClassLoader getVMClassLoader ()
  {
    if (redirect == null)
      redirect = new VMClassLoader ();
    return redirect;
  }

  // The only VMClassLoader that can exist.
  private static VMClassLoader redirect;
}