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:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>
