public void body(String value) throws Exception {
String propName = currChildElementName;
if (elementNames.containsKey(currChildElementName)) {
// overide propName
propName = (String) elementNames.get(currChildElementName);
if (propName == null) {
// user wants us to ignore this element
return;
}
}
boolean debug = log.isDebugEnabled();
if (debug) {
log.debug("[SetNestedPropertiesRule]{" + digester.match +
"} Setting property '" + propName + "' to '" +
value + "'");
}
// Populate the corresponding properties of the top object
Object top = digester.peek();
if (debug) {
if (top != null) {
log.debug("[SetNestedPropertiesRule]{" + digester.match +
"} Set " + top.getClass().getName() +
" properties");
} else {
log.debug("[SetPropertiesRule]{" + digester.match +
"} Set NULL properties");
}
}
if (trimData) {
value = value.trim();
}
if (!allowUnknownChildElements) {
// Force an exception if the property does not exist
// (BeanUtils.setProperty() silently returns in this case)
if (top instanceof DynaBean) {
DynaProperty desc =
((DynaBean) top).getDynaClass().getDynaProperty(propName);
if (desc == null) {
throw new NoSuchMethodException
("Bean has no property named " + propName);
}
} else /* this is a standard JavaBean */ {
PropertyDescriptor desc =
PropertyUtils.getPropertyDescriptor(top, propName);
if (desc == null) {
throw new NoSuchMethodException
("Bean has no property named " + propName);
}
}
}
try
{
BeanUtils.setProperty(top, propName, value);
}
catch(NullPointerException e) {
log.error("NullPointerException: "
+ "top=" + top + ",propName=" + propName + ",value=" + value + "!");
throw e;
}
}
|