/[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.17 by mkoch, Sun Jul 20 09:20:17 2003 UTC revision 1.18 by mkoch, Sat Sep 27 12:41:56 2003 UTC
# Line 771  public final class URL implements Serial Line 771  public final class URL implements Serial
771    {    {
772      URLStreamHandler ph;      URLStreamHandler ph;
773    
774      // First, see if a protocol handler is in our cache      // First, see if a protocol handler is in our cache.
775      if (cache_handlers)      if (cache_handlers)
776        {        {
777          Class cls = (Class)ph_cache.get(protocol);          Class cls = (Class) ph_cache.get (protocol);
778            
779          if (cls != null)          if (cls != null)
780            {            {
781              try              try
782                {                {
783                  ph = (URLStreamHandler)cls.newInstance();                  return (URLStreamHandler) cls.newInstance();
784                  return(ph);                }
785                catch (Exception e)
786                  {
787                    // Can't instantiate; handler still null.
788                }                }
             catch (Exception e) { ; }  
789            }            }
790        }        }
791    
792      // If a non-default factory has been set, use it to find the protocol.      // If a non-default factory has been set, use it to find the protocol.
793      if (factory != null)      if (factory != null)
794        {        {
795          ph = factory.createURLStreamHandler(protocol);          ph = factory.createURLStreamHandler (protocol);
         if (ph != null)  
           {  
             if (cache_handlers)  
               ph_cache.put(protocol, ph.getClass());  
   
             return(ph);  
           }  
796        }        }
797    
798      // Finally loop through our search path looking for a match      // Non-default factory may have returned null or a factory wasn't set.
799      StringTokenizer st = new StringTokenizer(ph_search_path, "|");      // Use the default search algorithm to find a handler for this protocol.
800      while (st.hasMoreTokens())      if (ph == null)
801        {        {
802          String clsname = st.nextToken() + "." + protocol + ".Handler";          // Finally loop through our search path looking for a match.
803                    StringTokenizer pkgPrefix = new StringTokenizer (ph_search_path, "|");
804          try          
805            while (pkgPrefix.hasMoreTokens())
806            {            {
807              Class cls = Class.forName(clsname);              String clsName = pkgPrefix.nextToken() + "." + protocol + ".Handler";
808              Object obj = cls.newInstance();          
809              if (!(obj instanceof URLStreamHandler))              try
810                continue;                {
811              else                  Object obj = Class.forName (clsName).newInstance();
812                ph = (URLStreamHandler)obj;              
813                    if (!(obj instanceof URLStreamHandler))
814              if (cache_handlers)                    continue;
815                ph_cache.put(protocol, cls);                  else
816                      ph = (URLStreamHandler) obj;
817              return(ph);                }
818                catch (Exception e)
819                  {
820                    // Can't instantiate; handler still null, go on to next element.
821                  }
822            }            }
         catch (Exception e) { ; }  
823        }        }
824    
825      // Still here, which is bad      // Update the hashtable with the new protocol handler.
826      return null;      if (ph != null
827            && cache_handlers)
828          if (ph instanceof URLStreamHandler)
829            ph_cache.put (protocol, ph.getClass());
830          else
831            ph = null;
832    
833        return ph;
834    }    }
835    
836    private void readObject(ObjectInputStream ois)    private void readObject(ObjectInputStream ois)

Legend:
Removed from v.1.17  
changed lines
  Added in v.1.18

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