FileDocCategorySizeDatePackage
ObjectParamRule.javaAPI DocApache Tomcat 6.0.144331Fri Jul 20 04:20:30 BST 2007org.apache.tomcat.util.digester

ObjectParamRule

public class ObjectParamRule extends Rule

Rule implementation that saves a parameter for use by a surrounding CallMethodRule.

This parameter may be:

  • an arbitrary Object defined programatically, assigned when the element pattern associated with the Rule is matched See {@link #ObjectParamRule(int paramIndex, Object param)}
  • an arbitrary Object defined programatically, assigned if the element pattern AND specified attribute name are matched See {@link #ObjectParamRule(int paramIndex, String attributeName, Object param)}

since
1.4

Fields Summary
protected String
attributeName
The attribute which we are attempting to match
protected int
paramIndex
The zero-relative index of the parameter we are saving.
protected Object
param
The parameter we wish to pass to the method call
Constructors Summary
public ObjectParamRule(int paramIndex, Object param)
Construct a "call parameter" rule that will save the given Object as the parameter value.

param
paramIndex The zero-relative parameter number
param
param the parameter to pass along

        this(paramIndex, null, param);
    
public ObjectParamRule(int paramIndex, String attributeName, Object param)
Construct a "call parameter" rule that will save the given Object as the parameter value, provided that the specified attribute exists.

param
paramIndex The zero-relative parameter number
param
attributeName The name of the attribute to match
param
param the parameter to pass along

        this.paramIndex = paramIndex;
        this.attributeName = attributeName;
        this.param = param;
    
Methods Summary
public voidbegin(java.lang.String namespace, java.lang.String name, org.xml.sax.Attributes attributes)
Process the start of this element.

param
attributes The attribute list for this element



    // --------------------------------------------------------- Public Methods

                       
         
                          
        Object anAttribute = null;
        Object parameters[] = (Object[]) digester.peekParams();

        if (attributeName != null) {
            anAttribute = attributes.getValue(attributeName);
            if(anAttribute != null) {
                parameters[paramIndex] = param;
            }
            // note -- if attributeName != null and anAttribute == null, this rule
            // will pass null as its parameter!
        }else{
            parameters[paramIndex] = param;
        }
    
public java.lang.StringtoString()
Render a printable version of this Rule.

        StringBuffer sb = new StringBuffer("ObjectParamRule[");
        sb.append("paramIndex=");
        sb.append(paramIndex);
        sb.append(", attributeName=");
        sb.append(attributeName);
        sb.append(", param=");
        sb.append(param);
        sb.append("]");
        return (sb.toString());