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 Fri, 25 Jun 2004 01:13:22 GMT
On Fri, 2004-06-25 at 12:55, Bill Keese wrote:
> >How about this??
> >
> >public class ChildCreationFactory implements ObjectCreationFactory {
> >  public Object createObject(Attributes x) {
> >    ParentClass parent = (ParentClass) digester.peek();
> >    String childClassName = parent.getChildClassName();
> >
> >    // create instance of child class and return it
> >  }
> >}
> >  
> >
> Looks good to me. I think that's what the original poster wanted. He
> just needs to add in the parts using reflection to instantiate the child
> object and set the attributes on it. Although, I guess the reflection
> code is a bit tricky, especially if there are type conversions, such as
> converting a string value of an attribute into a number. (Basically,
> it's re-implementing whatever digester.addSetProperties() does.)

Well, once the FactoryCreateRule has invoked the ChildCreationFactory to
create an instance of the right type and pushed it onto the digester
object stack, things look just like it was created via a "normal"
ObjectCreateRule, so I don't see any reason why a normal
SetPropertiesRule couldn't then be used:

  digester.addFactoryCreate("parent/child", new ChildCreationFactory());

I don't believe the object creation factory needs to set the child
properties. Yes, the createObject method is *passed* the attributes, so
it *could* set them if it wanted to, but I don't think it is



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

View raw message