Peter and Mark (mostly),
On Mon, 7 Jun 2004, Peter W. Draper wrote:
> Mark & Norman (mostly),
>
> [...]
> Playing around with all this has left me with the impression that the URL
> class is a mess, as it's possible to construct illegal states quite
> easily, and it offers little to help you out of the mess. URI seems a much
> better formulated class, so should probably be the one to use when there's
> a choice.
I just looked at this now, and I hadn't realised how shoddy the URL
class is. Two things:
I discovered that the File class has a toURI method, which presumably
handles whatever escaping of the `prefix' (ie, drive-letter) is
necessary. Therefore it looks as if any file URIs or URLs that are
being constructed should go via that route.
I wondered about simply removing the urlToUri method, but realised that
it's used in such contexts as getImage().getURL(): getImage must return
a URL rather than a URI, since it really has to be dereferencable -- it
doesn't make sense to have a non-dereferenceable URI being returned
here. Instead, I suggest rewriting urlToUri by decomposing the URL and
reconstructing it with a multi-argument URI constructor, which does
_all_ the necessary escaping. Secondly, I'll have it throw a
HdxException rather than an AssertionError.
That extra exception would require a few code changes here and there --
urlToUri is used in
./hdx/src/main/uk/ac/starlink/hdx/HdxFactory.java
./ndx/src/main/uk/ac/starlink/ndx/BridgeNdx.java
./ndx/src/main/uk/ac/starlink/ndx/XMLNdxHandler.java
./fits/src/main/uk/ac/starlink/fits/FitsNdxHandler.java
./fits/src/main/uk/ac/starlink/fits/FitsArrayBuilder.java
./treeview/src/main/uk/ac/starlink/treeview/NdxDataNode.java
Only two of those contexts aren't already catching HdxExceptions, and
it's fairly obvious what to do in the other cases. That's mostly Mark's
code -- is it OK if I go ahead here, Mark?
Is there a case for a util-specific subclass of HdxException here? I
don't think so, but could be persuaded.
See you,
Norman
--
---------------------------------------------------------------------------
Norman Gray http://www.astro.gla.ac.uk/users/norman/
Physics and Astronomy, University of Glasgow, UK [log in to unmask]
|