commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From robert burrell donkin <robertburrelldon...@blueyonder.co.uk>
Subject Re: [Digester] HashMap on top of stack
Date Tue, 10 Feb 2004 21:48:17 GMT
hi Christian

i think that there are two general approach to solving this with  
digester.

the first is to create a custom Rule implementation. this should be  
very easy in this case (just put the code you've already got into begin  
and then get the ordering right).

the second is to use a adapted version of CallMethodRule which calls a  
method on the root object (rather than the top). this should be easy to  
do and probably should already by in digester. (anyone fancy  
volunteering to develop this one for the ASF?)

- robert

On 10 Feb 2004, at 13:55, Christian Hauser wrote:

> Hi list
>
> I'd like to use Digester to parse an XML file. The root element  
> ('definitions') should correspond to a HashMap. This HashMap should  
> contain key/value pairs, whereas the value is a bean of type  
> DefinitionBean and the key is stored within the DefinitionKey.
>
> Here what I have so far:
>
>   Digester d = new Digester();
>   d.addObjectCreate("definitions", HashMap.class);
>   d.addObjectCreate("definitions/definition", DefinitionBean.class);
>   d.addBeanPropertySetter("definitions/definition/key", "key");
>   d.addObjectCreate("definitions/definition/properties/property",  
> DefinitionProperty.class);
> d.addBeanPropertySetter("definitions/definition/properties/property/ 
> xyz", "xyz");
>
>   d.addSetNext("definitions/definition/properties/property",  
> "addProperty");
>   // And this stuff here isn't working of course,
>   // but shows maybe what I'd like to do.
>   DefinitionBean bean = (DefinitionBean) d.pop();
>   HashMap hashMap = (HashMap) d.pop();
>   hashMap.put(bean.getKey(), bean);
>   d.push(hashMap);
>   d.push(bean);
>
>   HashMap map = (HashMap) d.parse(getTestXmlReader());
>
>
> When the definitions/definition tag ends I'd like to do something like
> hashMap.put(bean.getKey(), bean)
> whereas bean is of type DefinitionBean. The DefinitionBean is on top  
> of the stack and below the HashMap. Then of course the DefinitionBean  
> should be removed from stack for the next to come.
>
> I don't see a way to do that and would be very happy for every hint on  
> that.
>
> Christian
>
>
> ---------------------------------------------------------------------
> 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


Mime
View raw message