Gianugo Rabellino wrote:
Murray Altheim wrote:
I thought perhaps if I needed an answer to this question, others
might as well. I also figure that someone on this list has the
answer to this one at their fingertips...
For those programming in Java, the java.net.URL class is
ubiquitous. But creating a URL with 'xmldb' such as
xmldb:xindice-embed:///db/documentation/overview
will result in
[java] java.net.MalformedURLException: unknown protocol: xmldb
[java] at java.net.URL.<init>(URL.java:586)
[java] at java.net.URL.<init>(URL.java:476)
[...]
which never feels all that much like a warm puppy or a cold beer.
So the question is: how does one register a new protocol in Java
so that you can create xmldb URLs and obtain a valid String when
doing getProtocol()?
URLStreamHandlerFactory is your friend and foe. It's your friend since
it allows you to add a custom protocol to Java, it's your foe since only
exactly ONE additional protocol per JVM is allowed. I think that the
double colon issue can be somehow solves, but this limitation is quite
hard to digest...
Gianugo,
In reading over the javadocs for this, I didn't get that impression
at all. The docs for URL do state that
setURLStreamHandlerFactory(URLStreamHandlerFactory fac)
allows only one call per JVM, but that's for setting the factory,
not the protocol. The factory itself seems to be able to receive
any number of registrations using
createURLStreamHandler(String protocol)
so I *think* this isn't an issue. What I've been googling around for
is how to create the URLStreamHandler for a custom protocol, since
the one for 'xmldb' doesn't exist (and may be the reason the xmldb URLs
throw an exception upon creation).
What it sounds like is that one would extend the URLStreamHandler
(which is an abstract class) in some way to handle the new 'xmldb'
protocol, but this is where I fall flat on my face. I thought perhaps
somebody on this list had done this already...
Murray
......................................................................
Murray Altheim http://kmi.open.ac.uk/people/murray/
Knowledge Media Institute
The Open University, Milton Keynes, Bucks, MK7 6AA, UK .
"Ours is a dangerous time with two relatively new threats,
both of them exacerbated by the Iraq invasion and this
administration's policies. One is the threat of future
terrorism by Osama and al Qaeda. The other is the threat
to our freedoms and our constitutional republic. These
are dangers that were never faced before in my lifetime."
-- Daniel Ellsberg
http://www.sfgate.com/cgi-bin/article.cgi?file=/chronicle/archive/2004/02/29/CMG3R50LHE5.DTL