Revision: 7775
Author: victormote
Date: 2006-07-08 12:08:42 -0700 (Sat, 08 Jul 2006)
ViewCVS: http://svn.sourceforge.net/foray/?rev=7775&view=rev
Log Message:
-----------
Add factory method to the broker, and make the implementation constructors package-private, as per Vincent Hennebert's suggestion.
Modified Paths:
--------------
trunk/foray/foray-common/src/java/org/foray/common/url/AbstractProtocolRegistration.java
trunk/foray/foray-common/src/java/org/foray/common/url/FactoryProtocolRegistration.java
trunk/foray/foray-common/src/java/org/foray/common/url/PropertyProtocolRegistration.java
trunk/foray/foray-common/src/java/org/foray/common/url/ProtocolRegistrationBroker.java
trunk/foray/foray-common/src/java/org/foray/common/url/UniversalProtocolRegistration.java
Modified: trunk/foray/foray-common/src/java/org/foray/common/url/AbstractProtocolRegistration.java
===================================================================
--- trunk/foray/foray-common/src/java/org/foray/common/url/AbstractProtocolRegistration.java 2006-07-08 18:46:02 UTC (rev 7774)
+++ trunk/foray/foray-common/src/java/org/foray/common/url/AbstractProtocolRegistration.java 2006-07-08 19:08:42 UTC (rev 7775)
@@ -29,9 +29,7 @@
import java.net.URLStreamHandler;
/**
- * Abstract implementation of ProtocolHandlerRegistry which factorizes out
- * things common two both registration methods: by using the
- * URL.setURLStreamHandlerFactory of the "java.protocol.handler.pkgs" property.
+ * Abstract implementation of {@link ProtocolRegistrationStrategy}.
*/
public abstract class AbstractProtocolRegistration
implements ProtocolRegistrationStrategy {
Modified: trunk/foray/foray-common/src/java/org/foray/common/url/FactoryProtocolRegistration.java
===================================================================
--- trunk/foray/foray-common/src/java/org/foray/common/url/FactoryProtocolRegistration.java 2006-07-08 18:46:02 UTC (rev 7774)
+++ trunk/foray/foray-common/src/java/org/foray/common/url/FactoryProtocolRegistration.java 2006-07-08 19:08:42 UTC (rev 7775)
@@ -42,6 +42,12 @@
public class FactoryProtocolRegistration
implements ProtocolRegistrationStrategy {
+ /**
+ * Package-private constructor.
+ * Use
+ * {@link ProtocolRegistrationBroker#setStandardRegistrationStrategy(int)}
+ * to use this standard registration scheme.
+ */
public FactoryProtocolRegistration() {
}
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 18:46:02 UTC (rev 7774)
+++ trunk/foray/foray-common/src/java/org/foray/common/url/PropertyProtocolRegistration.java 2006-07-08 19:08:42 UTC (rev 7775)
@@ -49,10 +49,12 @@
protected Map protocols = new HashMap();
/**
- * Constructor.
- * @see ProtocolRegistrationBroker#getRegistrationStrategy
+ * Package-private constructor.
+ * Use
+ * {@link ProtocolRegistrationBroker#setStandardRegistrationStrategy(int)}
+ * to use this standard registration scheme.
*/
- public PropertyProtocolRegistration() {
+ PropertyProtocolRegistration() {
}
void doRegister(String protocol, URLStreamHandler handler) {
Modified: trunk/foray/foray-common/src/java/org/foray/common/url/ProtocolRegistrationBroker.java
===================================================================
--- trunk/foray/foray-common/src/java/org/foray/common/url/ProtocolRegistrationBroker.java 2006-07-08 18:46:02 UTC (rev 7774)
+++ trunk/foray/foray-common/src/java/org/foray/common/url/ProtocolRegistrationBroker.java 2006-07-08 19:08:42 UTC (rev 7775)
@@ -32,10 +32,48 @@
*/
public class ProtocolRegistrationBroker {
+ public static final byte UNIVERSAL_REGISTRATION_STRATEGY = 1;
+ public static final byte PROPERTY_REGISTRATION_STRATEGY = 2;
+ public static final byte FACTORY_REGISTRATION_STRATEGY = 3;
+
/** The singleton instance of {@link ProtocolRegistrationStrategy}. */
private static ProtocolRegistrationStrategy strategy = null;
/**
+ * Factory method that knows how to create any of the standard URL Protocol
+ * Registration strategies.
+ * @param strategy One of {@link #UNIVERSAL_REGISTRATION_STRATEGY},
+ * {@link #PROPERTY_REGISTRATION_STRATEGY}, or
+ * {@link #FACTORY_REGISTRATION_STRATEGY}.
+ */
+ public static synchronized void setStandardRegistrationStrategy(
+ int strategy) {
+ checkAlreadySet();
+ switch (strategy) {
+ case UNIVERSAL_REGISTRATION_STRATEGY: {
+ ProtocolRegistrationBroker.strategy =
+ new UniversalProtocolRegistration();
+ break;
+ }
+ case PROPERTY_REGISTRATION_STRATEGY: {
+ ProtocolRegistrationBroker.strategy =
+ new PropertyProtocolRegistration();
+ break;
+ }
+ case FACTORY_REGISTRATION_STRATEGY: {
+ ProtocolRegistrationBroker.strategy =
+ new FactoryProtocolRegistration();
+ break;
+ }
+ default: {
+ throw new IllegalArgumentException(
+ ProtocolRegistrationBroker.class.getName()
+ + ": invalid standard strategy.");
+ }
+ }
+ }
+
+ /**
* Sets the strategy which will be used within the application for
* registering custom URL protocol handlers.
* This method is provided to accommodate applications that prefer a custom
@@ -48,11 +86,15 @@
*/
public static synchronized void setRegistrationStrategy (
ProtocolRegistrationStrategy strategy) {
+ checkAlreadySet();
+ ProtocolRegistrationBroker.strategy = strategy;
+ }
+
+ private static void checkAlreadySet() {
if (strategy != null) {
String className = ProtocolRegistrationBroker.class.getName();
throw new RuntimeException(className + ": strategy already set");
}
- ProtocolRegistrationBroker.strategy = strategy;
}
/**
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:46:02 UTC (rev 7774)
+++ trunk/foray/foray-common/src/java/org/foray/common/url/UniversalProtocolRegistration.java 2006-07-08 19:08:42 UTC (rev 7775)
@@ -54,9 +54,12 @@
private ProtocolRegistrationStrategy delegate;
/**
- * Constructor.
+ * Package-private constructor.
+ * Use
+ * {@link ProtocolRegistrationBroker#setStandardRegistrationStrategy(int)}
+ * to use this standard registration scheme.
*/
- public UniversalProtocolRegistration() {
+ UniversalProtocolRegistration() {
FactoryProtocolRegistration factory = new FactoryProtocolRegistration();
if (factory.isValid()) {
delegate = factory;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|