Revision: 7735
Author: victormote
Date: 2006-06-24 08:55:16 -0700 (Sat, 24 Jun 2006)
ViewCVS: http://svn.sourceforge.net/foray/?rev=7735&view=rev
Log Message:
-----------
Catch the Error thrown if a factory has already been registered with URL.
Modified Paths:
--------------
trunk/foray/foray-common/src/java/org/foray/common/url/FOrayURLStreamHandlerFactory.java
Modified: trunk/foray/foray-common/src/java/org/foray/common/url/FOrayURLStreamHandlerFactory.java
===================================================================
--- trunk/foray/foray-common/src/java/org/foray/common/url/FOrayURLStreamHandlerFactory.java 2006-06-24 15:07:24 UTC (rev 7734)
+++ trunk/foray/foray-common/src/java/org/foray/common/url/FOrayURLStreamHandlerFactory.java 2006-06-24 15:55:16 UTC (rev 7735)
@@ -45,6 +45,8 @@
/** The singleton instance of this class. */
private static FOrayURLStreamHandlerFactory urlSHFactory;
+ private static boolean registrationAttempted = false;
+
/**
* Map of the protocols.
* The key is a String containing the protocol name.
@@ -108,13 +110,36 @@
*/
public static synchronized FOrayURLStreamHandlerFactory
getURLStreamHandlerFactory() {
- if (FOrayURLStreamHandlerFactory.urlSHFactory == null) {
- FOrayURLStreamHandlerFactory.urlSHFactory
- = new FOrayURLStreamHandlerFactory();
+ createFactory();
+ return FOrayURLStreamHandlerFactory.urlSHFactory;
+ }
+
+ /**
+ * Creates the Singleton instance of this class if it has not already
+ * been created, and if it can be created.
+ */
+ private static void createFactory() {
+ if (FOrayURLStreamHandlerFactory.urlSHFactory != null) {
+ /* Factory is already created. */
+ return;
+ }
+ if (FOrayURLStreamHandlerFactory.registrationAttempted) {
+ /* Registration has already tried and failed. Don't try again. */
+ return;
+ }
+ FOrayURLStreamHandlerFactory.urlSHFactory
+ = new FOrayURLStreamHandlerFactory();
+ try {
URL.setURLStreamHandlerFactory(
FOrayURLStreamHandlerFactory.urlSHFactory);
+ } catch (Error e) {
+ /* If an error is thrown, someone has already registered a
+ * URLStreamHandlerFactory, and we cannot register ours. All we
+ * can do is record the fact. */
+ FOrayURLStreamHandlerFactory.urlSHFactory = null;
+ } finally {
+ FOrayURLStreamHandlerFactory.registrationAttempted = true;
}
- return FOrayURLStreamHandlerFactory.urlSHFactory;
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|