commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Simon Kitching <>
Subject Re: [Digester] Create an object using parent attribute
Date Mon, 28 Jun 2004 01:31:22 GMT
On Sat, 2004-06-26 at 03:51, Rob Cash wrote:
> "Bill Keese" <> wrote in message
> >
> > >I'm trying to figure out how I can create an [child] object using a parent
> attribute
> > >value as the className for the child. Here's a sample XML snipet:
> > >
> > ><parent childClass="mypackage.childClass">
> > >   <child attribute1="value1" attribute2="value2"/>
> > >   <child attribute1="value3" attribute2="value4"/>
> > ></parent>
> > >
> > I thought that typically ObjectCreationFactory only looks at the
> > attributes of the element currently being processed, but I suppose you
> > could design one that looked at the value of the top element on the
> > stack. Alternately you could pipe your XML through XSLT to transform it
> > into something more digester-friendly.
> Yeah, I supposed the alternative would be something like this:
> <parent>
>    <child className="mypackage.childClass" attribute1="value1"
> attribute2="value2"/>
>    <child className="mypackage.childClass" attribute1="value3"
> attribute2="value4"/>
> </parent>
> Then i could use the className attribute of the current object on the stack to
> create each child object. I would still have to create my own
> ObjectCreationFactory, though, to use the attribute className as the name of the
> class to use when instantiating the object, right? I didn't see a
> Digester.addObjectCreate() method that would work.

The latter syntax is certainly more "normal" for digester. If you use
this syntax then you can use the FactoryCreateRule with an

Class defaultChildClass = StandardChild.class;
	"parent/child", defaultChildClass, "className");

If your child objects require significant configuration data, then you
may also wish to check out the "plugins" module currently in CVS. It's
very stable (we're very close to a new release of Digester). If,
however, your child objects only need a couple of attributes, as per
your example, then using the "plugins" facility is probably "overkill".



To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message