URL.java (getURLStreamHandler): Check if we have to use cache before trying to retrieve handler from cache.

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.

From-SVN: r71852
This commit is contained in:
Michael Koch 2003-09-27 12:38:05 +00:00 committed by Michael Koch
parent 9415397d87
commit 4ada1976c9
2 changed files with 39 additions and 21 deletions

View File

@ -1,3 +1,10 @@
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.
2003-09-27 Michael Koch <konqueror@gmx.de> 2003-09-27 Michael Koch <konqueror@gmx.de>
* gnu/java/nio/SelectionKeyImpl.java * gnu/java/nio/SelectionKeyImpl.java

View File

@ -753,18 +753,21 @@ public final class URL implements Serializable
{ {
URLStreamHandler ph; URLStreamHandler ph;
// See if a handler has been cached for this protocol. // First, see if a protocol handler is in our cache.
if ((ph = (URLStreamHandler) ph_cache.get(protocol)) != null) if (cache_handlers)
return ph; {
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 a non-default factory has been set, use it to find the protocol.
if (factory != null) if (factory != null)
{ {
ph = factory.createURLStreamHandler(protocol); ph = factory.createURLStreamHandler (protocol);
} }
else if (protocol.equals ("core")) else if (protocol.equals ("core"))
{ {
ph = new gnu.gcj.protocol.core.Handler (); ph = new gnu.gcj.protocol.core.Handler();
} }
else if (protocol.equals ("file")) 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 // fix this problem. If other protocols are required in a
// statically linked application they will need to be handled in // statically linked application they will need to be handled in
// the same way as "file". // 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. // 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 == null) ? "" : (propVal + "|");
propVal = propVal + "gnu.gcj.protocol|sun.net.www.protocol"; 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 do
{ {
String facName = pkgPrefix.nextToken() + "." + protocol + String clsName = pkgPrefix.nextToken() + "." + protocol + ".Handler";
".Handler";
try try
{ {
ph = (URLStreamHandler) Class.forName(facName).newInstance(); Object obj = Class.forName (clsName).newInstance();
}
catch (Exception e) if (!(obj instanceof URLStreamHandler))
{ continue;
// Can't instantiate; handler still null, go on to next element. else
} ph = (URLStreamHandler) obj;
} while ((ph == null || }
! (ph instanceof URLStreamHandler)) && catch (Exception e)
pkgPrefix.hasMoreTokens()); {
// 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. // Update the hashtable with the new protocol handler.