/[classpath]/classpath/java/net/URL.java
ViewVC logotype

Diff of /classpath/java/net/URL.java

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

revision 1.30 by mark, Fri Apr 23 17:37:46 2004 UTC revision 1.31 by mark, Thu Jul 1 22:56:17 2004 UTC
# Line 1  Line 1 
1  /* URL.java -- Uniform Resource Locator Class  /* URL.java -- Uniform Resource Locator Class
2     Copyright (C) 1998, 1999, 2000, 2002, 2003  Free Software Foundation, Inc.     Copyright (C) 1998, 1999, 2000, 2002, 2003, 2004
3       Free Software Foundation, Inc.
4    
5  This file is part of GNU Classpath.  This file is part of GNU Classpath.
6    
# Line 38  exception statement from your version. * Line 39  exception statement from your version. *
39  package java.net;  package java.net;
40    
41  import gnu.java.net.URLParseError;  import gnu.java.net.URLParseError;
42    import java.security.AccessController;
43    import java.security.PrivilegedAction;
44  import java.io.IOException;  import java.io.IOException;
45  import java.io.InputStream;  import java.io.InputStream;
46  import java.io.ObjectInputStream;  import java.io.ObjectInputStream;
# Line 123  public final class URL implements Serial Line 126  public final class URL implements Serial
126    private static final String DEFAULT_SEARCH_PATH =    private static final String DEFAULT_SEARCH_PATH =
127      "gnu.java.net.protocol|gnu.inet";      "gnu.java.net.protocol|gnu.inet";
128    
129      // Cached System ClassLoader
130      private static ClassLoader systemClassLoader;
131    
132    /**    /**
133     * The name of the protocol for this URL.     * The name of the protocol for this URL.
134     * The protocol is always stored in lower case.     * The protocol is always stored in lower case.
# Line 854  public final class URL implements Serial Line 860  public final class URL implements Serial
860          // Finally loop through our search path looking for a match.          // Finally loop through our search path looking for a match.
861          StringTokenizer pkgPrefix = new StringTokenizer(ph_search_path, "|");          StringTokenizer pkgPrefix = new StringTokenizer(ph_search_path, "|");
862    
863          do          // Cache the systemClassLoader
864            if (systemClassLoader == null)
865            {            {
866              String clsName =              systemClassLoader = (ClassLoader) AccessController.doPrivileged
867                (pkgPrefix.nextToken() + "." + protocol + ".Handler");                (new PrivilegedAction() {
868                      public Object run() {
869                        return ClassLoader.getSystemClassLoader();
870                      }
871                    });
872              }
873    
874            do
875              {
876              try              try
877                {                {
878                  Object obj = Class.forName(clsName).newInstance();                  // Try to get a class from the system/application
879                    // classloader, initialize it, make an instance
880                  if (! (obj instanceof URLStreamHandler))                  // and try to cast it to a URLStreamHandler.
881                    continue;                  String clsName =
882                  else                    (pkgPrefix.nextToken() + "." + protocol + ".Handler");
883                    ph = (URLStreamHandler) obj;                  Class c = Class.forName(clsName, true, systemClassLoader);
884                }                  ph = (URLStreamHandler) c.newInstance();
             catch (Exception e)  
               {  
                 // Can't instantiate; handler still null,  
                 // go on to next element.  
885                }                }
886                catch (Throwable t) { /* ignored */ }
887            }            }
888           while ((! (ph instanceof URLStreamHandler))           while (ph == null && pkgPrefix.hasMoreTokens());
                 && pkgPrefix.hasMoreTokens());  
889        }        }
890    
891      // Update the hashtable with the new protocol handler.      // Update the hashtable with the new protocol handler.
892      if (ph != null && cache_handlers)      if (ph != null && cache_handlers)
893        if (ph instanceof URLStreamHandler)        ph_cache.put(protocol, ph);
894          ph_cache.put(protocol, ph);      else
895        else        ph = null;
         ph = null;  
896    
897      return ph;      return ph;
898    }    }

Legend:
Removed from v.1.30  
changed lines
  Added in v.1.31

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