thanks for the heads up simon. it is very much along the lines that i was thinking. i was thinking about using string arrays (for - perhaps - not very good reasons). i like the xml rule naming (and to be honest i wouldn't have remembered to do this myself).
i've searched the archives and i don't think that there was any particular follow up to the post - whether positive or negative. (you need to remember that the commons components have relatively small developer teams and so it's easy to get ignored.) the class example is a clincher for me but i'll go back and re-read the original threads to make sure that i haven't missed anything. - robert On Tuesday, July 9, 2002, at 10:55 PM, Simon Kitching wrote: > Hi Robert/Edgar. > > I sent in a patch a while ago which I think would solve your problem. > [It was a while ago, so my memory might be misleading me]. > > There was no response; I meant to follow up but have been kind of busy > later. > See > http://marc.theaimsgroup.com/?l=jakarta-commons-dev&m=102150414316796&w= > 2 > > I'm not claiming that the patch *should* have been added; there may > well have been reasons not to.. > > As mentioned in the referenced email, there are a couple of solutions > that don't involve modifying digester: > (a) write CallMethodRules to map attributes to setter methods > instead of using SetProperties. > (b) writing an XXXBeanInfo bean properties class which specifies > attribute-name -> setter-method mappings (see java beans > documentation). > > Regards, > > Simon > >> -----Original Message----- >> From: robert burrell donkin [mailto:[EMAIL PROTECTED]] >> Sent: Wednesday, July 10, 2002 8:47 AM >> To: Jakarta Commons Users List >> Subject: Re: Digester: How to make a rule that maps an XML >> attribute to a Java Beans property with a different name? >> >> >> hi edgar >> >> i think that this ability might well be missing from digester at the >> moment. >> >> there are various ways in which this could be added. i'll >> have a think >> about which seems the best. (i don't know if anyone out there has any >> preferences.) >> >> - robert >> >> On Tuesday, July 9, 2002, at 05:15 PM, Edgar Vonk wrote: >> >>> Hi all, >>> >>> I have an XML message of which the toplevel element contains amongst >>> others >>> an attribute named 'class'. >>> I cannot map this attribute to a JavaBeans property named >> 'class' since >>> the >>> getClass() method is final in java.lang.Object. >>> >>> Therefore I have created a different JavaBeans property named >>> 'content' to which I want to map this XML attribute. The >> same JavaBean >>> I want to use for the other attributes of this XML element. >>> >>> My question is how do I do this (neatly)? >>> >>> I have looked into the Digester documentation but could not find a >>> way. In the end I took the source code of both the latest >>> commons-digester (version 1.2) and the commons-beanutils >> (version 1.3) >>> and created my own 'SetPropertiesRule' and 'BeanUtils' class. >>> >>> In the former I adapted the 'begin' method to include >> special handling >>> for my 'class' attribute. The latter I only modified >> slightly: I made >>> the 'setProperty' method public. >>> Why is it private anyway? It seems to me like a method >> which could be of >>> use >>> outside of the class. >>> >>> My version of the SetPropertiesRule class now maps all >> attributes of >>> my 'request' element to their corresponding JavaBeans >> property except >>> for the 'class' attribute. It maps this one to the >> 'content' property. >>> >>> However, I'd much rather just use the digester API as it is >> (well, I >>> am still using the API I guess..) so I wondered if there >> was a neater >>> way to do this? >>> Somehow this feels like a problem other people may have run >> into in the >>> past? >>> >>> >>> Example XML message: >>> >>> <?xml version="1.0" encoding="ISO-8859-1"?> >>> <!DOCTYPE request SYSTEM "http://localhost:8080/zrt_1_0.dtd"> >>> <request class="screensaver" command="GetCategories" >>> msisdn="31612345678" >>>> >>> </request> >>> >>> Example part of corresponding JavaBean: >>> >>> public class Request { >>> public String getCommand() {..} >>> public void setCommand(String command) {..} >>> public String getContent() {..} >>> public void setContent(String content) {..} >>> } >>> >>> Current solution: part of my adapted SetPropertiesRule#begin method: >>> >>> // special handling for 'class' attribute >>> // this attribute corresponds to the 'content' property >>> // in the Java bean >>> String name = "class"; >>> String value = classValue; >>> if (digester.getLogger().isDebugEnabled()) { >>> >> digester.getLogger().debug("[SetPropertiesRule]{" + >>> digester.getMatch() + >>> "} Setting property '" + name + "' to '" + >>> value + "'"); >>> } >>> RequestBeanUtils.setProperty(top, "content", value); >>> >>> >>> >>> regards, >>> >>> Edgar >>> >>> _______________________ >>> Edgar Vonk >>> Software Engineering >>> Info.nl >>> Sint Antoniesbreestraat 16 >>> 1011 HB Amsterdam >>> >>> [EMAIL PROTECTED] >>> tel: 020 - 5 30 91 00 >>> fax: 020 - 5 30 91 01 >>> mobile: 06 - 417 23 151 >>> http://www.info.nl/ >>> >>> -- >>> To unsubscribe, e-mail: >> <mailto:commons-user-> [EMAIL PROTECTED] >>> org> >>> For >> additional >> commands, e-mail: >>> <mailto:[EMAIL PROTECTED]. >>> org> >>> >> >> >> -- >> To unsubscribe, e-mail: >> <mailto:commons-user-> [EMAIL PROTECTED]> >> For >> additional commands, >> e-mail: <mailto:[EMAIL PROTECTED]> >> >> > > > -- > To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]. > org> > For additional commands, e-mail: <mailto:[EMAIL PROTECTED]. > org> > -- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>
