commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Simon Kitching <>
Subject Re: Digester mixing simple and complex properties
Date Thu, 14 Apr 2005 23:33:46 GMT
On Thu, 2005-04-14 at 13:14 -0500, wrote:
> Hi all,
> I'm brand-spanking-new to the Digester.  I'd like to use nested
> properties because some are quite long and cumbersome to specify as xml
> attributes.  I'd also like to use complex properties.  I can't figure
> out the rules, however.  Suppose I have this:
> <foo>
>   <name>foo name</name>
>   <bar>
>     <name>bar name</name>
>   </bar>
> </foo>
> If my rules look like this:
>         digester.addObjectCreate("foo", Foo.class);
>         digester.addSetNestedProperties("foo");
>         digester.addObjectCreate("foo/bar", Bar.class);
>         digester.addSetNext("foo/bar", "setBar");
>         digester.addSetNestedProperties("foo/bar");
> I get "java.lang.NoSuchMethodException: Bean has no property named bar."
> If I comment out the addSetNestedProperties("foo") it's ok (foo, bar,
> and bar name get populated) except that foo's nested props are ignored.
> I've also tried addSetNestedProperties("foo", "bar", null) to no avail.
> Is it possible to mix properties like this?  If so, how?

SetNestedPropertiesRule was really meant to be used with "leaf" objects,
ie ones that don't contain references to other objects, just to
primitive values such as strings/ints etc. The problem is that I can see
no way for SetNestedPropertiesRule to *know* whether <bar> is meant to
contain a literal value or a nested object.

However it should be possible to achieve what you want. You were on the
right track with 
  addSetNestedProperties("foo", "bar", null)
but unfortunately there appears to be a bug that doesn't recognise null
as "ignore" in this form.

Using the slightly longer form:
	new String[] {"bar"}, 
	new String[] {})
should ensure SetNestedPropertiesRule ignores the "bar" property (at
least it looks that way from my reading of the code).

I hope this helps.



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

View raw message