FileDocCategorySizeDatePackage
SetPropertyRule.javaAPI DocApache Tomcat 6.0.144763Fri Jul 20 04:20:32 BST 2007org.apache.tomcat.util.digester

SetPropertyRule

public class SetPropertyRule extends Rule
Rule implementation that sets an individual property on the object at the top of the stack, based on attributes with specified names.

Fields Summary
protected String
name
The attribute that will contain the property name.
protected String
value
The attribute that will contain the property value.
Constructors Summary
public SetPropertyRule(Digester digester, String name, String value)
Construct a "set property" rule with the specified name and value attributes.

param
digester The digester with which this rule is associated
param
name Name of the attribute that will contain the name of the property to be set
param
value Name of the attribute that will contain the value to which the property should be set
deprecated
The digester instance is now set in the {@link Digester#addRule} method. Use {@link #SetPropertyRule(String name, String value)} instead.


        this(name, value);

    
public SetPropertyRule(String name, String value)
Construct a "set property" rule with the specified name and value attributes.

param
name Name of the attribute that will contain the name of the property to be set
param
value Name of the attribute that will contain the value to which the property should be set


        this.name = name;
        this.value = value;

    
Methods Summary
public voidbegin(org.xml.sax.Attributes attributes)
Process the beginning of this element.

param
attributes The attribute list of this element
exception
NoSuchMethodException if the bean does not have a writeable property of the specified name



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


                                       
          

        // Identify the actual property name and value to be used
        String actualName = null;
        String actualValue = null;
        for (int i = 0; i < attributes.getLength(); i++) {
            String name = attributes.getLocalName(i);
            if ("".equals(name)) {
                name = attributes.getQName(i);
            }
            String value = attributes.getValue(i);
            if (name.equals(this.name)) {
                actualName = value;
            } else if (name.equals(this.value)) {
                actualValue = value;
            }
        }

        // Get a reference to the top object
        Object top = digester.peek();

        // Log some debugging information
        if (digester.log.isDebugEnabled()) {
            digester.log.debug("[SetPropertyRule]{" + digester.match +
                    "} Set " + top.getClass().getName() + " property " +
                    actualName + " to " + actualValue);
        }

        // Set the property (with conversion as necessary)
        // FIXME: Exception if property doesn't exist ?
        IntrospectionUtils.setProperty(top, actualName, actualValue);

    
public java.lang.StringtoString()
Render a printable version of this Rule.


        StringBuffer sb = new StringBuffer("SetPropertyRule[");
        sb.append("name=");
        sb.append(name);
        sb.append(", value=");
        sb.append(value);
        sb.append("]");
        return (sb.toString());