You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Wendy Smoak <ja...@wendysmoak.com> on 2005/01/28 19:58:35 UTC
[digester] How to set a LazyDynaBean map-of-objects property?
I'm trying to set a mapped property of a LazyDynaBean. This is easy enough
if the Map is String/String, but I'm having trouble populating a Map where
the values are objects.
Example XML:
<download><person><degree key="1123*12332" type="BS" major="Computer
Science" /></person></download>
Assuming a LazyDynaBean got created earlier
digester.addObjectCreate("download", LazyDynaBean.class);
when I hit the <degree> tag, I create a DegreeViewImpl object and set its
properties from the tag attributes...
digester.addObjectCreate("download/person/degree",
DegreeViewImpl.class);
digester.addSetProperties("download/person/degree");
Now I need to pop the top object (the Degree) and call set( "degrees", key,
degree) on the LazyDynaBean. I need something like SetNextRule, but
SetNextRule only allows a single parameter to be passed to the method it is
told to call.
At this point I believe I have a DegreeViewImpl object on the top of the
stack, and a LazyDynaBean just below it. (Though the log messages I'm
getting disagree.) It looks like CallMethodRule can be told to call its
method on an object further down the stack. I tried this:
Rule rule = new CallMethodRule( -1, "set", 3); //also tried with
1 instead of -1
digester.addRule("/download/person/degree", rule);
digester.addObjectParam("download/person/degree", 0, "degrees");
digester.addCallParam("download/person/degree", 1, "key");
digester.addCallParam("download/person/degree", 2, true);
But the CallMethodRule never happens, the logs show the ObjectParamRule
throwing a NPE, and complaining that the stack is empty.
Digester - New match='download/person/degree'
... skip setting all the properties of the DegreeImpl, which works ...
Digester - Fire begin() for ObjectParamRule[paramIndex=0,
attributeName=null, param=degrees]
Digester - Empty stack (returning null)
Digester - Begin event threw exception java.lang.NullPointerException
at
org.apache.commons.digester.ObjectParamRule.begin(ObjectParamRule.java:106)
(The entire log output with the code and example xml is posted here:
http://wiki.wendysmoak.com/cgi-bin/wiki.pl?DigesterLazyDynaBean )
Does anyone see what I'm doing wrong?
And what's the proper way to refer to the stack elements. If 0 is the top,
is the next one -1 or 1?
Thanks,
Wendy Smoak
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org
Re: [digester] How to set a LazyDynaBean map-of-objects property?
Posted by Kishore Senji <ks...@gmail.com>.
On Fri, 28 Jan 2005 18:20:55 -0700, Wendy Smoak <ja...@wendysmoak.com> wrote:
> From: "Kishore Senji" <ks...@gmail.com>
> >> digester.addRule("/download/person/degree", rule);
> >
> > shouldn't the pattern be "download/person/degree" without the "/" in
> > the beginning.
>
> Thank you! All that time wasted, for _one_ extra character...
>
> > Note 1 or -1 should both resolve in this case to the
> > LazyDynaBean object stored on the stack.
>
> Weird. Is there a convention to use either negative or positive numbers, or
> does it not matter? I suppose it depends how you draw your stack on paper,
> whether 'next' is up or down. :)
>
Top
+------------------------+
0 + DriverViewImpl + -2
+------------------------+
1 + LazyDynaBean + -1
+------------------------+
Bottom
0 means top of the stack. Positive number "n" resolves to "n+1th"
element in the stack (starting at the top (0) and counting down). -1
means bottom on the stack and Negative number "-n" resolves to the nth
starting from the bottom and counting up. Since the stack has only 2
objects in this case 1 and -1 resolve to the same object in the stack.
I don't know if there is any convention, but sticking to positive
numbers might be easier since we have the same convention in arrays
(starting from 0)
> --
> Wendy Smoak
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org
Re: [digester] How to set a LazyDynaBean map-of-objects property?
Posted by Wendy Smoak <ja...@wendysmoak.com>.
From: "Kishore Senji" <ks...@gmail.com>
>> digester.addRule("/download/person/degree", rule);
>
> shouldn't the pattern be "download/person/degree" without the "/" in
> the beginning.
Thank you! All that time wasted, for _one_ extra character...
> Note 1 or -1 should both resolve in this case to the
> LazyDynaBean object stored on the stack.
Weird. Is there a convention to use either negative or positive numbers, or
does it not matter? I suppose it depends how you draw your stack on paper,
whether 'next' is up or down. :)
--
Wendy Smoak
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org
Re: [digester] How to set a LazyDynaBean map-of-objects property?
Posted by Kishore Senji <ks...@gmail.com>.
On Fri, 28 Jan 2005 11:58:35 -0700, Wendy Smoak <ja...@wendysmoak.com> wrote:
> I'm trying to set a mapped property of a LazyDynaBean. This is easy enough
> if the Map is String/String, but I'm having trouble populating a Map where
> the values are objects.
>
> Example XML:
> <download><person><degree key="1123*12332" type="BS" major="Computer
> Science" /></person></download>
>
> Assuming a LazyDynaBean got created earlier
> digester.addObjectCreate("download", LazyDynaBean.class);
>
> when I hit the <degree> tag, I create a DegreeViewImpl object and set its
> properties from the tag attributes...
> digester.addObjectCreate("download/person/degree",
> DegreeViewImpl.class);
> digester.addSetProperties("download/person/degree");
>
> Now I need to pop the top object (the Degree) and call set( "degrees", key,
> degree) on the LazyDynaBean. I need something like SetNextRule, but
> SetNextRule only allows a single parameter to be passed to the method it is
> told to call.
>
> At this point I believe I have a DegreeViewImpl object on the top of the
> stack, and a LazyDynaBean just below it. (Though the log messages I'm
> getting disagree.) It looks like CallMethodRule can be told to call its
> method on an object further down the stack. I tried this:
>
> Rule rule = new CallMethodRule( -1, "set", 3); //also tried with
> 1 instead of -1
> digester.addRule("/download/person/degree", rule);
shouldn't the pattern be "download/person/degree" without the "/" in
the beginning. Note 1 or -1 should both resolve in this case to the
LazyDynaBean object stored on the stack. So, either one should work
fine after removing the "/" in the pattern for the above line
> digester.addObjectParam("download/person/degree", 0, "degrees");
> digester.addCallParam("download/person/degree", 1, "key");
> digester.addCallParam("download/person/degree", 2, true);
>
> But the CallMethodRule never happens, the logs show the ObjectParamRule
> throwing a NPE, and complaining that the stack is empty.
>
> Digester - New match='download/person/degree'
> ... skip setting all the properties of the DegreeImpl, which works ...
> Digester - Fire begin() for ObjectParamRule[paramIndex=0,
> attributeName=null, param=degrees]
> Digester - Empty stack (returning null)
> Digester - Begin event threw exception java.lang.NullPointerException
> at
> org.apache.commons.digester.ObjectParamRule.begin(ObjectParamRule.java:106)
>
> (The entire log output with the code and example xml is posted here:
> http://wiki.wendysmoak.com/cgi-bin/wiki.pl?DigesterLazyDynaBean )
>
> Does anyone see what I'm doing wrong?
>
> And what's the proper way to refer to the stack elements. If 0 is the top,
> is the next one -1 or 1?
>
> Thanks,
> Wendy Smoak
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org