[Biojava-dev] Re: StAX questions
Michael L. Heuer
heuermh@acm.org
Wed, 27 Nov 2002 15:26:55 -0500 (EST)
Ok. I've found two ways to do this, one using a nested class
class ParentHandler ...
{
private List children;
private ChildHandler childHandler = new ChildHandler();
public void startTree(..) { children = new ArrayList(); }
public void startElement(...)
{
if ("child".equals(qName))
dctx.delegate(childHandler);
}
private class ChildHandler ...
{
private Child child;
public void startTree(..) { child = new Child(); }
public void endTree(..) { children.add(child); return child; }
public void startElement(...)
{
child.setName(...attr.getValue();...);
}
}
}
the other as two classes at the same level
class ParentHandler ...
{
private List children;
private ChildHandler childHandler = new ChildHandler();
public void startTree(..) { children = new ArrayList(); }
public void startElement(...)
{
if ("child".equals(qName))
dctx.delegate(childHandler);
}
public void endElement(..., Object dResult, ...)
{
Child child = (Child) dResult;
children.add(child);
}
}
class ChildHandler ...
{
private Child child;
public void startTree(..) { child = new Child(); }
public void endTree(..) { return child; }
public void startElement(...)
{
child.setName(...attr.getValue();...);
}
}
michael
On Tue, 26 Nov 2002, Michael L. Heuer wrote:
> Hello,
>
> Two more questions about StAX,
>
> 1. would it be possible to make DispatchOnElement.ByQName and friends
> non-final? I end up duplicating the funcationality of DispatchOnElement
> in subclasses of StAXContentHandlerBase just because I need to parse
> attributes, for instance.
>
> 2. when you return an object from public void endTree(StAXContext ctx),
> where does it go? I've used StAX on several occassions now and always
> have this feeling like I'd have to type a lot less if I fully understood
> what was going on.
>
> given
>
> <parent>
> <children>
> <child name="child0" />
> <child name="child1" />
> </children>
> </parent>
>
> one has something like
>
> class ParentHandler ...
> {
> private List children;
> private ChildHandler childHandler = new ChildHandler();
>
> public void startTree(..) { children = new ArrayList(); }
> public void startElement(...)
> {
> if ("child".equals(qName))
> dctx.delegate(childHandler);
> }
>
> private class ChildHandler ...
> {
> private Child child;
>
> public void startTree(..) { child = new Child(); }
> public void endTree(..) { return child; }
> public void startElement(...)
> {
> child.setName(...attr.getValue...);
> }
> }
> }
>
> where's the best place to add child to the children list in ParentHandler?
>
> Maybe I'd like to see something like
>
> public void startElement(...)
> {
> if ("child".equals(qName))
> {
> children.add( (Child) dctx.delegate(childHandler) );
> }
> }
>
> Thank you in advance,
>
> michael
>
> _______________________________________________
> biojava-dev mailing list
> biojava-dev@biojava.org
> http://biojava.org/mailman/listinfo/biojava-dev
>