You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by "Gorostegui Martin (SFN)" <go...@telefonica.com.ar> on 2005/02/04 19:57:43 UTC

how to add an object to a map by using a XML config file?

Hi,
 
In the application i´m working on, we are currently setting the Digester
rules from a class and adding the resulting objects to a list and,
sometimes, to a hashmap. We do this by calling an "add" method from a
CallMethod rule. 
 
Now we are trying to change the implementation and set the Digester rules
from an xml config file. Adding the object to the list is not a problem as
we can achieve this by pushing the list to the stack for making it the root
item and then use the SetRoot rule for calling the list´s add method passing
the top object as parameter. But we can´t find a way for adding and object
to a hashmap, as we need to pass the top object and the key as parameters.
The SetRoot rule can´t be used here because it doesn´t accept other
parameter than the stack´s top object. 
I´ve found ways of doing this by using a supporting class for the cases in
which I need to use the hashmap, but my idea is to use only an xml config
file per case.
 
Basically what I need is a SetRoot rule accepting parameters like the
CallMethod rule.
 
Anybody knows a solution to this problem or if what I mentioned will be
considered for future releases? 
 
Thanks in advanced,
 
Martin G

Re: how to add an object to a map by using a XML config file?

Posted by Simon Kitching <sk...@apache.org>.
Hi Martin,

On Fri, 2005-02-04 at 15:57 -0300, Gorostegui Martin (SFN) wrote:
> Hi,
>  
> In the application i´m working on, we are currently setting the Digester
> rules from a class and adding the resulting objects to a list and,
> sometimes, to a hashmap. We do this by calling an "add" method from a
> CallMethod rule. 
>  
> Now we are trying to change the implementation and set the Digester rules
> from an xml config file. Adding the object to the list is not a problem as
> we can achieve this by pushing the list to the stack for making it the root
> item and then use the SetRoot rule for calling the list´s add method passing
> the top object as parameter. But we can´t find a way for adding and object
> to a hashmap, as we need to pass the top object and the key as parameters.
> The SetRoot rule can´t be used here because it doesn´t accept other
> parameter than the stack´s top object. 
> I´ve found ways of doing this by using a supporting class for the cases in
> which I need to use the hashmap, but my idea is to use only an xml config
> file per case.
>  
> Basically what I need is a SetRoot rule accepting parameters like the
> CallMethod rule.
>  
> Anybody knows a solution to this problem or if what I mentioned will be
> considered for future releases? 

Well, the CallMethodRule class has an optional "target stack offset"
that can be used to point to any object on the digester's object stack
rather than just the top object. Specifying "-1" will cause methods to
be invoked on the root object of the stack.

This functionality is currently accessable only when using the api (ie
not when using xmlrules). If you wish to use this from xmlrules, please
feel free to implement the missing bits in DigesterRuleParser (probably
about 3 lines) and submit a patch!

Regards,

Simon



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