org.foray.common.url
Class ProtocolRegistrationBroker

java.lang.Object
  extended by org.foray.common.url.ProtocolRegistrationBroker

public final class ProtocolRegistrationBroker
extends Object

Manages which ProtocolRegistrationStrategy is used to register new custom URL protocol handlers. Only one strategy can be used within a session. Java provides two methods for registering these protocol handlers, one found in URLStreamHandlerFactory (the Factory scheme), and the other using the "java.protocol.handler.pkgs" Java property (the Property scheme). Each of these schemes has drawbacks.

This class can register the following implementations using its setStandardRegistrationStrategy(int) method:

In addition to the standard strategies described above, custom strategies can be registered using setRegistrationStrategy(ProtocolRegistrationStrategy). This may be useful in cases where a URLStreamHandlerFactory has been registered by some third-party and the developer wishes to use it to get URL handlers registered. AbstractProtocolRegistration is an abstract implementation of ProtocolRegistrationStrategy which may be a useful starting place for custom implementations.


Field Summary
static byte FACTORY_REGISTRATION_STRATEGY
          Constant indicating that the "factory" method should be used for URL handler registration.
static byte PROPERTY_REGISTRATION_STRATEGY
          Constant indicating that the "property" method should be used for URL handler registration.
static byte UNIVERSAL_REGISTRATION_STRATEGY
          Constant indicating that any URL handler registration strategy is acceptable.
 
Method Summary
static ProtocolRegistrationStrategy getRegistrationStrategy()
          Provides access to the chosen protocol registration strategy, or to a default one if none has been set.
static URLStreamHandler getURLStreamHandler(String protocol)
          Convenience method making registered protocol handler available in a static way.
static void setRegistrationStrategy(ProtocolRegistrationStrategy strategy)
          Sets the strategy which will be used within the application for registering custom URL protocol handlers.
static void setStandardRegistrationStrategy(int strategy)
          Factory method that knows how to create any of the standard URL Protocol Registration strategies.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

UNIVERSAL_REGISTRATION_STRATEGY

public static final byte UNIVERSAL_REGISTRATION_STRATEGY
Constant indicating that any URL handler registration strategy is acceptable.

See Also:
Constant Field Values

PROPERTY_REGISTRATION_STRATEGY

public static final byte PROPERTY_REGISTRATION_STRATEGY
Constant indicating that the "property" method should be used for URL handler registration.

See Also:
Constant Field Values

FACTORY_REGISTRATION_STRATEGY

public static final byte FACTORY_REGISTRATION_STRATEGY
Constant indicating that the "factory" method should be used for URL handler registration.

See Also:
Constant Field Values
Method Detail

setStandardRegistrationStrategy

public static void setStandardRegistrationStrategy(int strategy)
Factory method that knows how to create any of the standard URL Protocol Registration strategies.

Parameters:
strategy - One of UNIVERSAL_REGISTRATION_STRATEGY, PROPERTY_REGISTRATION_STRATEGY, or FACTORY_REGISTRATION_STRATEGY.

setRegistrationStrategy

public static void setRegistrationStrategy(ProtocolRegistrationStrategy 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 strategy over the default strategy. The default strategy is UniversalProtocolRegistration, and it will be selected automatically unless this method is used to set a different strategy before the first call to the getRegistrationStrategy() method.

Parameters:
strategy - the registry used to record custom URL protocol handlers

getRegistrationStrategy

public static ProtocolRegistrationStrategy getRegistrationStrategy()
Provides access to the chosen protocol registration strategy, or to a default one if none has been set.

Returns:
The ProtocolRegistrationStrategy to be used for custom URL handler registration for this session.

getURLStreamHandler

public static URLStreamHandler getURLStreamHandler(String protocol)
Convenience method making registered protocol handler available in a static way.

Parameters:
protocol - The protocol for which a Handler is sought.
Returns:
The Handler for protocol, or null if it has not been registered.


Copyright © 2017. All rights reserved.