commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Lister, Tom (ANTS)" <>
Subject RE: [Digester] element names
Date Wed, 09 Jul 2003 12:11:03 GMT
I have got the behaviour I want by extending the CallMethodRule as per the
code below (basically setting the bodyText to the element name). Then
configuring it as
        digester.addCallMethod("FXTRADE/sale_ccy", "addCurrencyMapping", 2);
        digester.addCallParam("FXTRADE/sale_ccy", 0);
        digester.addRule("FXTRADE/sale_ccy", new ElementNameParamRule(1));
My question is really given my two days experience of Digester, Is this a
sensible solution.

package org.apache.commons.digester;
import java.lang.reflect.Method;
import org.xml.sax.Attributes;
 * Rule implementation that saves a parameter from either an attribute of
 * this element, or from the element body, to be used in a call generated
 * by a surrounding CallMethodRule rule.
 * @author Craig McClanahan
 * @version $Revision: 1.7 $ $Date: 2002/03/23 17:45:57 $
public class ElementNameParamRule extends CallParamRule {
    // -----------------------------------------------------------
     * Construct a "call parameter" rule that will save the body text of
     * element as the parameter value.
     * @param paramIndex The zero-relative parameter number
    public ElementNameParamRule(int paramIndex) {
     * Construct a "call parameter" rule that will save the value of the
     * specified attribute as the parameter value.
     * @param paramIndex The zero-relative parameter number
     * @param attributeName The name of the attribute to save
    public ElementNameParamRule(int paramIndex,
                         String attributeName) {
     super (paramIndex, attributeName);
    // --------------------------------------------------------- Public
     * Process the start of this element.
     * @param attributes The attribute list for this element
    public void begin(Attributes attributes) throws Exception {

        if (attributeName != null) {
            bodyText = digester.getCurrentElementName();
     * Render a printable version of this Rule.
    public String toString() {

        StringBuffer sb = new StringBuffer("ElementNameParamRule[");
        sb.append(", attributeName=");
        return (sb.toString());

:-) Tom Lister
Technical Architecture Group
* - 020 7756 5014
* -

-----Original Message-----
From: Simon Kitching []
Sent: 09 July 2003 00:25
To: Jakarta Commons Users List
Subject: Re: [Digester] element names

On Wed, 2003-07-09 at 04:54, Lister, Tom (ANTS) wrote:
> Hi
> I'm need to parse an XML document and cross reference selected elements
> a mapping database to resolve different naming conventions between
> We are using XML via MQ for real time integration.
> My problem is that when I get the content of an element to call a mapping
> method call, I also want to pass the name of the element as a second
> parameter to the method. I can't see a way to get this information.
> Alternatively a way to pass in a hard coded parameter would also work as I
> know which elements I am defining rules for.
> I can't see any way to pass parameters to a method call other than element
> contents - or have I missed something basic.
> Do I need to build a custom rule for this?

I don't think what you want to do can be accomplished without extending
Digester in one way or another.

Digester class has a getCurrentElementName() method.
The Rule class (which is extended by every type of Rule) has a
getDigester() method. So yes I think you could write a custom rule which
passes the element name.

Your suggestion about passing a constant string as a parameter also
sounds reasonable but as far as I am aware, CallMethodRule/CallParamRule
do not currently support passing constants as parameters. I think that
this feature would be a nice addition to Digester; eg adding a new
  public CallParamRule(int paramIndex, Object paramObj)

If you did implement constant parameters, I think it would be a good
candidate for inclusion in Digester (not that my opinion counts for
anything :-). 



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

This communication (including any attachments) contains confidential information.  If you
are not the intended recipient and you have received this communication in error, you should
destroy it without copying, disclosing or otherwise using its contents.  Please notify the
sender immediately of the error.

Internet communications are not necessarily secure and may be intercepted or changed after
they are sent.  Abbey National Treasury Services plc does not accept liability for any loss
you may suffer as a result of interception or any liability for such changes.  If you wish
to confirm the origin or content of this communication, please contact the sender by using
an alternative means of communication.

This communication does not create or modify any contract and, unless otherwise stated, is
not intended to be contractually binding.

Abbey National Treasury Services plc. Registered Office:  Abbey National House, 2 Triton Square,
Regents Place, London NW1 3AN.  Registered in England under Company Registration Number: 2338548.
 Regulated by the Financial Services Authority (FSA).

View raw message