Revision: 7760
Author: victormote
Date: 2006-07-07 18:53:53 -0700 (Fri, 07 Jul 2006)
ViewCVS: http://svn.sourceforge.net/foray/?rev=7760&view=rev
Log Message:
-----------
Roll up doc and code related to the property-based registration.
Modified Paths:
--------------
trunk/foray/foray-common/src/java/org/foray/common/url/AbstractURLStreamHandler.java
trunk/foray/foray-common/src/java/org/foray/common/url/PropertyProtocolRegistration.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-07-08 01:42:02 UTC (rev 7759)
+++ trunk/foray/foray-common/src/java/org/foray/common/url/AbstractURLStreamHandler.java 2006-07-08 01:53:53 UTC (rev 7760)
@@ -30,7 +30,6 @@
import java.net.URLStreamHandler;
-import java.util.StringTokenizer;
/**
* Abstract superclass for all URLStreamHandlers using the FOray scheme for
@@ -65,7 +64,14 @@
* 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);
+ /* 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.
+ */
+ PropertyProtocolRegistration.propertyRegistration(protocol,
+ handler);
return;
}
@@ -85,71 +91,4 @@
factory.registerProtocol(protocol, handler);
}
- /**
- * 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.
- * 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);
- }
-
}
Modified: trunk/foray/foray-common/src/java/org/foray/common/url/PropertyProtocolRegistration.java
===================================================================
--- trunk/foray/foray-common/src/java/org/foray/common/url/PropertyProtocolRegistration.java 2006-07-08 01:42:02 UTC (rev 7759)
+++ trunk/foray/foray-common/src/java/org/foray/common/url/PropertyProtocolRegistration.java 2006-07-08 01:53:53 UTC (rev 7760)
@@ -48,8 +48,11 @@
}
/**
- * @param protocol
- * @param handler
+ * 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>.
*/
public static void propertyRegistration(String protocol,
URLStreamHandler handler) {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|