Revision: 7758
Author: victormote
Date: 2006-07-07 18:23:15 -0700 (Fri, 07 Jul 2006)
ViewCVS: http://svn.sourceforge.net/foray/?rev=7758&view=rev
Log Message:
-----------
Part of Vincent's patch. Uses the new Broker class to get the predefined Strategy.
Modified Paths:
--------------
trunk/foray/foray-common/src/java/org/foray/common/url/classpath/Handler.java
Modified: trunk/foray/foray-common/src/java/org/foray/common/url/classpath/Handler.java
===================================================================
--- trunk/foray/foray-common/src/java/org/foray/common/url/classpath/Handler.java 2006-07-08 01:12:47 UTC (rev 7757)
+++ trunk/foray/foray-common/src/java/org/foray/common/url/classpath/Handler.java 2006-07-08 01:23:15 UTC (rev 7758)
@@ -28,7 +28,8 @@
package org.foray.common.url.classpath;
-import org.foray.common.url.AbstractURLStreamHandler;
+import org.foray.common.url.ProtocolRegistrationBroker;
+import org.foray.common.url.ProtocolRegistrationStrategy;
import java.io.IOException;
import java.io.InputStream;
@@ -45,10 +46,12 @@
* <li><code>classpath:path/to/the/resource</code></li>
* </ul>
*/
-public class Handler extends AbstractURLStreamHandler {
+public class Handler extends URLStreamHandler {
private static final String PROTOCOL = "classpath";
+ private static boolean alreadyRegistered = false;
+
protected URLConnection openConnection(URL u) {
return new URLConnection(u) {
public void connect() {}
@@ -69,13 +72,19 @@
}
/**
- * Register an instance of this class with the custom
- * URLStreamHandlerFactory so that this handler will be used for URLs of
- * protocol "classpath".
+ * Register an instance of this class with the given ProtocolHandlerRegistry
+ * so that this handler will be used for URLs of protocol "classpath". This
+ * method may be safely called several times; only the first time will be
+ * the registration done.
*/
- public static void register() {
- URLStreamHandler handler = new Handler();
- AbstractURLStreamHandler.register(Handler.PROTOCOL, handler);
+ public static synchronized void register() {
+ if (!alreadyRegistered) {
+ URLStreamHandler handler = new Handler();
+ ProtocolRegistrationStrategy registry =
+ ProtocolRegistrationBroker.getRegistry();
+ registry.registerProtocolHandler(Handler.PROTOCOL, handler);
+ alreadyRegistered = true;
+ }
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|