Revision: 7736
Author: victormote
Date: 2006-06-24 08:56:43 -0700 (Sat, 24 Jun 2006)
ViewCVS: http://svn.sourceforge.net/foray/?rev=7736&view=rev
Log Message:
-----------
Extract method for registration with the Java environment to make it easier to reuse and reference.
Modified Paths:
--------------
trunk/foray/foray-common/src/java/org/foray/common/url/AbstractURLStreamHandler.java
Modified: trunk/foray/foray-common/src/java/org/foray/common/url/AbstractURLStreamHandler.java
===================================================================
--- trunk/foray/foray-common/src/java/org/foray/common/url/AbstractURLStreamHandler.java 2006-06-24 15:55:16 UTC (rev 7735)
+++ trunk/foray/foray-common/src/java/org/foray/common/url/AbstractURLStreamHandler.java 2006-06-24 15:56:43 UTC (rev 7736)
@@ -42,7 +42,10 @@
/**
* Register an instance of this class with the custom
* URLStreamHandlerFactory so that this handler will be used for URLs of
- * protocol "classpath".
+ * a specific type.
+ * @param protocol The name of the protocol to register.
+ * @param handler The handler that should be registered to handle URLs of
+ * type <code>protocol</code>.
*/
protected static void register(String protocol, URLStreamHandler handler) {
/* Validate the input. */
@@ -57,6 +60,15 @@
FOrayURLStreamHandlerFactory factory =
FOrayURLStreamHandlerFactory.getURLStreamHandlerFactory();
+ if (factory == null) {
+ /* If factory is null, it is because something got registered in
+ * URL.setURLStreamHandlerFactory(URLStreamHandlerFactory)
+ * before our FOrayURLStreamHandlerFactory could register.
+ * Therefore, the best we can do is register ours with the Java
+ * environment "java.protocol.handler.pkgs". */
+ registerInEnvironment(protocol, handler);
+ }
+
/* See if this protocol is already registered with the factory. */
URLStreamHandler registeredHandler = factory.createURLStreamHandler(
protocol);
@@ -77,7 +89,17 @@
* about it either. */
return;
}
+ }
+ /**
+ * Registers a specific protocol handler by making it available to the
+ * Java property "java.protocol.handler.pkgs".
+ * @param protocol The name of the protocol to register.
+ * @param handler An instance of the class that should be registered to
+ * handle URLs of type <code>protocol</code>.
+ */
+ private static void registerInEnvironment(String protocol,
+ URLStreamHandler handler) {
/* The FOray Factory will not be able to register itself with Java in a
* case where other software running has already registered another
* URLStreamHandlerFactory first.
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|