I didn't know about this cache mecanism and "multiple capital letters"
constraints.

For use in my JSP Tag to set parent tag Attribute (known value type:
String), do you think

PropertyUtils.setSimpleProperty(parentTag, arg, bodyContent)

is a good replacement from the reflection code ? So it will re-use
PropertyUtil cache and introspection mecanism.

> >
> >     Nicolas>        String setterName = "set"
> >     Nicolas>           + arg.substring(0,1).toUpperCase()
> >     Nicolas>           + arg.substring(1);
> >     Nicolas>        try {
> >     Nicolas>           System.out.println("setterName "+setterName);
> >     Nicolas>           Method setter = parentTag.getClass().getMethod(
> >     Nicolas>              setterName, new Class[] { String.class } );
> >
> >     Nicolas>           setter.invoke(parentTag,
> >     Nicolas>              new Object[] {getBodyContent().getString()} );
> >
> > I believe the functionality in this block is basically what
> > "BeanUtils.populate()" does, although with a little more overhead.
> >
>
> BeanUtils and PropertyUtils actually do somewhat more than this:
>
> * Property setter names do *not* have to start with "set" -- bean
>   developers can supply an additional BeanInfo class to define the
>   get and set method names.  BeanUtils uses the standard introspection
>   capabilities to do this lookup.
>
> * There are some special case rules for property names that start with
>   multiple capital letters that the introspection code deals with.
>
> * Because the introspection is the expensive part, the results are cached.
>   Therefore, BeanUtils will execute repeated property sets on the same
>   bean class much faster than the above code, which does a
>   getMethod() lookup every single time.
>
> * The BeanUtils version of the property setters (including the ones
>   called in populate()) do automatic type conversion for you, while
>   the PropertyUtils version of the property setters assumes you already
>   have the right data type.
>
> * The library methods know how to deal with indexed and mapped setters
>   as well as scalar properties.
>
> So, the above code (if included in the tag) would most likely be replaced
> by a call to PropertyUtils.getProperty() to take advantage of what the
> library can do.
>
> Craig
>
>
> --
> To unsubscribe, e-mail:
<mailto:[EMAIL PROTECTED]>
> For additional commands, e-mail:
<mailto:[EMAIL PROTECTED]>


--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to