/[classpath]/classpath/java/lang/ClassLoader.java
ViewVC logotype

Diff of /classpath/java/lang/ClassLoader.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.31.2.2 by gnu_andrew, Sat Jan 15 17:01:52 2005 UTC revision 1.31.2.3 by gnu_andrew, Sun Jan 16 02:14:48 2005 UTC
# Line 85  import java.util.StringTokenizer; Line 85  import java.util.StringTokenizer;
85   * <p>The bootstrap classloader in GNU Classpath is implemented as a couple of   * <p>The bootstrap classloader in GNU Classpath is implemented as a couple of
86   * static (native) methods on the package private class   * static (native) methods on the package private class
87   * <code>java.lang.VMClassLoader</code>, the system classloader is an   * <code>java.lang.VMClassLoader</code>, the system classloader is an
88   * instance of <code>gnu.java.lang.SystemClassLoader</code>   * anonymous inner class of ClassLoader and a subclass of
89   * (which is a subclass of <code>java.net.URLClassLoader</code>).   * <code>java.net.URLClassLoader</code>.
90   *   *
91   * <p>Users of a <code>ClassLoader</code> will normally just use the methods   * <p>Users of a <code>ClassLoader</code> will normally just use the methods
92   * <ul>   * <ul>
# Line 151  public abstract class ClassLoader Line 151  public abstract class ClassLoader
151    private final boolean initialized;    private final boolean initialized;
152    
153    /**    /**
    * System/Application classloader: defaults to an instance of  
    * gnu.java.lang.SystemClassLoader, unless the first invocation of  
    * getSystemClassLoader loads another class loader because of the  
    * java.system.class.loader property. The initialization of this field  
    * is somewhat circular - getSystemClassLoader() checks whether this  
    * field is null in order to bypass a security check.  
    */  
   static final ClassLoader systemClassLoader =  
     VMClassLoader.getSystemClassLoader();  
   
   /**  
154     * The default protection domain, used when defining a class with a null     * The default protection domain, used when defining a class with a null
155     * paramter for the domain.     * paramter for the domain.
156     */     */
# Line 222  public abstract class ClassLoader Line 211  public abstract class ClassLoader
211     */     */
212    protected ClassLoader() throws SecurityException    protected ClassLoader() throws SecurityException
213    {    {
214      this(systemClassLoader);      this(System.systemClassLoader);
215    }    }
216    
217    /**    /**
# Line 480  public abstract class ClassLoader Line 469  public abstract class ClassLoader
469    protected final Class<?> findSystemClass(String name)    protected final Class<?> findSystemClass(String name)
470      throws ClassNotFoundException      throws ClassNotFoundException
471    {    {
472      return Class.forName(name, false, systemClassLoader);      return Class.forName(name, false, System.systemClassLoader);
473    }    }
474    
475    /**    /**
# Line 642  public abstract class ClassLoader Line 631  public abstract class ClassLoader
631     */     */
632    public static final URL getSystemResource(String name)    public static final URL getSystemResource(String name)
633    {    {
634      return systemClassLoader.getResource(name);      return System.systemClassLoader.getResource(name);
635    }    }
636    
637    /**    /**
# Line 659  public abstract class ClassLoader Line 648  public abstract class ClassLoader
648    public static Enumeration<URL> getSystemResources(String name)    public static Enumeration<URL> getSystemResources(String name)
649      throws IOException      throws IOException
650    {    {
651      return systemClassLoader.getResources(name);      return System.systemClassLoader.getResources(name);
652    }    }
653    
654    /**    /**
# Line 714  public abstract class ClassLoader Line 703  public abstract class ClassLoader
703    
704    /**    /**
705     * Returns the system classloader. The system classloader (also called     * Returns the system classloader. The system classloader (also called
706     * the application classloader) is the classloader that was used to     * the application classloader) is the classloader that is used to
707     * load the application classes on the classpath (given by the system     * load the application classes on the classpath (given by the system
708     * property <code>java.class.path</code>. This is set as the context     * property <code>java.class.path</code>. This is set as the context
709     * class loader for a thread. The system property     * class loader for a thread. The system property
710     * <code>java.system.class.loader</code>, if defined, is taken to be the     * <code>java.system.class.loader</code>, if defined, is taken to be the
711     * name of the class to use as the system class loader, which must have     * name of the class to use as the system class loader, which must have
712     * a public constructor which takes a ClassLoader as a parent; otherwise this     * a public constructor which takes a ClassLoader as a parent. The parent
713     * uses gnu.java.lang.SystemClassLoader.     * class loader passed in the constructor is the default system class
714       * loader.
715     *     *
716     * <p>Note that this is different from the bootstrap classloader that     * <p>Note that this is different from the bootstrap classloader that
717     * actually loads all the real "system" classes (the bootstrap classloader     * actually loads all the real "system" classes.
    * is the parent of the returned system classloader).  
718     *     *
719     * <p>A security check will be performed for     * <p>A security check will be performed for
720     * <code>RuntimePermission("getClassLoader")</code> if the calling class     * <code>RuntimePermission("getClassLoader")</code> if the calling class
# Line 745  public abstract class ClassLoader Line 734  public abstract class ClassLoader
734        {        {
735          Class<?> c = VMSecurityManager.getClassContext()[1];          Class<?> c = VMSecurityManager.getClassContext()[1];
736          ClassLoader cl = c.getClassLoader();          ClassLoader cl = c.getClassLoader();
737          if (cl != null && cl != systemClassLoader)          if (cl != null && cl != System.systemClassLoader)
738            sm.checkPermission(new RuntimePermission("getClassLoader"));            sm.checkPermission(new RuntimePermission("getClassLoader"));
739        }        }
740    
741      return systemClassLoader;      return System.systemClassLoader;
742    }    }
743    
744    /**    /**
# Line 992  public abstract class ClassLoader Line 981  public abstract class ClassLoader
981      return urls;      return urls;
982    }    }
983    
984      private static void addFileURL(ArrayList list, String file)
985      {
986        try
987          {
988            list.add(new File(file).toURL());
989          }
990        catch(java.net.MalformedURLException x)
991          {
992          }
993      }
994    
995    private static URL[] getSystemClassLoaderUrls()    private static URL[] getSystemClassLoaderUrls()
996    {    {
997      String classpath = getSystemProperty("java.class.path", ".");      String classpath = getSystemProperty("java.class.path", ".");
998      StringTokenizer tok = new StringTokenizer(classpath, File.pathSeparator);      StringTokenizer tok = new StringTokenizer(classpath, File.pathSeparator, true);
999      ArrayList list = new ArrayList();      ArrayList list = new ArrayList();
1000      while (tok.hasMoreTokens())      while (tok.hasMoreTokens())
1001        {        {
1002          try          String s = tok.nextToken();
1003            {          if (s.equals(File.pathSeparator))
1004              list.add(new File(tok.nextToken()).toURL());              addFileURL(list, ".");
1005            }          else
         catch(java.net.MalformedURLException x)  
1006            {            {
1007                addFileURL(list, s);
1008                if (tok.hasMoreTokens())
1009                  {
1010                    // Skip the separator.
1011                    tok.nextToken();
1012                    // If the classpath ended with a separator,
1013                    // append the current directory.
1014                    if (!tok.hasMoreTokens())
1015                        addFileURL(list, ".");
1016                  }
1017            }            }
1018        }        }
1019      URL[] urls = new URL[list.size()];      URL[] urls = new URL[list.size()];

Legend:
Removed from v.1.31.2.2  
changed lines
  Added in v.1.31.2.3

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26