blob: 07f128be060ed2f44ea62a651a5a1e391ebe08c1 [file] [log] [blame]
package org.eclipse.core.internal.boot;
/*
* Licensed Materials - Property of IBM,
* WebSphere Studio Workbench
* (c) Copyright IBM Corp 2000
*/
import java.net.*;
import java.util.*;
public class PlatformURLHandlerFactory implements URLStreamHandlerFactory {
private static Hashtable handlers = new Hashtable();
public PlatformURLHandlerFactory() {
super();
// register eclipse handler
handlers.put(PlatformURLHandler.PROTOCOL, new PlatformURLHandler());
}
public URLStreamHandler createURLStreamHandler(String protocol) {
URLStreamHandler handler = null;
// check for cached handler
Object element = handlers.get(protocol);
if (element==null) return null;
if (element instanceof URLStreamHandler) handler = (URLStreamHandler)element;
else {
// convert registered factory to a handler
URLStreamHandlerFactory f = (URLStreamHandlerFactory) element;
handler = f.createURLStreamHandler(protocol);
if (handler!=null) handlers.put(protocol, handler);
else handlers.remove(protocol); // bad entry
}
return handler;
}
public static void register(String protocol, URLStreamHandlerFactory factory) {
if (protocol.equals(PlatformURLHandler.PROTOCOL)) return; // just in case ...
handlers.put(protocol,factory);
}
public static void shutdown() {
PlatformURLHandlerFactoryProxy p = PlatformURLHandlerFactoryProxy.getFactoryProxy();
if (p!=null) p.setFactory(null);
PlatformURLConnection.shutdown();
}
public static void startup(String location) {
PlatformURLHandlerFactoryProxy p = PlatformURLHandlerFactoryProxy.getFactoryProxy();
if (p==null) {
p = new PlatformURLHandlerFactoryProxy();
URL.setURLStreamHandlerFactory(p);
}
p.setFactory(new PlatformURLHandlerFactory());
PlatformURLConnection.startup(location);
}
}