commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Kai <>
Subject Re: [Digester DynaBeans] How to combine ?
Date Tue, 01 Jul 2003 17:14:19 GMT
Erik Price schrieb:
> Kai wrote:
>> Hi all,
>> i am new to digester and i find the philosophy behind it very 
>> interesting. The following question turned out:
>> 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 XML, 
> perhaps writing out the code to a StringBuffer.  Then at the end of the 
> XML file the Digester can instruct the DynaBeanGenerator to write the 
> StringBuffer's contents to a file, or something.
> But note that there are some XDoclet tags that can let you go in the 
> other direction.  I'm not sure about Dynabeans.  But you can incorporate 
> the XDoclet tags into your Java code that automatically generates your 
> struts-config.xml file.
> 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.addObjectCreate("fields/element",  ElementBean.class  );


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.


View raw message