On Thu, 25 Nov 2004 10:00:16 +1030, Lance Semmens <[EMAIL PROTECTED]> wrote: > I'm not familiar with DynaBeans. > Is there some form of DynaBeanPropertySetterRule out there?
No special case rule is needed -- BeanUtils and PropertyUtils (which Digester uses under the covers) are smart enough to know how to deal with them, so the standard rules work with either a JavaBean or a DynaBean. Craig > > > > -----Original Message----- > From: Carsten Kaiser [mailto:[EMAIL PROTECTED] > Sent: Tuesday, 23 November 2004 6:38 PM > To: Jakarta Commons Users List > Subject: RE: [digester] Setting arbitrary XML attributes > Importance: Low > > Wouldn't it be also possible just to let MyBean implement the DynaBean > interface or directly uses the BasicDynaBean itself? If so, BeanUtils > should properly populate your attributes! I guess, it is exactly, what you > are looking for... > > Regards, > CAK > > -----Urspr�ngliche Nachricht----- > Von: Lance Semmens [mailto:[EMAIL PROTECTED] > Gesendet: Di 23.11.2004 04:13 > An: 'Jakarta Commons Users List' > Cc: > Betreff: RE: [digester] Setting arbitrary XML attributes > Thanks Simon. > I was hoping that the reflective option existed rather than creating a > specialized rule. > I may look at writing the reflective option myself. > > Lance. > > -----Original Message----- > From: Simon Kitching [mailto:[EMAIL PROTECTED] > Sent: Tuesday, 23 November 2004 1:41 PM > To: Jakarta Commons Users List > Subject: Re: [digester] Setting arbitrary XML attributes > Importance: Low > > Hi Lance, > > On Tue, 2004-11-23 at 15:59, Lance Semmens wrote: > > I'm wanting to set all XML attributes on my object. > > At the time of XML digesting, I don't know the set of attribute names. > > If I use a SetPropertiesRule, my object will require a setX() method for > > every attribute. > > > > If I parse > > <mybean foo="ABC" bar="123" /> > > > > Using the following bean: > > public class MyBean { > > public Map attributes = new HashMap(); > > public void setAttribute(String name, String value); > > } > > > > I'd like the digester to do the following: > > MyBean myBean = new MyBean(); > > myBean.setAttribute("foo", "ABC"); > > myBean.setAttribute("bar", "123"); > > > > Is there a digester rule that will do this? > > There's no standard Rule class distributed with Digester that does this, > but implementing your own subclass of Rule to do this is very easy. > > Roughly: > > public class MyBeanAttributeSetterRule > extends org.apache.commons.digester.Rule > { > public void begin(String namespace, String name, Attributes attrs) > { > MyBean b = (MyBean) digester.peek(); > for each attribute in attrs > call setAttribute(name, value) > } > } > > Then of course: > digester.addRule(somePattern, new MyBeanAttributeSetterRule()); > ... > > Of course it would be possible to use reflection etc to avoid direct > coupling between the new Rule class and the MyBean class, but there's > probably not much point. > > Regards, > > Simon > > --------------------------------------------------------------------- > 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] > > --------------------------------------------------------------------- > 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] > > --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
