in blueprint/blueprint-cm/src/main/java/org/apache/aries/blueprint/compendium/cm/CmManagedProperties.java [199:264]
private void inject(Object bean, boolean initial) {
LOGGER.debug("Injecting bean for bean={} / pid={}", beanName, persistentId);
LOGGER.debug("Configuration: {}", properties);
if (initial || "container-managed".equals(updateStrategy)) {
if (properties != null) {
for (Enumeration<String> e = properties.keys(); e.hasMoreElements();) {
String key = e.nextElement();
Object val = properties.get(key);
String setterName = "set" + Character.toUpperCase(key.charAt(0));
if (key.length() > 0) {
setterName += key.substring(1);
}
Set<Method> validSetters = new LinkedHashSet<Method>();
List<Method> methods = new ArrayList<Method>(Arrays.asList(bean.getClass().getMethods()));
methods.addAll(Arrays.asList(bean.getClass().getDeclaredMethods()));
for (Method method : methods) {
if (method.getName().equals(setterName)) {
if (shouldSkip(method)) {
continue;
}
Class methodParameterType = method.getParameterTypes()[0];
Object propertyValue;
try {
propertyValue = blueprintContainer.getConverter().convert(val, new ReifiedType(methodParameterType));
} catch (Throwable t) {
LOGGER.debug("Unable to convert value for setter: " + method, t);
continue;
}
if (methodParameterType.isPrimitive() && propertyValue == null) {
LOGGER.debug("Null can not be assigned to {}: {}", methodParameterType.getName(), method);
continue;
}
if (validSetters.add(method)) {
try {
method.invoke(bean, propertyValue);
} catch (Exception t) {
LOGGER.debug("Setter can not be invoked: " + method, getRealCause(t));
}
}
}
}
if (validSetters.isEmpty()) {
LOGGER.debug("Unable to find a valid setter method for property {} and value {}", key, val);
}
}
}
} else if ("component-managed".equals(updateStrategy) && updateMethod != null) {
List<Method> methods = ReflectionUtils.findCompatibleMethods(bean.getClass(), updateMethod, new Class[] { Map.class });
Map map = null;
if (properties != null) {
map = new HashMap();
for (Enumeration<String> e = properties.keys(); e.hasMoreElements();) {
String key = e.nextElement();
Object val = properties.get(key);
map.put(key, val);
}
}
for (Method method : methods) {
try {
method.invoke(bean, map);
} catch (Throwable t) {
LOGGER.warn("Unable to call method " + method + " on bean " + beanName, getRealCause(t));
}
}
}
}