class URLHandlers
extends java.lang.Object
implements java.net.URLStreamHandlerFactory, java.net.ContentHandlerFactory
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:
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.
| Modifier and Type | Field and Description |
|---|---|
private static java.lang.Class[] |
CLASS_TYPE |
private static java.lang.String |
DEFAULT_STREAM_HANDLER_PACKAGE |
private static java.util.Map |
m_builtIn |
private static java.util.Map |
m_classloaderToFrameworkLists |
private static java.util.Map |
m_contentHandlerCache |
private static java.net.ContentHandlerFactory |
m_contentHandlerFactory |
private static int |
m_counter |
private static java.util.List |
m_frameworks |
private static URLHandlers |
m_handler |
private static java.util.Map |
m_handlerToURL |
private static boolean |
m_loaded |
private static java.lang.Object |
m_rootURLHandlers |
private static SecureAction |
m_secureAction |
private static SecurityManagerEx |
m_sm |
private static java.util.Map |
m_streamHandlerCache |
private static java.net.URLStreamHandlerFactory |
m_streamHandlerFactory |
private static java.lang.String |
m_streamPkgs |
private static java.lang.String |
STREAM_HANDLER_PACKAGE_PROP |
private static java.lang.Class |
URLHANDLERS_CLASS |
| Modifier | Constructor and Description |
|---|---|
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.
|
| Modifier and Type | Method and Description |
|---|---|
private java.lang.Object |
addToCache(java.util.Map cache,
java.lang.String key,
java.lang.Object value) |
private java.net.URLStreamHandler |
addToCache(java.lang.String protocol,
java.net.URLStreamHandler result) |
private java.net.ContentHandler |
addToContentCache(java.lang.String mimeType,
java.net.ContentHandler handler) |
private java.net.URLStreamHandler |
addToStreamCache(java.lang.String protocol,
java.net.URLStreamHandler handler) |
java.net.ContentHandler |
createContentHandler(java.lang.String mimeType)
This is a method implementation for the ContentHandlerFactory
interface.
|
java.net.URLStreamHandler |
createURLStreamHandler(java.lang.String protocol)
This is a method implementation for the URLStreamHandlerFactory
interface.
|
private java.net.URLStreamHandler |
getBuiltInStreamHandler(java.lang.String protocol,
java.net.URLStreamHandlerFactory factory) |
static java.lang.Object |
getFrameworkFromContext()
This method returns the system bundle context for the caller.
|
private java.net.ContentHandler |
getFromContentCache(java.lang.String mimeType) |
private java.net.URLStreamHandler |
getFromStreamCache(java.lang.String protocol) |
private void |
init(java.lang.String protocol,
java.net.URLStreamHandlerFactory factory) |
private java.net.URLStreamHandler |
loadBuiltInStreamHandler(java.lang.String protocol,
java.lang.ClassLoader classLoader) |
static void |
registerFrameworkInstance(java.lang.Object framework,
boolean enable)
Static method that adds a framework instance to the centralized
instance registry.
|
(package private) static void |
registerFrameworkListsForContextSearch(java.lang.ClassLoader index,
java.util.List frameworkLists) |
static void |
unregisterFrameworkInstance(java.lang.Object framework)
Static method that removes a framework instance from the centralized
instance registry.
|
(package private) static void |
unregisterFrameworkListsForContextSearch(java.lang.ClassLoader index) |
private static final java.lang.Class[] CLASS_TYPE
private static final java.lang.Class URLHANDLERS_CLASS
private static final SecureAction m_secureAction
private static volatile SecurityManagerEx m_sm
private static volatile URLHandlers m_handler
private static final java.util.Map m_classloaderToFrameworkLists
private static final java.util.List m_frameworks
private static int m_counter
private static java.util.Map m_contentHandlerCache
private static java.util.Map m_streamHandlerCache
private static java.net.URLStreamHandlerFactory m_streamHandlerFactory
private static java.net.ContentHandlerFactory m_contentHandlerFactory
private static final java.lang.String STREAM_HANDLER_PACKAGE_PROP
private static final java.lang.String DEFAULT_STREAM_HANDLER_PACKAGE
private static java.lang.Object m_rootURLHandlers
private static final java.lang.String m_streamPkgs
private static final java.util.Map m_builtIn
private static final boolean m_loaded
private static final java.util.Map m_handlerToURL
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.
private void init(java.lang.String protocol,
java.net.URLStreamHandlerFactory factory)
static void registerFrameworkListsForContextSearch(java.lang.ClassLoader index,
java.util.List frameworkLists)
static void unregisterFrameworkListsForContextSearch(java.lang.ClassLoader index)
private java.net.URLStreamHandler getBuiltInStreamHandler(java.lang.String protocol,
java.net.URLStreamHandlerFactory factory)
private java.net.URLStreamHandler loadBuiltInStreamHandler(java.lang.String protocol,
java.lang.ClassLoader classLoader)
private java.net.URLStreamHandler addToCache(java.lang.String protocol,
java.net.URLStreamHandler result)
public java.net.URLStreamHandler createURLStreamHandler(java.lang.String protocol)
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.
createURLStreamHandler in interface java.net.URLStreamHandlerFactoryprotocol - the protocol for which a stream handler should be returned.public java.net.ContentHandler createContentHandler(java.lang.String mimeType)
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.
createContentHandler in interface java.net.ContentHandlerFactorymimeType - the mime type for which a content handler should be returned.private java.net.ContentHandler addToContentCache(java.lang.String mimeType,
java.net.ContentHandler handler)
private java.net.ContentHandler getFromContentCache(java.lang.String mimeType)
private java.net.URLStreamHandler addToStreamCache(java.lang.String protocol,
java.net.URLStreamHandler handler)
private java.net.URLStreamHandler getFromStreamCache(java.lang.String protocol)
private java.lang.Object addToCache(java.util.Map cache,
java.lang.String key,
java.lang.Object value)
public static void registerFrameworkInstance(java.lang.Object framework,
boolean enable)
Static method that adds a framework instance to the centralized instance registry.
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.public static void unregisterFrameworkInstance(java.lang.Object framework)
Static method that removes a framework instance from the centralized instance registry.
framework - the framework instance to be removed from the instance
registry.public static java.lang.Object 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.