You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ru...@us.ibm.com on 2000/02/14 20:01:40 UTC

Re: [Catalina] Using XML Parsing Package in "org.apache.tomcat .util.xml"


Costin wrote:
> > I also have a pet peeve against people looking for setters by explicit
> > names instead of using Introspectors...
>
> There is a reason for that :-)
>
> It's _VERY_ important to be able to separate the document from the
> program.

I must not have been clear.

Bad:

   String setter= "set" +capitalize(name);
   Method methods[]=o.getClass().getMethods();
   Method setPropertyMethod=null;
   for( int i=0; i< methods.length; i++ ) {
       if( setter.equals( methods[i].getName() ) )
           setPropertyMethod=methods[i];

Good:

   BeanInfo beanInfo = Introspector.getBeanInfo(o.getClass());
   PropertyDescriptor props[] = beanInfo.getPropertyDescriptors();
   Method setPropertyMethod=null;
   for (int i=0; i<props.length; i++) {
       if (props[i].getName().equals(name)) {
           setPropertyMethod=props[i].getWriteMethod();

In other words, the document remains separated from the program.

- Sam Ruby



Re: [Catalina] Using XML Parsing Package in "org.apache.tomcat .util.xml"

Posted by co...@eng.sun.com.
>    BeanInfo beanInfo = Introspector.getBeanInfo(o.getClass());
>    PropertyDescriptor props[] = beanInfo.getPropertyDescriptors();
>    Method setPropertyMethod=null;
>    for (int i=0; i<props.length; i++) {
>        if (props[i].getName().equals(name)) {
>            setPropertyMethod=props[i].getWriteMethod();

You are right about that. The only problem is that the second style
doesn't work on kaffe ( probably not a big problem for us,
Solaris/Linux.i386/AIX/Windows  users).

And we have to use Class.getMethod for non-property setters. The Bean API
might be a bit heavy for our modest use of introspection, but I agree it
is the "right" way.

Costin