Re: Exceptions in Attribues(2), AttributesImpl

"Karl Waclawek" <[email protected]> Sun, 16 Nov 2003 03:46:33 -0500
Newsgroups gmane.text.xml.sax.devel
Message-ID <000e01c3ac1e$23885740$0207a8c0@karl>
> Hi, Karl --
> 
> > Is there any good reason I have overlooked why it should
> > be the way it is?
> 
> The by-name getters are used for the purpose of testing for the 
> presence of an attribute as much as getting its value, and something 
> like this:
> 
> String s = atts.getValue("foo");
> if (s != null) {
>   doStuff(s);
> }
> 
> is preferable to something like this:
> 
> if (isSet("foo")) {
>    String s = atts.getValue("foo");
>    doStuff(s);
> }
> 
> If for nothing else, the former is more in the habit of Java 
> programmers, but also it saves two traversals of the internal data 
> structure.  (The same would be true for an implementation of Attributes 
> backed by Collection APIs.)

Well, I understand all of this, but it is inconsistent with
the setters in Attributes and the getters in Attributes2,
which all raise exceptions.

Also, the getIndex() methods provide an easy way to test
and then access without double traversal, as the second
access is by index and therefore direct and cheap.

If one really wants to do it in one call, the proper way
is to separate the requested value from the success/failure
information. For instance, one could define a boolean return
value for all methods (indicating success or failure), and pass
the requested value back by setting some property on an object 
passed as argument, or vice versa, by passing some "status"
object where one can check certain flags on return from the call
(the second method is one that I like to use myself).

By piggy-backing on the object nature of string one
is forced to do it differently where the requested value
is not an object (like for isDeclared, isSpecified), or
where there is no return value (like for the setters).

Karl




-------------------------------------------------------
This SF. Net email is sponsored by: GoToMyPC
GoToMyPC is the fast, easy and secure way to access your computer from
any Web browser or wireless device. Click here to Try it Free!
https://www.gotomypc.com/tr/OSDN/AW/Q4_2003/t/g22lp?Target=mm/g22lp.tmpl
_______________________________________________
List: sax-devel, [email protected]
See:  http://www.saxproject.org/
https://lists.sourceforge.net/lists/listinfo/sax-devel