You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Sloan Seaman <sl...@sgi.net> on 2003/05/28 21:27:56 UTC

[Digester] - Read only methods

Is there any way to get Digester to call methods that it thinks are read only?

I have a public void setActionMappingClass(String) that Digester does not call because the get is public Class getActionMappingClass() instead of a public String getActionMappingClass()....

Just seems odd that Digester would be so strict...

Thanks!

--
Sloan

________________________________________________________________________
This email has been scanned for all viruses by the MessageLabs Email
Security System. For more information on a proactive email security
service working around the clock, around the globe, visit
http://www.messagelabs.com
________________________________________________________________________

Re: [Digester] - Read only methods

Posted by "Craig R. McClanahan" <cr...@apache.org>.

On Wed, 28 May 2003, Sloan Seaman wrote:

> Date: Wed, 28 May 2003 15:27:56 -0400
> From: Sloan Seaman <sl...@sgi.net>
> Reply-To: Jakarta Commons Users List <co...@jakarta.apache.org>
> To: commons-user@jakarta.apache.org
> Subject: [Digester] - Read only methods
>
> Is there any way to get Digester to call methods that it thinks are read only?
>
> I have a public void setActionMappingClass(String) that Digester does
> not call because the get is public Class getActionMappingClass() instead
> of a public String getActionMappingClass()....
>
> Just seems odd that Digester would be so strict...
>

Digester isn't being strict -- your class is breaking the JavaBeans design
pattern requirements for recognizing properties.  This only matters when
you are trying to use rules like SetPropertyRule or SetPropertiesRule that
rely on a promise from you that your beans obey the rules.  Your class
does not conform, so you should not be surprised by this.

You can investigate using something like SetNextRule, where you can
explicitly define the name of the method to be called, and the argument
type it takes.  However, you'll save yourself lots of other work later if
you just make sure that your classes are proper JavaBeans instead.

> Thanks!
>
> --
> Sloan

Craig

Re: [Digester] - Read only methods

Posted by Simon Kitching <si...@ecnetwork.co.nz>.
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
property.

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
attribute:

  digester.addCallMethod(
    "struts-config/action-mappings/action", 
    "setClassName", 1);
  digester.addCallParam(
    "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...


Regards,

Simon



Re: [Digester] - Read only methods

Posted by robert burrell donkin <ro...@blueyonder.co.uk>.
this is a bit of a guess but are you using the latest versions of 
beanutils and digester? i seem to remember a beanutils bug sounding 
similar to this...

- robert

On Thursday, May 29, 2003, at 01:14 PM, Sloan Seaman wrote:

> It does not display an error message but if I turn on debugging it leaves 
> a
> "skipping read only method" in the logs.
>
> Here are the rules:
>
>         _digester.addFactoryCreate
>             ("struts-config/action-mappings/action",
>              new ActionMappingFactory());
>   _digester.addSetProperties
>             ("struts-config/action-mappings/action");
>         _digester.addSetNext
>             ("struts-config/action-mappings/action",
>              "addActionConfig",
>              "org.apache.struts.config.ActionConfig");
>
> (yes, I'm overriding part of Struts to provide my own ActionMappingFactory
> :))
>
> The XML in question:
>    <action path="/test"
>    className="com.symbol.mc.oms.core.struts.mcp.ActionMCPMapping"
>    type="com.symbol.mc.oms.core.struts.mcp.ActionMCP"
>>
>    <set-property property="ACTION_TYPE" value="JDO"/>
>    <set-property property="ACTION_PROCESSOR" value="blah"/>
>    <forward name="PAGE_ACCESS_DENIED" path="/index.jsp"/>
>    <forward name="PAGE_ACTION_FAILURE" path="/index.jsp"/>
>    <forward name="PAGE_ACTION_SUCCESS" path="/index.jsp"/>
>   </action>
>
> --
> Sloan
>
> ----- Original Message -----
> From: "Simon Kitching" <si...@ecnetwork.co.nz>
> To: "Jakarta Commons Users List" <co...@jakarta.apache.org>
> Sent: Wednesday, May 28, 2003 6:33 PM
> Subject: Re: [Digester] - Read only methods
>
>
>> On Thu, 2003-05-29 at 07:27, Sloan Seaman wrote:
>>> I have a public void setActionMappingClass(String)
>>> that Digester does not call because the get is
>>> public Class getActionMappingClass() instead of
>>> a public String getActionMappingClass()....
>>>
>>> Just seems odd that Digester would be so strict...
>>
>> While this means that your class does not comply with the Java Beans
>> specification, I don't see why Digester would not invoke the method.
>>
>> Does Digester display an error message, or just appear to ignore the
>> rule?
>>
>> Can you post the code you use to set up the related rules, and a
>> fragment of the input xml?
>>
>> Regards,
>>
>> Simon
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail: commons-user-help@jakarta.apache.org
>>
>>
>
>
> ________________________________________________________________________
> This email has been scanned for all viruses by the MessageLabs Email
> Security System. For more information on a proactive email security
> service working around the clock, around the globe, visit
> http://www.messagelabs.com
> ________________________________________________________________________
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
>


Re: [Digester] - Read only methods

Posted by Sloan Seaman <sl...@sgi.net>.
It does not display an error message but if I turn on debugging it leaves a
"skipping read only method" in the logs.

Here are the rules:

        _digester.addFactoryCreate
            ("struts-config/action-mappings/action",
             new ActionMappingFactory());
  _digester.addSetProperties
            ("struts-config/action-mappings/action");
        _digester.addSetNext
            ("struts-config/action-mappings/action",
             "addActionConfig",
             "org.apache.struts.config.ActionConfig");

(yes, I'm overriding part of Struts to provide my own ActionMappingFactory
:))

The XML in question:
   <action path="/test"
   className="com.symbol.mc.oms.core.struts.mcp.ActionMCPMapping"
   type="com.symbol.mc.oms.core.struts.mcp.ActionMCP"
   >
   <set-property property="ACTION_TYPE" value="JDO"/>
   <set-property property="ACTION_PROCESSOR" value="blah"/>
   <forward name="PAGE_ACCESS_DENIED" path="/index.jsp"/>
   <forward name="PAGE_ACTION_FAILURE" path="/index.jsp"/>
   <forward name="PAGE_ACTION_SUCCESS" path="/index.jsp"/>
  </action>

--
Sloan

----- Original Message ----- 
From: "Simon Kitching" <si...@ecnetwork.co.nz>
To: "Jakarta Commons Users List" <co...@jakarta.apache.org>
Sent: Wednesday, May 28, 2003 6:33 PM
Subject: Re: [Digester] - Read only methods


> On Thu, 2003-05-29 at 07:27, Sloan Seaman wrote:
> > I have a public void setActionMappingClass(String)
> > that Digester does not call because the get is
> > public Class getActionMappingClass() instead of
> > a public String getActionMappingClass()....
> >
> > Just seems odd that Digester would be so strict...
>
> While this means that your class does not comply with the Java Beans
> specification, I don't see why Digester would not invoke the method.
>
> Does Digester display an error message, or just appear to ignore the
> rule?
>
> Can you post the code you use to set up the related rules, and a
> fragment of the input xml?
>
> Regards,
>
> Simon
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
>
>


________________________________________________________________________
This email has been scanned for all viruses by the MessageLabs Email
Security System. For more information on a proactive email security
service working around the clock, around the globe, visit
http://www.messagelabs.com
________________________________________________________________________

Re: [Digester] - Read only methods

Posted by Simon Kitching <si...@ecnetwork.co.nz>.
On Thu, 2003-05-29 at 07:27, Sloan Seaman wrote:
> I have a public void setActionMappingClass(String) 
> that Digester does not call because the get is 
> public Class getActionMappingClass() instead of 
> a public String getActionMappingClass()....
> 
> Just seems odd that Digester would be so strict...

While this means that your class does not comply with the Java Beans
specification, I don't see why Digester would not invoke the method.

Does Digester display an error message, or just appear to ignore the
rule?

Can you post the code you use to set up the related rules, and a
fragment of the input xml?

Regards,

Simon