Name: jn10789 Date: 11/18/98
This is still a big problem in JDK 1.2beta4.1...
independently developed JavaBeans have NO WAY to
work together with multiple URLStreamHandlers
for new protocols. There is a simple, elegant
fix that does not break the APIs and I address it
in detail below:
If an application is built from a set of complex
independently-developed third-party beans, and at
least two of those beans has
defined its own URLStreamHandlers for a custom
URL protocol, at least one of those beans will
fail to register its stream handler.
This is because the static method in class URL:
"setURLStreamHandlerFactory" can only be called
once, and there is no way to find out what factory
is currently registered.
There are at least two solutions to this problem.
One (not preferred because it breaks the current
semantics of the API) is to allow multiple
URLStreamHandlerFactory objects to be registered,
with each successive factory being the first
one consulted with when resolving a protocol type
(i.e., consult them in last-registered to first
order).
The better solution is to make the method
setURLStreamHandlerFactory() a synchronized
static method and change the return type from
"void" to URLStreamHandlerFactory. It must not
throw an Error if you call it more than once.
Instead, it registers the given
URLStreamHandlerFactory in place of the current
one (if any) and it returns the now replaced
URLStreamHandlerFactory from the method.
Now you have almost the same semantics, BUT a
smart bean will take the return value and
proxy to that URLStreamHandlerFactory if it
can't resolve a certain protocol.
This way, any number of URLStreamHandlerFactories
can be chained together.
Here is the new method declaration in URL:
public static synchronized URLStreamHandlerFactory setURLStreamHandlerFactory(URLStreamHandlerFactory fac)
The sooner you get this change into your APIs, the
sooner bean writers can follow these guidelines
and not be stepping on each other.
(Review ID: 37863)
======================================================================
- duplicates
-
JDK-4191103 Two beans can't add new URLStreamHandlers
-
- Closed
-
-
JDK-4191106 Two beans can't add new URLStreamHandlers
-
- Closed
-
- relates to
-
JDK-8262102 java.net.URL setURLStreamHandlerFactory can be called only once per VM.
-
- Open
-