You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Jo...@wellsfargo.com on 2005/04/14 20:14:53 UTC

Digester mixing simple and complex properties

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?
 
thanks
 
 
 
John Gregg
Application Systems Engineer
Wells Fargo Private Client Services Technology
 

Re: Digester mixing simple and complex properties

Posted by Simon Kitching <sk...@apache.org>.
On Thu, 2005-04-14 at 13:14 -0500, John.E.Gregg@wellsfargo.com 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:
  addSetNestedProperties(
	"foo", 
	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.

Regards,

Simon



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