public void begin(Attributes attributes) throws Exception {
// --------------------------------------------------------- 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);
}
// Force an exception if the property does not exist
// (BeanUtils.setProperty() silently returns in this case)
//
// This code should probably use PropertyUtils.isWriteable(),
// like SetPropertiesRule does.
if (top instanceof DynaBean) {
DynaProperty desc =
((DynaBean) top).getDynaClass().getDynaProperty(actualName);
if (desc == null) {
throw new NoSuchMethodException
("Bean has no property named " + actualName);
}
} else /* this is a standard JavaBean */ {
PropertyDescriptor desc =
PropertyUtils.getPropertyDescriptor(top, actualName);
if (desc == null) {
throw new NoSuchMethodException
("Bean has no property named " + actualName);
}
}
// Set the property (with conversion as necessary)
BeanUtils.setProperty(top, actualName, actualValue);
}
Process the beginning of this element. |