commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Wendy Smoak" <j...@wendysmoak.com>
Subject [digester] How to set a LazyDynaBean map-of-objects property?
Date Fri, 28 Jan 2005 18:58:35 GMT
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


Mime
View raw message