Revision: 7705
Author: victormote
Date: 2006-06-19 10:02:20 -0700 (Mon, 19 Jun 2006)
ViewCVS: http://svn.sourceforge.net/foray/?rev=7705&view=rev
Log Message:
-----------
Add backup scheme to find the class using java.protocol.handler.pkgs, as per Vincent Hennebert's original plan.
Modified Paths:
--------------
trunk/foray/foray-common/src/java/org/foray/common/AbstractURLStreamHandler.java
Modified: trunk/foray/foray-common/src/java/org/foray/common/AbstractURLStreamHandler.java
===================================================================
--- trunk/foray/foray-common/src/java/org/foray/common/AbstractURLStreamHandler.java 2006-06-19 16:07:09 UTC (rev 7704)
+++ trunk/foray/foray-common/src/java/org/foray/common/AbstractURLStreamHandler.java 2006-06-19 17:02:20 UTC (rev 7705)
@@ -30,6 +30,7 @@
import java.io.IOException;
import java.net.URLStreamHandler;
+import java.util.StringTokenizer;
/**
* Abstract superclass for all URLStreamHandlers using the FOray scheme for
@@ -75,6 +76,63 @@
* about it either. */
return;
}
+
+ /* 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.
+ * Therefore, we will give Java another opportunity to find our custom
+ * handler by placing its location in the Java environment.
+ */
+
+ /* Parse the path. */
+ Class theClass = handler.getClass();
+ String classPath = theClass.getName();
+ int lastTokenDelimiter = classPath.lastIndexOf('.');
+ String className = classPath.substring(lastTokenDelimiter + 1,
+ classPath.length());
+
+ /* Validate the class name. */
+ if (! className.equals("Handler")) {
+ return;
+ }
+
+ Package thePackage = theClass.getPackage();
+ String packageName = thePackage.getName();
+ lastTokenDelimiter = packageName.lastIndexOf('.');
+ String lastSubPackage = packageName.substring(lastTokenDelimiter + 1,
+ packageName.length());
+ /* The last sub-package must be equal to the name of the protocol, or
+ * Java won't find it. */
+ if (! lastSubPackage.equals(protocol)) {
+ return;
+ }
+
+ /* Add the packagePrefix to the Java search path. */
+ String packagePrefix = packageName.substring(0, lastTokenDelimiter);
+ String javaProperty = "java.protocol.handler.pkgs";
+ String searchPath = System.getProperty(javaProperty);
+
+ /* The search path doesn't exist. Create it. */
+ if (searchPath == null) {
+ System.setProperty(javaProperty, packagePrefix);
+ return;
+ }
+
+ /* The search path does exist. See if the package prefix is already
+ * registered. */
+ StringTokenizer packagePrefixIter = new StringTokenizer(
+ searchPath, "|");
+ while (packagePrefixIter.hasMoreTokens()) {
+ String token = packagePrefixIter.nextToken();
+ if (token.equals(packagePrefix)) {
+ /* It is already registered. No need to do it again. */
+ return;
+ }
+ }
+
+ /* It is not registered, so we need to add it. */
+ searchPath += "|" + packagePrefix;
+ System.setProperty(javaProperty, searchPath);
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|