diff options
author | mkoch <mkoch@138bc75d-0d04-0410-961f-82ee72b054a4> | 2003-09-27 12:38:05 +0000 |
---|---|---|
committer | mkoch <mkoch@138bc75d-0d04-0410-961f-82ee72b054a4> | 2003-09-27 12:38:05 +0000 |
commit | 67b247e4c10e0411f46aec7a32647c8594e53b84 (patch) | |
tree | bd343e17cde3ce8c7460374042e97685cbdf6aa0 /libjava/java/net/URL.java | |
parent | 6d60bd48a21116e026c64ccaa55eda3a75aeb869 (diff) | |
download | ppe42-gcc-67b247e4c10e0411f46aec7a32647c8594e53b84.tar.gz ppe42-gcc-67b247e4c10e0411f46aec7a32647c8594e53b84.zip |
2003-09-27 Michael Koch <konqueror@gmx.de>
* java/net/URL.java (getURLStreamHandler):
Check if we have to use cache before trying to retrieve handler from
cache. Rename facName to clsName to match classpath more. Reformated
some little pieces.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@71852 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libjava/java/net/URL.java')
-rw-r--r-- | libjava/java/net/URL.java | 53 |
1 files changed, 32 insertions, 21 deletions
diff --git a/libjava/java/net/URL.java b/libjava/java/net/URL.java index 2db8c4dd1cd..0e0f3186945 100644 --- a/libjava/java/net/URL.java +++ b/libjava/java/net/URL.java @@ -753,18 +753,21 @@ public final class URL implements Serializable { URLStreamHandler ph; - // See if a handler has been cached for this protocol. - if ((ph = (URLStreamHandler) ph_cache.get(protocol)) != null) - return ph; + // First, see if a protocol handler is in our cache. + if (cache_handlers) + { + if ((ph = (URLStreamHandler) ph_cache.get(protocol)) != null) + return ph; + } // If a non-default factory has been set, use it to find the protocol. if (factory != null) { - ph = factory.createURLStreamHandler(protocol); + ph = factory.createURLStreamHandler (protocol); } else if (protocol.equals ("core")) { - ph = new gnu.gcj.protocol.core.Handler (); + ph = new gnu.gcj.protocol.core.Handler(); } else if (protocol.equals ("file")) { @@ -778,7 +781,7 @@ public final class URL implements Serializable // fix this problem. If other protocols are required in a // statically linked application they will need to be handled in // the same way as "file". - ph = new gnu.gcj.protocol.file.Handler (); + ph = new gnu.gcj.protocol.file.Handler(); } // Non-default factory may have returned null or a factory wasn't set. @@ -793,22 +796,30 @@ public final class URL implements Serializable propVal = (propVal == null) ? "" : (propVal + "|"); propVal = propVal + "gnu.gcj.protocol|sun.net.www.protocol"; - StringTokenizer pkgPrefix = new StringTokenizer(propVal, "|"); + // Finally loop through our search path looking for a match. + StringTokenizer pkgPrefix = new StringTokenizer (ph_search_path, "|"); + do - { - String facName = pkgPrefix.nextToken() + "." + protocol + - ".Handler"; - try - { - ph = (URLStreamHandler) Class.forName(facName).newInstance(); - } - catch (Exception e) - { - // Can't instantiate; handler still null, go on to next element. - } - } while ((ph == null || - ! (ph instanceof URLStreamHandler)) && - pkgPrefix.hasMoreTokens()); + { + String clsName = pkgPrefix.nextToken() + "." + protocol + ".Handler"; + + try + { + Object obj = Class.forName (clsName).newInstance(); + + if (!(obj instanceof URLStreamHandler)) + continue; + else + ph = (URLStreamHandler) obj; + } + catch (Exception e) + { + // Can't instantiate; handler still null, go on to next element. + } + } + while ((ph == null || + !(ph instanceof URLStreamHandler)) + && pkgPrefix.hasMoreTokens()); } // Update the hashtable with the new protocol handler. |