[FOray-commit] SF.net SVN: foray: [7679] trunk/foray/foray-common/src/java/org/foray/common
Modular XSL-FO Implementation for Java.
Status: Alpha
Brought to you by:
victormote
|
From: <vic...@us...> - 2006-06-17 18:57:42
|
Revision: 7679 Author: victormote Date: 2006-06-17 11:57:37 -0700 (Sat, 17 Jun 2006) ViewCVS: http://svn.sourceforge.net/foray/?rev=7679&view=rev Log Message: ----------- Make the exception thrown a checked one so that at least someone knows it failed. Modified Paths: -------------- trunk/foray/foray-common/src/java/org/foray/common/ClasspathHandler.java trunk/foray/foray-common/src/java/org/foray/common/FOrayURLStreamHandlerFactory.java Modified: trunk/foray/foray-common/src/java/org/foray/common/ClasspathHandler.java =================================================================== --- trunk/foray/foray-common/src/java/org/foray/common/ClasspathHandler.java 2006-06-17 18:27:04 UTC (rev 7678) +++ trunk/foray/foray-common/src/java/org/foray/common/ClasspathHandler.java 2006-06-17 18:57:37 UTC (rev 7679) @@ -41,6 +41,8 @@ */ public class ClasspathHandler extends URLStreamHandler { + private static final String PROTOCOL = "classpath"; + protected URLConnection openConnection(URL u) { return new URLConnection(u) { public void connect() {} @@ -68,8 +70,27 @@ public static void register() { FOrayURLStreamHandlerFactory factory = FOrayURLStreamHandlerFactory.getURLStreamHandlerFactory(); - ClasspathHandler handler = new ClasspathHandler(); - factory.registerProtocol("classpath", handler); + URLStreamHandler handler = factory.getHandler( + ClasspathHandler.PROTOCOL); + if (handler != null) { + /* If already registed, that one is the one being used, and there + * is no way to change it. */ + return; + } + handler = new ClasspathHandler(); + if (handler == null) { + return; + } + try { + factory.registerProtocol(ClasspathHandler.PROTOCOL, handler); + } catch (IOException e) { + /* This should never happen. We have already checked whether the + * protocol is previously registered, and we know that neither the + * protocol or handler are null. The only thing we could do is + * pass the exception upstream, but there is nothing they can do + * about it either. */ + return; + } } } Modified: trunk/foray/foray-common/src/java/org/foray/common/FOrayURLStreamHandlerFactory.java =================================================================== --- trunk/foray/foray-common/src/java/org/foray/common/FOrayURLStreamHandlerFactory.java 2006-06-17 18:27:04 UTC (rev 7678) +++ trunk/foray/foray-common/src/java/org/foray/common/FOrayURLStreamHandlerFactory.java 2006-06-17 18:57:37 UTC (rev 7679) @@ -26,10 +26,10 @@ package org.foray.common; +import java.io.IOException; import java.net.URL; import java.net.URLStreamHandler; import java.net.URLStreamHandlerFactory; -import java.security.InvalidParameterException; import java.util.HashMap; /** @@ -73,31 +73,41 @@ * @param protocol The protocol to be registered. * @param handler The {@link URLStreamHandler} instance which should be * used for URLs whose protocol is <code>protocol</code>. - * @throws InvalidParameterException For any of the following reasons: + * @throws IOException For any of the following reasons: * <ul> * <li>If <code>protocol</code> or <code>handlerClass</code> are * null.</li> * <li>If <code>protocol</code> has already been registered</li> * </ul> */ - public void registerProtocol(String protocol, URLStreamHandler handler) - throws InvalidParameterException { + public void registerProtocol(String protocol, URLStreamHandler handler) + throws IOException { if (protocol == null) { - throw new InvalidParameterException("Cannot register a null " + throw new IOException("Cannot register a null " + "protocol."); } if (handler == null) { - throw new InvalidParameterException("Cannot register a null " + throw new IOException("Cannot register a null " + "URLStreamHandler."); } if (this.protocols.containsKey(protocol)) { - throw new InvalidParameterException("Protocol \n" + protocol + throw new IOException("Protocol \n" + protocol + "\" has already been registered."); } this.protocols.put(protocol, handler); } /** + * Provides the handler for a given protocol. + * @param protocol The protocol whose handler is desired. + * @return True iff <code>protocol</code> has previously been registered. + */ + public URLStreamHandler getHandler(String protocol) { + Object object = this.protocols.get(protocol); + return (URLStreamHandler) object; + } + + /** * Provides access to a custom URLStreamHandlerFactory instance, creating * it and registering it with Java if needed. * @return The custom URLStreamHandlerFactory instance for this session. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |