commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Simon Kitching <>
Subject Re: [Digester] - Read only methods
Date Thu, 29 May 2003 23:25:53 GMT
Hi Sloan,

>From a quick look at the digester code, I see that SetPropertiesRule
uses BeanUtils.populate(targetObject, valuesMap). Following this down, I
see that eventually java.beans.Introspector is called to get info about
the target class.

For my own interest, I looked into the JavaBeans spec, and it is quite
clear that this is the expected behavior (see Section 8.3.1). Because it
found a getFoo method returning type Y, but no setFoo(Y newFoo) method,
property Foo is regarded as readonly.

So I guess that what you are seeing is what is actually expected:
java.beans.Introspector is saying that "className" is a read-only

I hadn't realized that digester's use of BeanUtils would force such a
strict compliance with the JavaBeans rules onto users of the Digester!

What you could do is write an explicit CallMethod rule for the className

    "setClassName", 1);
    "struts-config/action-mappings/action", 0, "className");

The CallMethodRule uses MethodUtils.invokeMethod, which should find the
setClassName method without any problems.

Maybe it is also possible to write a BeanInfo class for your target
class to force className to be recognised as a bean property?

Or you could define getActionMappingClass to return a string, and have
getActionMappingClassAsClass to return the Class representation...

Or you could define a ConvertUtils converter which can convert string
--> class, then define setActionMappingClass(Class) instead of
setActionMappingClass(String). I'm sure that BeanUtils.setProperty uses
ConvertUtils internally...



View raw message