commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
Subject Re: [Digester] Method call order.
Date Fri, 03 Jun 2005 05:17:14 GMT

My mistake. You are right that <set-next-rule> *fixed* it, I mistakenly
mixed it up with another situation. This situation is far more complicated
and I hope I can explain it clearly here...

The XML I'm trying to parse:
      <attributes1 attr="common_attributes1"/>
      <attributes2 attr2="common_attributes2"/>
            <attributes attr="subclass1_attributes"/>
            <attributes attr="subclass2_attributes"/>

In this scenario, I'm trying to generate an appropriate object depending on
whether the tag <Type1> or <Type2> appears but both must have common
attributes "common_attributes1" & "common_attributes2" set into them. Since
this is my first time using Digester, I'm unaware of a way to write a
factory at <Common> to peek deeper to get the appropriate Type class to
load. So I introduced a "CommonLoader" intermediate class and wrote the
rules as follows...

      <pattern value="Common">
            <object-create-rule classname="CommonLoader"/>
            <call-method-rule methodname="setCommonAttributes1"
paramcount="1" paramtypes="java.lang.Boolean"/>
            <call-param-rule pattern="attributes1" attrname="attr1"
            <call-method-rule methodname="setCommonAttributes2"
paramcount="1" />
            <call-param-rule pattern="attributes2" attrname="attr2"
            <pattern value="Type1">
                  <object-create-rule classname="Type1"/>
                  <set-next-rule methodname="setType1"/>
                  <call-method-rule methodname="setType1Attribute"
paramcount="1" paramtypes="java.lang.Boolean"/>
                  <call-param-rule pattern="attributes" attrname="attr"
            <pattern value="Type2">
                  <object-create-rule classname="Type2"/>
                  <set-next-rule methodname="setType2"/>
                  <call-method-rule methodname="setType1Attribute"
paramcount="1" paramtypes="java.lang.Boolean"/>
                  <call-param-rule pattern="attributes" attrname="attr"

CommonLoader will have the method setType1() and setType2() and these
methods accepts the object created (either Type1 or Type2) and then sets
the common attributes obtained from within the <Common> tag to these Type
objects. I require that the method setType1() and setType2() be called last
to ensure all the common attributes are loaded into CommonLoader before it
proceeds to set them into the appropriate Type object. However the order of
execution I got is as follows:

1.    setCommonAttributes2.
2.    setType1.
3.    setCommonAttributes1.

Because setType1 as seen above is called before setCommonAttributes1,
common_attribute1 never gets set into the object Type1.

I've got a few workarounds in mind that would work, but before I proceed, I
need to understand as to why setCommonAttributes2() gets called based on
the proper order while setCommonAttributes1() gets called last? Why is the
order not as follows?

1.    setType1
2.    setCommonAttributes2
3.    setCommonAttributes1

However if I were to remove "paramtypes=java.lang.Boolean" and pass it in
as a String then the order will be as follows:

1.    setCommonAttributes1
2.    setCommonAttributes2
3.    setType1

I hope my explanation is clear and the experts out there is able to help.


P.S : I've got no control over the XML I'm receiving to modify the source
XML file is out of the question unfortunately.

                      Simon Kitching                                                     
                      <skitching@apach         To:      Jakarta Commons Users List <>
            >                   cc:                                    
                                               Subject: Re: [Digester] Method call order.
                      03/06/2005 11:46                                                   
                      Please respond                                                     
                      to "Jakarta                                                        
                      Commons Users                                                      

On Fri, 2005-06-03 at 10:38 +0800, wrote:
> Greetings,
> Decoder Rule XML:
> ...
> <pattern value="Party">
>   <object-create-rule
> classname=""/>
>   <call-method-rule methodname="setApplicationType" paramcount="1"
> paramtypes="" />
>   <call-param-rule attrname="ApplicationType" paramnumber="0" />
>   <set-next-rule methodname="addParty" />
> </pattern>
> ...
> Apparently the decoder always calls 'addParty' method BEFORE calling
> 'setApplicationType' resulting in an incomplete object being added. I've
> even tried moving <set-next-rule> to the top (based on the
> of this FAQ '' under
> 'How do I get CallMethodRule to fire before SetNextRule?') and it still
> gets called first. Anyone with experience on this please share your

Moving the set-next-rule to before the call-method-rule *will* fix this
problem. I can't think of any reason why it wouldn't work for you.

But if you still have problems, I recommend enabling digester's logging
as described in the same FAQ and inspecting the output.



To unsubscribe, e-mail:
For additional commands, e-mail:

Unencrypted electronic mail is not secure and may not be authentic.
If you have any doubts as to the contents please telephone to confirm.

This electronic transmission including any attachments is intended only
for those to whom it is addressed. It may contain copyright material or
information that is confidential, privileged or exempt from disclosure by law.
Any claim to privilege is not waived or lost by reason of mistaken transmission
of this information. If you are not the intended recipient you must not
distribute or copy this transmission and should please notify the sender.
Your costs for doing this will be reimbursed by the sender.

We do not accept liability in connection with computer virus, data corruption,
delay, interruption, unauthorised access or unauthorised amendment.

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message