xom-interest AT lists.ibiblio.org
Subject: XOM API for Processing XML with Java
List archive
Re: [XOM-interest] CanonicalXMLSerializer exceptions
- From: Janek Bogucki <janekdb AT yahoo.co.uk>
- To: Elliotte Harold <elharo AT metalab.unc.edu>, xom-interest <xom-interest AT lists.ibiblio.org>
- Cc:
- Subject: Re: [XOM-interest] CanonicalXMLSerializer exceptions
- Date: Mon, 10 Nov 2003 14:25:57 +0000 (GMT)
--- Elliotte Harold <elharo AT metalab.unc.edu> wrote:
> Currently in CanonicalXMLSerializer methods such as setLineSeparator()
> and setMaxLength() ignore their arguments because the canonicalization
> algorithm sets certain required values for these properties. For
> example, in caonical XML the line break must be a linefeed. Therefore
> the code for setLineSeparator() looks like this:
>
> public final void setLineSeparator(String lineSeparator) {
> super.setLineSeparator("\n"); }
>
> I have an open question as to whether I should throw an exception if
> someone passes in something else such as "\r". Is it better to silently
> do the right and required thing here? (current behavior) or should I
> warn clients when they attempt to do the wrong thing by throwing an
> IllegalArgumentException? I'm leaning toward throwing the exception,
> but I'm open to discussion and argument about this. I'd also be curious
> if anyone has references to suggested programming practices (e.g. Bloch
> item #s) that are squarely on point here.
>
> Hmm, one more point that argues in favor of throwing the exception: the
> superclass (Serializer) variants of these methods to throw exceptions
> when illegal values such as NEL are passed to these methods. So it's not
> out of the question or unexpected for these methods to throw an
> IllegalArgumentException. On the other hand throwing the exception for
> different values the superclass will accept means I'd be tightening the
> preconditions on the subclass implementation. I think Bertrand Meyer
> (Object Oriented Software Construction) claims I'm not allowed to do that.
>
> --
> Elliotte
>
One way of ensuring that CanonicalXMLSerializer has less surprising behaviour
and remains a
subtype of Serializer is to move the properties mutators that should not be
used out of Serializer
into a subclass called 'ConfigurableSerializer':
void setIndent(int)
void setLineSeparator(String)
void setMaxLength(int)
void preserveBaseURI(boolean)
Then you get this heirarchy:
Serializer
|
+ ConfigurableSerializer
|
+ CanonicalXMLSerializer
This is an improvement as the inappropriate setter methods do not exist on
CanonicalXMLSerializer
and any method expecting a Serializer will not be surprised by
IllegalArgumentExceptions.
An alternative would be to make Serializer and CanonicalXMLSerializer
immutable by setting all
configuration via the constructor, possibly using a parameter object to keep
the API uncluttered.
(How about changing 'void preserveBaseURI(boolean)' to 'void
setPreserveBaseURI(boolean)'. Then
Serializer becomes more JavaBeanie.)
-Janek
________________________________________________________________________
Want to chat instantly with your online friends? Get the FREE Yahoo!
Messenger http://mail.messenger.yahoo.co.uk
-
[XOM-interest] CanonicalXMLSerializer exceptions,
Elliotte Harold, 11/08/2003
- Re: [XOM-interest] CanonicalXMLSerializer exceptions, John Cowan, 11/09/2003
-
Re: [XOM-interest] CanonicalXMLSerializer exceptions,
Janek Bogucki, 11/10/2003
- Re: [XOM-interest] CanonicalXMLSerializer exceptions, Elliotte Rusty Harold, 11/10/2003
-
Re: [XOM-interest] CanonicalXMLSerializer exceptions,
Elliotte Rusty Harold, 11/10/2003
-
Re: [XOM-interest] CanonicalXMLSerializer exceptions,
Nils_Kilden-Pedersen, 11/11/2003
-
Re: [XOM-interest] CanonicalXMLSerializer exceptions,
Janek Bogucki, 11/13/2003
-
Re: [XOM-interest] CanonicalXMLSerializer exceptions,
Elliotte Rusty Harold, 11/13/2003
-
Re: [XOM-interest] CanonicalXMLSerializer exceptions,
John Cowan, 11/13/2003
- Re: [XOM-interest] CanonicalXMLSerializer exceptions, Elliotte Rusty Harold, 11/13/2003
-
Re: [XOM-interest] CanonicalXMLSerializer exceptions,
John Cowan, 11/13/2003
-
Re: [XOM-interest] CanonicalXMLSerializer exceptions,
Elliotte Rusty Harold, 11/13/2003
-
Re: [XOM-interest] CanonicalXMLSerializer exceptions,
Janek Bogucki, 11/13/2003
-
Re: [XOM-interest] CanonicalXMLSerializer exceptions,
Nils_Kilden-Pedersen, 11/11/2003
Archive powered by MHonArc 2.6.24.