Return-Path: Mailing-List: contact commons-user-help@jakarta.apache.org; run by ezmlm Delivered-To: mailing list commons-user@jakarta.apache.org Received: (qmail 53787 invoked from network); 6 Feb 2003 16:40:26 -0000 Received: from icarus.apache.org (208.185.179.13) by daedalus.apache.org with SMTP; 6 Feb 2003 16:40:26 -0000 Received: (qmail 21957 invoked by uid 1059); 6 Feb 2003 16:40:25 -0000 Received: from localhost (sendmail-bs@127.0.0.1) by localhost with SMTP; 6 Feb 2003 16:40:25 -0000 Date: Thu, 6 Feb 2003 08:40:25 -0800 (PST) From: "Craig R. McClanahan" To: Jakarta Commons Users List Subject: Re: Digester Problem related to Bean Classname In-Reply-To: <2D5BBBE40DAF3F468DD94EFA87284C8402670C2F@sdestoex1.sto.de.web-int.net> Message-ID: <20030206083227.A14133@icarus.apache.org> References: <2D5BBBE40DAF3F468DD94EFA87284C8402670C2F@sdestoex1.sto.de.web-int.net> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Spam-Rating: localhost 1.6.2 0/1000/N X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N On Thu, 6 Feb 2003, Maher Martin wrote: > Date: Thu, 6 Feb 2003 16:20:58 +0100 > From: Maher Martin > Reply-To: Jakarta Commons Users List > To: "'commons-user@jakarta.apache.org'" > Subject: Digester Problem related to Bean Classname > > Hi, > > I've encountered a strange problem with Digester which is related to the > name of the java bean class. If I name the Java class "x.y.Component" then > the fails to call the setter methods for the bean > class. However if I rename the class to "x.y.Component2" all setters are > invoked by Digester when parsing the XML. > > Can anybody explain what's going on here? I've included examples below. > This is going to take a few paragraphs, but here goes ... Digester (and beanutils, for that matter) use Java's introspection capabilities (java.beans.Introspector) to find the available methods and properties of bean classes. Normally, properties are identified by the naming pattern used on the methods (getFoo() and setFoo()), but you can also override this if you provide a BeanInfo class associated with your bean class (see the Introspector Javadocs and the JavaBeans Specification for more info). Now, there are two ways to associate a BeanInfo class with your bean: * Put it in the same package as your bean class, with the same classname + BeanInfo on the end (for a bean MyBean, the corresponding class would be MyBeanBeanInfo). * Tell the introspector to use a particular "search path" (set of package names) to search in for BeanInfo classes. Unfortunately, the default search path in the JDK includes a directory that contains a class named ComponentBeanInfo -- which tells the introspector that any class named "Component" will use this BeanInfo class to identify its properties, rather than looking at the methods of your class. Thus, *your* properties are not recognized. There's two workarounds: * Name your class anything other than "Component". (This seems to be the only BeanInfo class available in the default JDK list) * Call Introspector.setBeanInfoSearchPath() to set a different set of search directories, before using Digester. > Best Regards > > Martin Maher > Craig McClanahan > ------ Component Class -------- > > package x.y > > public class Component { > > private int _number; > private String _type; > > public Component() { > } > > public void setNumber(int number) { > _number = number; > } > > public void setType(String type) { > _type = type; > } > > public int getNumber() { > return _number; > } > > public String getType() { > return _type; > } > > public String toString() { > String newline = System.getProperty("line.separator"); > StringBuffer sBuf = new StringBuffer(); > > sBuf.append("Number:").append(_number).append(newline); > sBuf.append("Type:").append(_type).append(newline); > > return sBuf.toString(); > } > > } > > ------INPUT XML FILE-------- > > > > > > > ------ XML RULES -------- > > > > > > > > > > > > -------------- > > --------------------------------------------------------------------- > To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org > For additional commands, e-mail: commons-user-help@jakarta.apache.org > >