[Biojava-l] [StAX] returning objects from delegated ContentHandlers

Thomas Down td2@sanger.ac.uk
Wed, 13 Jun 2001 13:50:29 +0100


Posting this to biojava-l since there isn't really anywhere
else.  Given than StAX doesn't actually have anything to
do with BioJava (other than historically) I'm wondering if
it might be worth setting up a SourceForge project.  Any thoughts?



Anyway, the current status of StAX is that it seems to be
working very nicely for a number of users.  There does seem
to be one recurrant issue that comes up -- how to cleanly
return data from delegate ContentHandlers.  I'm considering
the possibility of one more API change, to try to resolve
this once and for all.  I'd really prefer to avoid changing
the API, but this issue comes up sufficiently frequently that
it might be worth breaking things now rather than later...

The original StAX didn't have any mechanism for ContentHandlers
to return data at all.  The assumption was that each ContentHandler
would have access to some kind of callback for passing any
data back.

After some complaints, the `second draft' of StAX added an extra
parameter on endElement.  If the element was delegated, the delegate
ContentHandler gets passed back.  This has been used quite a bit
in some applications, but it still strikes me as ugly.


Proposed alternative:

  - Change StAXContentHandler.endTree() so that it returns an Object
    (may be null).  To get the existing behaviour:

       public Object endTree() {
           return this;
       }

  - Either:

     + Change the `delegate' parameter on endElement to be the
       returned object

     + add new method "endDelegation(Object returnValue)"


Either version of this solution will require existing handlers to be
changed a little.  I think it will make for cleaner code in the
long term, though.

What's the opinion of this.  Should we have one more round of
polishing on StAX before presenting it to the wider world, or
should it stay as it is?

    Thomas.