SetPropertyRulepublic 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 | nameThe attribute that will contain the property name. | protected String | valueThe 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.
this(name, value);
| public SetPropertyRule(String name, String value)Construct a "set property" rule with the specified name and value
attributes.
this.name = name;
this.value = value;
|
Methods Summary |
---|
public void | begin(org.xml.sax.Attributes attributes)Process the beginning of this element.
// --------------------------------------------------------- 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.String | toString()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());
|
|