Revision: 7771
Author: victormote
Date: 2006-07-08 11:27:56 -0700 (Sat, 08 Jul 2006)
ViewCVS: http://svn.sourceforge.net/foray/?rev=7771&view=rev
Log Message:
-----------
Use delegate scheme, as per Vincent Hennebert's latest patch.
Modified Paths:
--------------
trunk/foray/foray-common/src/java/org/foray/common/url/UniversalProtocolRegistration.java
Modified: trunk/foray/foray-common/src/java/org/foray/common/url/UniversalProtocolRegistration.java
===================================================================
--- trunk/foray/foray-common/src/java/org/foray/common/url/UniversalProtocolRegistration.java 2006-07-08 18:04:47 UTC (rev 7770)
+++ trunk/foray/foray-common/src/java/org/foray/common/url/UniversalProtocolRegistration.java 2006-07-08 18:27:56 UTC (rev 7771)
@@ -38,57 +38,39 @@
* Registers URL protocols in a universal manner, attempting first to register
* using a {@link URLStreamHandlerFactory}, then using the Java properties
* method as a fallback.
- * @see PropertyProtocolRegistration which registers only using the Java
- * properties method.
+ * @see FactoryProtocolRegistration which registers using only the
+ * {@link URLStreamHandlerFactory} scheme.
+ * @see PropertyProtocolRegistration which registers using only the Java
+ * properties scheme.
*/
public class UniversalProtocolRegistration
- extends AbstractProtocolRegistration {
+ implements ProtocolRegistrationStrategy {
/**
+ * The object which will actually do the registration. The
+ * URLStreamHandlerFactory will first be tried; if it fails, the
+ * property-based method will be used as a fallback.
+ */
+ private ProtocolRegistrationStrategy delegate;
+
+ /**
* Constructor.
*/
public UniversalProtocolRegistration() {
+ FactoryProtocolRegistration factory = new FactoryProtocolRegistration();
+ if (factory.isValid()) {
+ delegate = factory;
+ } else {
+ delegate = new PropertyProtocolRegistration();
+ }
}
/**
* {@inheritDoc}
*/
- public void doRegister(String protocol, URLStreamHandler handler) {
- /* Get the Factory instance. */
- 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". */
- /* 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;
- }
-
- /* See if this protocol is already registered with the factory. */
- URLStreamHandler registeredHandler = factory.createURLStreamHandler(
- protocol);
- if (registeredHandler != null) {
- /* If already registed, that one is the one being used, and there
- * is no way to change it. If it has in fact not yet been used,
- * then registering this now would make the new one used instead
- * of the old one. However, until we have some indication that this
- * would be the "right" thing to do, we will not. */
- return;
- }
-
- /* Register the protocol with the Factory. */
- factory.registerProtocol(protocol, handler);
+ public void registerProtocolHandler(String protocol,
+ URLStreamHandler handler) {
+ delegate.registerProtocolHandler(protocol, handler);
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|