1 package net.sf.msplice.property.impl; 2 3 import net.sf.msplice.property.IPropertySetter; 4 import net.sf.msplice.property.PropertySetException; 5 6 import org.apache.commons.beanutils.PropertyUtils; 7 import org.apache.commons.lang.StringUtils; 8 9 public class BeanutilsPropertySetter implements IPropertySetter { 10 11 public void setProperty(String propertyName, Object rootObject, Object value) 12 throws PropertySetException { 13 14 boolean emptyPropertyName = StringUtils.isEmpty(propertyName); 15 boolean nullRoot = (rootObject == null); 16 17 StringBuffer messageBuffer = new StringBuffer(); 18 if (nullRoot || emptyPropertyName) { 19 if (nullRoot) { 20 messageBuffer.append("The root object must not be null! "); 21 } 22 if (emptyPropertyName) { 23 messageBuffer.append("The property name must not be empty! "); 24 } 25 throw new PropertySetException(messageBuffer.toString()); 26 } 27 28 try { 29 PropertyUtils.setNestedProperty(rootObject, propertyName, value); 30 } catch (Exception e) { 31 throw new PropertySetException( 32 "Could not set the property with name: " + propertyName 33 + ", on object: " + rootObject 34 + ", with the value: " + value, e); 35 } 36 37 } 38 }