Now that generics provide us with some compile-time checking of the
class argument, let's stop with the runtime checking. git-svn-id: https://samskivert.googlecode.com/svn/trunk@2288 6335cc39-0255-0410-8fd6-9bcaacd3b74c
This commit is contained in:
@@ -43,11 +43,6 @@ public class AttachableURLFactory implements URLStreamHandlerFactory
|
|||||||
public static void attachHandler (
|
public static void attachHandler (
|
||||||
String protocol, Class<? extends URLStreamHandler> handlerClass)
|
String protocol, Class<? extends URLStreamHandler> handlerClass)
|
||||||
{
|
{
|
||||||
if (!URLStreamHandler.class.isAssignableFrom(handlerClass)) {
|
|
||||||
throw new IllegalArgumentException(
|
|
||||||
"Specified class is not a java.net.URLStreamHandler.");
|
|
||||||
}
|
|
||||||
|
|
||||||
// set up the factory.
|
// set up the factory.
|
||||||
if (_handlers == null) {
|
if (_handlers == null) {
|
||||||
_handlers = new HashMap<String,Class<? extends URLStreamHandler>>();
|
_handlers = new HashMap<String,Class<? extends URLStreamHandler>>();
|
||||||
@@ -92,8 +87,7 @@ public class AttachableURLFactory implements URLStreamHandlerFactory
|
|||||||
// documentation inherited from interface URLStreamHandlerFactory
|
// documentation inherited from interface URLStreamHandlerFactory
|
||||||
public URLStreamHandler createURLStreamHandler (String protocol)
|
public URLStreamHandler createURLStreamHandler (String protocol)
|
||||||
{
|
{
|
||||||
Class<? extends URLStreamHandler> handler =
|
Class<? extends URLStreamHandler> handler = _handlers.get(protocol.toLowerCase());
|
||||||
_handlers.get(protocol.toLowerCase());
|
|
||||||
if (handler != null) {
|
if (handler != null) {
|
||||||
try {
|
try {
|
||||||
return handler.newInstance();
|
return handler.newInstance();
|
||||||
@@ -106,6 +100,5 @@ public class AttachableURLFactory implements URLStreamHandlerFactory
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** A mapping of protocol name to handler classes. */
|
/** A mapping of protocol name to handler classes. */
|
||||||
protected static HashMap<String,Class<? extends URLStreamHandler>>
|
protected static HashMap<String,Class<? extends URLStreamHandler>> _handlers;
|
||||||
_handlers;
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user