commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Simon Kitching <si...@ecnetwork.co.nz>
Subject Re: [digester] how to use digester with a class hierarchy
Date Wed, 19 May 2004 05:03:24 GMT
On Wed, 2004-05-19 at 16:43, Bill Keese wrote:
> Thanks Simon!
> 
> > All the existing Digester object creation options
> > (ObjectCreateRule, FactoryCreateRule) create the target object when the
> > opening xml tag is found.
> 
> I see. In that case, I need to create the Text object when the <text>
> tag is encountered. The question is, how do I save the information that
> appears before the <text> tag?

Yes, that's exactly the problem.

> 
> <component>
> <x>10</x> <y>20</y>
> <text> Hello world </text>
> </component>
> 
> I suppose that I could have some kind of dummy ComponentBuilder class
> which would sit at the root of the stack and save the x/y value.
> Something like this, maybe:
> 
> digester.addObjectCreate("component", ComponentBuilder.class);
> digester.addSetNext("component/x", "addX"); // save x in ComponentBuilder
> digester.addSetNext("component/y", "addY"); // save y in ComponentBuilder
> digester.setTopRule("component/text", "setXY"); // initialialize Text.x
> and Text.y
> // from values saved in ComponentBuilder
> digester.addSetNext("component/text", "setComponent"); // stores Text
> obj in ComponentBuilder obj
> 
> ComponentBuilder foo = (ComponentBuilder) digester.parse();
> Component realResult = foo.getComponent();
> 
> It's a bit ugly, but not so bad.

I don't see how you are going to compose bigger data structures with
this. The rules shown above build a ComponentBuilder object on the
digester object stack. This object may have an object of the correct
subtype within it (eg a Text object), but you can't access that easily
with the Digester rules. For example, how will you add the Text object
to a parent object? The SetNextRule will attempt to pass the
ComponentBuilder object to the parent, not the Text object.


It would be cool if you could get this working, but I suspect it will be
pretty challenging...


Regards,

Simon


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Mime
View raw message