You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Lorrin Nelson <lh...@the-fam.net> on 2003/11/19 23:43:39 UTC
Re: [Digester DynaBeans] How to combine ?
Kai wrote:
>Erik Price schrieb:
>>
>>
>> Kai wrote:
>>
>>> is it possible (and if, how) using Digester to parse my xml file and
>>> creating dynabeans out of the parsed properties ?
>>
>>
>> Do you mean to generate the code to make a dynabean class? I suppose
>> you would have to write a class such as DynaBeanGenerator which has
>> methods that can be called by a Digester instance as it parses the
>
>Erik,
>thanks for your reply, but i think i did not point out my problem
>clearly enough:
>
>i have a class which instantiates Digester and parses / maps my xml >file:
>..
>
> Digester digester = new Digester();
>
> digester.push(this);
> digester.setValidating(true);
>
>
> digester.addObjectCreate("fields/element", ElementBean.class );
> digester.addSetProperties("fields/element");
>
>
> ...
>
>ElementBean is a Bean whith fixed properties. If properties in my xml
>file change, i also have to change ElementBean.
>My idea is to generate a DynaBean on the fly by setting the parsed
>properties as bean properties.
>
>In the package description of beanutils i found the following code:
>
> DynaProperty[] props = new DynaProperty[]{
> new DynaProperty("address", java.util.Map.class),
> new DynaProperty("subordinate", mypackage.Employee[].class),
> new DynaProperty("firstName", String.class),
> new DynaProperty("lastName", String.class)
> };
> BasicDynaClass dynaClass = new BasicDynaClass("employee", null,
props);
>DynaBean employee = dynaClass.newInstance();
>employee.set("address", new HashMap());
>..
>
>My understanding is that i can dynamically create properties by filling
>the DynaPropery[] array with DynaProperties and then instantiating the
>bean with it, like above.
>
>i am searching for a way to parse my xml file with digester and create
>these dynabean-properties with DynaProperties. Then, after having set up
>my dynabean i want it to be filled with the property values.
>I want the whole process to be done by Digester.
>
>
Kai, did you ever find a solution to this? Seems like it would be a
common problem to me. Adding a new property shouldn't involve modifying
so many different places in the code. (At least not for a small-scale
project).
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org