Class URLHandlers
- All Implemented Interfaces:
ContentHandlerFactory
,URLStreamHandlerFactory
This class is a singleton and implements the stream and content handler factories for all framework instances executing within the JVM. Any calls to retrieve stream or content handlers is routed through this class and it acts as a multiplexer for all framework instances. To achieve this, all framework instances register with this class when they are created so that it can maintain a centralized registry of instances.
When this class receives a request for a stream or content handler, it always returns a proxy handler instead of only returning a proxy if a handler currently exists. This approach is used for three reasons:
- Potential caching behavior by the JVM of stream handlers does not give you a second chance to provide a handler.
- Due to the dynamic nature of OSGi services, handlers may appear at any time, so always creating a proxy makes sense.
- Since these handler factories service all framework instances, some instances may have handlers and others may not, so returning a proxy is the only answer that makes sense.
It is possible to disable the URL Handlers service by setting the framework.service.urlhandlers configuration property to false. When multiple framework instances are in use, if no framework instances enable the URL Handlers service, then the singleton stream and content factories will never be set (i.e., URL.setURLStreamHandlerFactory() and URLConnection.setContentHandlerFactory()). However, if one instance enables URL Handlers service, then the factory methods will be invoked. In that case, framework instances that disable the URL Handlers service will simply not provide that services to their contained bundles, while framework instances with the service enabled will.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final Class[]
private static final String
private static final Map
private static final Map
private static Map
private static ContentHandlerFactory
private static int
private static final List
private static URLHandlers
private static final Map
private static final boolean
private static Object
private static final SecureAction
private static SecurityManagerEx
private static Map
private static URLStreamHandlerFactory
private static final String
private static final String
private static final Class
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprivate
Only one instance of this class is created per classloader and that one instance is registered as the stream and content handler factories for the JVM. -
Method Summary
Modifier and TypeMethodDescriptionprivate URLStreamHandler
addToCache
(String protocol, URLStreamHandler result) private Object
addToCache
(Map cache, String key, Object value) private ContentHandler
addToContentCache
(String mimeType, ContentHandler handler) private URLStreamHandler
addToStreamCache
(String protocol, URLStreamHandler handler) createContentHandler
(String mimeType) This is a method implementation for the ContentHandlerFactory interface.createURLStreamHandler
(String protocol) This is a method implementation for the URLStreamHandlerFactory interface.private URLStreamHandler
getBuiltInStreamHandler
(String protocol, URLStreamHandlerFactory factory) static Object
This method returns the system bundle context for the caller.private ContentHandler
getFromContentCache
(String mimeType) private URLStreamHandler
getFromStreamCache
(String protocol) private void
init
(String protocol, URLStreamHandlerFactory factory) private URLStreamHandler
loadBuiltInStreamHandler
(String protocol, ClassLoader classLoader) static void
registerFrameworkInstance
(Object framework, boolean enable) Static method that adds a framework instance to the centralized instance registry.(package private) static void
registerFrameworkListsForContextSearch
(ClassLoader index, List frameworkLists) static void
unregisterFrameworkInstance
(Object framework) Static method that removes a framework instance from the centralized instance registry.(package private) static void
-
Field Details
-
CLASS_TYPE
-
URLHANDLERS_CLASS
-
m_secureAction
-
m_sm
-
m_handler
-
m_classloaderToFrameworkLists
-
m_frameworks
-
m_counter
private static int m_counter -
m_contentHandlerCache
-
m_streamHandlerCache
-
m_streamHandlerFactory
-
m_contentHandlerFactory
-
STREAM_HANDLER_PACKAGE_PROP
- See Also:
-
DEFAULT_STREAM_HANDLER_PACKAGE
- See Also:
-
m_rootURLHandlers
-
m_streamPkgs
-
m_builtIn
-
m_loaded
private static final boolean m_loaded -
m_handlerToURL
-
-
Constructor Details
-
URLHandlers
private URLHandlers()Only one instance of this class is created per classloader and that one instance is registered as the stream and content handler factories for the JVM. Unless, we already register one from a different classloader. In this case we attach to this root.
-
-
Method Details
-
init
-
registerFrameworkListsForContextSearch
-
unregisterFrameworkListsForContextSearch
-
getBuiltInStreamHandler
-
loadBuiltInStreamHandler
-
addToCache
-
createURLStreamHandler
This is a method implementation for the URLStreamHandlerFactory interface. It simply creates a stream handler proxy object for the specified protocol. It caches the returned proxy; therefore, subsequent requests for the same protocol will receive the same handler proxy.
- Specified by:
createURLStreamHandler
in interfaceURLStreamHandlerFactory
- Parameters:
protocol
- the protocol for which a stream handler should be returned.- Returns:
- a stream handler proxy for the specified protocol.
-
createContentHandler
This is a method implementation for the ContentHandlerFactory interface. It simply creates a content handler proxy object for the specified mime type. It caches the returned proxy; therefore, subsequent requests for the same content type will receive the same handler proxy.
- Specified by:
createContentHandler
in interfaceContentHandlerFactory
- Parameters:
mimeType
- the mime type for which a content handler should be returned.- Returns:
- a content handler proxy for the specified mime type.
-
addToContentCache
-
getFromContentCache
-
addToStreamCache
-
getFromStreamCache
-
addToCache
-
registerFrameworkInstance
Static method that adds a framework instance to the centralized instance registry.
- Parameters:
framework
- the framework instance to be added to the instance registry.enable
- a flag indicating whether or not the framework wants to enable the URL Handlers service.
-
unregisterFrameworkInstance
Static method that removes a framework instance from the centralized instance registry.
- Parameters:
framework
- the framework instance to be removed from the instance registry.
-
getFrameworkFromContext
This method returns the system bundle context for the caller. It determines the appropriate system bundle by retrieving the class call stack and find the first class that is loaded from a bundle. It then checks to see which of the registered framework instances owns the class and returns its system bundle context.
- Returns:
- the system bundle context associated with the caller or null if no associated framework was found.
-