The "Set Next" rule is optimized for the case of attaching a child to
a parent via a standard JavaBean property setter, so it doesn't know
anything about DynaBeans.  However, you might want to take a look at
the "Call Method" rule instead ... you can set up a call to a method
that takes parameters, so you should be able to call the standard
set() method on the DynaBean directly, passing the property name key
and the appropriate value.

Craig



On Thu, 25 Nov 2004 11:45:41 -0500, Jon Brule <[EMAIL PROTECTED]> wrote:
> Greetings!
> 
> I am using Digester to consume an XML stream that I intend to be a hierarchy
> of Commons DynaBeans. For the sake of flexibility, I am using the XML Rules
> mechanism in conjunction with object factories. I can create the whole
> hierarchy of beans without a problem. I can even register the child beans
> with their parent. I, however, had to make each parent bean extend
> BasicDynaBean in order to add special "set" methods (i.e. setChild1(Child1
> child)) to allow the set-next-rule to properly function. Each of these
> special methods simple calls the DynaBean.set() method with the appropriate
> property.
> 
> I'd love to eliminate these special parent DynaBeans and just use
> BaseDynaBean.
> 
> Is there anyway to use set-next-rule / SetNextRule with DynaBeans directly
> (i.e. pass more than one argument, namely the property name as well)? If
> not, is there another way with the common rules that I can eliminate these
> custom DynaBeans? Or must I write my own rule extension to SetNextRule?
> 
> At this point, my thought is that I must extend the SetNextRule to achieve
> my desired functionality. Does this mean that I need to extend another class
> to handle the set-next-rule XML rule?
> 
> I have included abbreviate versions of the core files in question. Please
> let me know if more code / information is needed...
> 
> Thanks. This component is fantastic. It has REALLY made my life easier!
> 
> Jon Brule
> 
> -----
> 
> Supporting files (stripped down for brevity):
> 
> weather.xml:
>   <digester-rules>
>     <pattern value="weather">
>       <factory-create-rule
> classname="jrb.service.schedule.sensor.weather.WeatherBeanFactory"/>
>       <bean-property-setter-rule pattern="cc/lsup"
> propertyname="lastUpdate"/>
>       <bean-property-setter-rule pattern="cc/tmp"
> propertyname="temperature"/>
>       <pattern value="head">
>         <factory-create-rule
> classname="jrb.service.schedule.sensor.weather.UnitsBeanFactory"/>
>         <bean-property-setter-rule pattern="ud" propertyname="distance"/>
>         <set-next-rule methodname="setUnits"/>
>       </pattern>
>   <digester-rules>
> 
> WeatherBean:
>     public class WeatherBean extends BasicDynaBean {
>         public WeatherBean(DynaClass dynaClass) {
>                 super(dynaClass);
>         }
>         public void setUnits(DynaBean units) {
>             this.set(WeatherBeanFactory.PROP_UNITS, units);
>         }
>     }
> 
> WeatherBeanfactory:
>     public class WeatherBeanFactory extends AbstractObjectCreationFactory {
>         static final String BEAN_WEATHER = "Weather";
>         static final String PROP_LAST_UPDATE = "lastUpdate";
>         static final String PROP_TEMPERATURE = "temperature";
>         static final String PROP_UNITS = "units";
> 
>         public Object createObject(Attributes attributes) throws Exception
> {
>             DynaClass beanClass = new BasicDynaClass(
>                 BEAN_WEATHER,
>                 WeatherBean.class,
>                 new DynaProperty[] {
>                     new DynaProperty(PROP_LAST_UPDATE, Date.class),
>                     new DynaProperty(PROP_TEMPERATURE, Integer.class),
>                     new DynaProperty(PROP_UNITS, DynaBean.class)
>                 }
>             );
>             DynaBean dynabean = beanClass.newInstance();
>             return dynabean;
>         }
>     }
> 
> UnitsBeanFactory:
>     public class UnitsBeanFactory extends AbstractObjectCreationFactory {
>         private static final String BEAN_UNITS = "Units";
>         private static final String PROP_DISTANCE = "distance";
> 
>         public Object createObject(Attributes attributes) throws Exception {
>             DynaClass beanClass = new BasicDynaClass(
>                 BEAN_UNITS,
>                 null,
>                 new DynaProperty[] {
>                     new DynaProperty(PROP_DISTANCE, String.class)
>                 }
>             );
>             DynaBean dynabean = beanClass.newInstance();
>             return dynabean;
>         }
>     }
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to