use of org.apache.aries.blueprint.utils.ReflectionUtils.PropertyDescriptor in project aries by apache.
the class BeanRecipe method setProperty.
private void setProperty(Object instance, Class clazz, String propertyName, Object propertyValue) {
String[] names = propertyName.split("\\.");
for (int i = 0; i < names.length - 1; i++) {
PropertyDescriptor pd = getPropertyDescriptor(clazz, names[i]);
if (pd.allowsGet()) {
try {
instance = pd.get(instance, blueprintContainer);
} catch (Exception e) {
throw new ComponentDefinitionException("Error getting property: " + names[i] + " on bean " + getName() + " when setting property " + propertyName + " on class " + clazz.getName(), getRealCause(e));
}
if (instance == null) {
throw new ComponentDefinitionException("Error setting compound property " + propertyName + " on bean " + getName() + ". Property " + names[i] + " is null");
}
clazz = instance.getClass();
} else {
throw new ComponentDefinitionException("No getter for " + names[i] + " property on bean " + getName() + " when setting property " + propertyName + " on class " + clazz.getName());
}
}
// Instantiate value
if (propertyValue instanceof Recipe) {
propertyValue = ((Recipe) propertyValue).create();
}
final PropertyDescriptor pd = getPropertyDescriptor(clazz, names[names.length - 1]);
if (pd.allowsSet()) {
try {
pd.set(instance, propertyValue, blueprintContainer);
} catch (Exception e) {
throw new ComponentDefinitionException("Error setting property: " + pd, getRealCause(e));
}
} else {
throw new ComponentDefinitionException("No setter for " + names[names.length - 1] + " property");
}
}
Aggregations