Interface Plurl
- All Known Implementing Classes:
PlurlImpl
URL.setURLStreamHandlerFactory(URLStreamHandlerFactory)
and
URLConnection.setContentHandlerFactory(ContentHandlerFactory)
. Plurl
factories may be added and removed using the add and remove methods or using
the plurl
protocol.
The plurl
protocol allows factories to be added even
if the installed plurl implementation is not using the same
org.eclipse.equinox.plurl package as the factories being registered. A plurl
implementation must handle this case by reflecting on the plurl factories
that are added. A plurl factory can be added and removed with the plurl
protocol like this:
PlurlStreamHandlerFactory myStreamFactory = getStreamFactory(); PlurlContentHandlerFactory myContentFactory = getContentFactory(); ((Consumer<URLStreamHandlerFactory>) ("plurl://op/addURLStreamHandlerFactory").getContent()).accept(myStreamFactory); ((Consumer<ContentHandlerFactory>) ("plurl://op/addContentHandlerFactory").getContent()).accept(myContentFactory); ((Consumer<URLStreamHandlerFactory>) ("plurl://op/removeURLStreamHandlerFactory").getContent()) .accept(myStreamFactory); ((Consumer<ContentHandlerFactory>) ("plurl://op/removeContentHandlerFactory").getContent()).accept(myContentFactory);The content provided by the plurl protocol is of type
Consumer
which
can take either an URLStreamHandlerFactory
or a
ContentHandlerFactory
depending on the operation.
A plurl implementation delegates to the added PlurlFactory
objects.
To select which PlurlFactory
to delegate the
PlurlFactory.shouldHandle(Class)
method is used.
If only one factory has been added to plurl then that PlurlFactory
is
used to create the handler. Otherwise each
PlurlFactory.shouldHandle(Class)
is called for a class in the call
stack until a factory returns true. If no factory returns true then the next
class in the call stack is used. If no factory is found after using all
classes in the call stack then the first factory added is selected. Once a
factory is selected, it is used to create the requested handler. If the
selected factory returns a null
handler then no other factory is
asked to create the handler.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final String
The plurl protocol operation to add a ContentStreamHandlerFactorystatic final String
The plurl protocol operation to add a URLStreamHandlerFactorystatic final String
The value to use for theinstall(String...)
method to indicate that no protocols are forbidden. for overriding by plurl handlers.static final String
The host to use for the "plurl" protocol to indicate an operation for adding or removing factories.static final String
The "plurl" protocol to add and remove plurl factories.static final String
An optional plurl protocol operation to register aPlurl
instance with the current plurl protocol implementation.static final String
The plurl protocol operation to remove a ContentStreamHandlerFactorystatic final String
The plurl protocol operation to remove a URLStreamHandlerFactorystatic final String
An optional plurl protocol operation to unregister aPlurl
instance with the current plurl instance set with the JVM. -
Method Summary
Modifier and TypeMethodDescriptionstatic void
add
(PlurlContentHandlerFactory factory) Adds aPlurlContentHandlerFactory
from aninstalled
plurl implementation.static void
add
(PlurlStreamHandlerFactory factory) Adds aPlurlStreamHandlerFactory
to aninstalled
plurl implementation.void
Installs the plurl factories into the JVM singletons.static void
remove
(PlurlContentHandlerFactory factory) Removes aPlurlContentHandlerFactory
from aninstalled
plurl implementation.static void
remove
(PlurlStreamHandlerFactory factory) Removes aPlurlStreamHandlerFactory
to aninstalled
plurl implementation.void
If this plurl instance is the primordial factory for the JVM then uninstall is a no-op and the plurl instance will remain set with the JVM for the lifetime of the JVM instance.
-
Field Details
-
PLURL_PROTOCOL
The "plurl" protocol to add and remove plurl factories.- See Also:
-
PLURL_OP
The host to use for the "plurl" protocol to indicate an operation for adding or removing factories.- See Also:
-
PLURL_ADD_URL_STREAM_HANDLER_FACTORY
The plurl protocol operation to add a URLStreamHandlerFactory- See Also:
-
PLURL_REMOVE_URL_STREAM_HANDLER_FACTORY
The plurl protocol operation to remove a URLStreamHandlerFactory- See Also:
-
PLURL_ADD_CONTENT_HANDLER_FACTORY
The plurl protocol operation to add a ContentStreamHandlerFactory- See Also:
-
PLURL_REMOVE_CONTENT_HANDLER_FACTORY
The plurl protocol operation to remove a ContentStreamHandlerFactory- See Also:
-
PLURL_REGISTER_IMPLEMENTATION
An optional plurl protocol operation to register aPlurl
instance with the current plurl protocol implementation. This is an optional operation that aPlurl
implementation may implement to allow another plurl instance to be registered as a delegate. A delegate may be used to install the delegate plurl instance when the current plurl getsuninstalled
.- See Also:
-
PLURL_UNREGISTER_IMPLEMENTATION
An optional plurl protocol operation to unregister aPlurl
instance with the current plurl instance set with the JVM. This is an optional operation that aPlurl
implementation may implement to allow another plurl instance to be unregistered as a delegate.- See Also:
-
PLURL_FORBID_NOTHING
The value to use for theinstall(String...)
method to indicate that no protocols are forbidden. for overriding by plurl handlers.- See Also:
-
-
Method Details
-
install
Installs the plurl factories into the JVM singletons. If plurl factories are already installed then this plurl instance isregistered
with the existing plurl instance set with the JVM by using something like the following:((Consumer<Object>) ("plurl://op/plurlRegisterImplementation").getContent()).accept(this);
If the plurl factories cannot be installed then anIllegalStateException
is thrown.If the JVM singletons are already set with other factories that are not plurl then an attempt is made to override the JVM singletons with this plurl instance. This may only be possible if the implementation is allowed to do deep reflection on the
java.net
package. If the JVM singletons are overriden then the original singleton factory instances must be used as parent factories of the plurl instance until the plurl instance isuninstalled
. if overriding the JVM singletons is not possible then anIllegalStateException
is thrown.If the JVM singletons were not overriden then this plurl instance is considered the primordial singleton factory for the JVM. Such a plurl instance cannot be
uninstalled
and will live the lifetime of the JVM.When this method returns without throwing an exception then the following will be true:
- The singleton
URL.setURLStreamHandlerFactory(URLStreamHandlerFactory)
is set with a plurl implementation which delegates to thePlurlStreamHandlerFactory
objects that have beenadded
. - The singleton
URLConnection.setContentHandlerFactory(ContentHandlerFactory)
is set with a plurl implementation which delegates to thePlurlContentHandlerFactory
objects that have beenadded
. - The
plurl
protocol is available for creatingURL
objects. - If plurl factories are already installed then this plurl implementation is registered as a delegate with the already installed plurl instance.
- Parameters:
forbidden
- builtin JVM protocols that cannot be overridden by plurl. If no forbidden protocols are specified then the default forbidden protocols are 'jar', 'jmod', 'file', and 'jrt'. To forbid no protocols then use the valuePLURL_FORBID_NOTHING
- Throws:
IllegalStateException
- if the Plurl factories cannot be installed
- The singleton
-
uninstall
void uninstall()If this plurl instance is the primordial factory for the JVM then uninstall is a no-op and the plurl instance will remain set with the JVM for the lifetime of the JVM instance.If this plurl is not the primordial factory and is the current plurl set with the JVM singletons then this plurl instance must do the following:
- Reset the original parent factories as the singleton factories of the JVM
- If there are any other plurl instances that got
registered
with this plurl instance then one of the registered plurl instances must be selected to be the next delegate plurl instance toinstall
. - If a delegate plurl instance gets installed then any existing factories
that were added to this plurl instance must be added to the new delegate
plurl instance and any
registered
plurl instances must be registered with the new delegate plurl instance. - This plurl instance must release all references to other factories or plurl instances.
registered
with the existing plurl instance set with the JVM by using something like the following:((Consumer<Object>) ("plurl://op/plurlRegisterImplementation").getContent()).accept(this);
-
add
Adds aPlurlStreamHandlerFactory
to aninstalled
plurl implementation. If there is no plurl implementation installed then anIOException
is thrown. The plurl implementation must not hold any strong references to the factory. If the factory is garbage collected then the plurl implementation must behave as if the factory gotremoved
.This is a convenience method for using the plurl protocol like this:
((Consumer<URLStreamHandlerFactory>) ("plurl://op/addURLStreamHandlerFactory").getContent()).accept(factory);
- Parameters:
factory
- the PlurlStreamHandlerFactory to add- Throws:
IOException
- if there is no plurl implementation installed or there was an error adding the factory
-
remove
Removes aPlurlStreamHandlerFactory
to aninstalled
plurl implementation. If there is no plurl implementation installed then anIOException
is thrown.This is a convenience method for using the plurl protocol like this:
((Consumer<URLStreamHandlerFactory>) ("plurl://op/removeURLStreamHandlerFactory").getContent()).accept(factory);
- Parameters:
factory
- the PlurlStreamHandlerFactory to remove- Throws:
IOException
- if there is no plurl implementation installed or there was an error removing the factory
-
add
Adds aPlurlContentHandlerFactory
from aninstalled
plurl implementation. If there is no plurl implementation installed then anIOException
is thrown. The plurl implementation must not hold any strong references to the factory. If the factory is garbage collected then the plurl implementation must behave as if the factory gotremoved
.This is a convenience method for using the plurl protocol like this:
((Consumer<ContentHandlerFactory>) ("plurl://op/addContentHandlerFactory").getContent()).accept(factory);
- Parameters:
factory
- the PlurlContentHandlerFactory to add- Throws:
IOException
- if there is no plurl implementation installed or there was an error adding the factory
-
remove
Removes aPlurlContentHandlerFactory
from aninstalled
plurl implementation. If there is no plurl implementation installed then anIOException
is thrown.This is a convenience method for using the plurl protocol like this:
((Consumer<ContentHandlerFactory>) ("plurl://op/removeContentHandlerFactory").getContent()).accept(factory);
- Parameters:
factory
- the PlurlContentHandlerFactory to remove- Throws:
IOException
- if there is no plurl implementation installed or there was an error removing the factory
-