Search in sources :

Example 1 with ConfigurationAware

use of org.dkpro.lab.task.ConfigurationAware in project dkpro-lab by dkpro.

the class DefaultLifeCycleManager method configure.

@Override
public void configure(TaskContext aParentContext, Task aTask, Map<String, Object> aConfiguration) {
    PropertyAccessor paBean = PropertyAccessorFactory.forBeanPropertyAccess(aTask);
    PropertyAccessor paDirect = PropertyAccessorFactory.forDirectFieldAccess(aTask);
    for (Entry<String, Object> property : aConfiguration.entrySet()) {
        String key = property.getKey();
        Object value = property.getValue();
        // a non-default name and might apply.
        for (String prop : ParameterUtil.findBeanPropertiesWithName(aTask, key)) {
            // Try setter - there may be extra logic in the setter
            if (paBean.isWritableProperty(prop)) {
                paBean.setPropertyValue(prop, value);
            } else // Otherwise try direct access
            if (paDirect.isWritableProperty(prop)) {
                paDirect.setPropertyValue(prop, value);
            }
        }
        // Try setter - there may be extra logic in the setter
        if (paBean.isWritableProperty(key)) {
            paBean.setPropertyValue(key, value);
        } else // Otherwise try direct access
        if (paDirect.isWritableProperty(key)) {
            paDirect.setPropertyValue(key, value);
        }
    }
    if (aTask instanceof ConfigurationAware) {
        ((ConfigurationAware) aTask).setConfiguration(aConfiguration);
    }
    if (aParentContext != null) {
        aParentContext.message("Injected parameters into [" + aTask.getType() + "]");
    }
}
Also used : PropertyAccessor(org.springframework.beans.PropertyAccessor) ConfigurationAware(org.dkpro.lab.task.ConfigurationAware)

Aggregations

ConfigurationAware (org.dkpro.lab.task.ConfigurationAware)1 PropertyAccessor (org.springframework.beans.PropertyAccessor)1