Search in sources :

Example 1 with IBeanInitializerPlugin

use of org.jowidgets.cap.service.api.plugin.IBeanInitializerPlugin in project jo-client-platform by jo-source.

the class BeanInitializerImpl method initialize.

@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public void initialize(final BEAN_TYPE bean, final IBeanData beanData) {
    Assert.paramNotNull(bean, "bean");
    Assert.paramNotNull(beanData, "beanData");
    // plugin before invocation
    final List<IBeanInitializerPlugin<?>> plugins;
    plugins = PluginProvider.getPlugins(IBeanInitializerPlugin.ID, pluginProperties);
    for (final IBeanInitializerPlugin plugin : plugins) {
        plugin.beforeInitialize(bean, beanData);
    }
    // set the values
    for (final String propertyName : propertyNames) {
        final Method method = methods.get(propertyName);
        if (method != null) {
            try {
                method.invoke(bean, beanData.getValue(propertyName));
            } catch (final Exception e) {
                throw new RuntimeException("Error while setting property '" + propertyName + "' on bean '" + bean + "'.", e);
            }
        } else if (bean instanceof IPropertyMap) {
            ((IPropertyMap) bean).setValue(propertyName, beanData.getValue(propertyName));
        }
    }
    // plugin after invocation
    for (final IBeanInitializerPlugin plugin : plugins) {
        plugin.afterInitialize(bean, beanData);
    }
}
Also used : IPropertyMap(org.jowidgets.cap.common.api.bean.IPropertyMap) Method(java.lang.reflect.Method) IntrospectionException(java.beans.IntrospectionException) IBeanInitializerPlugin(org.jowidgets.cap.service.api.plugin.IBeanInitializerPlugin)

Example 2 with IBeanInitializerPlugin

use of org.jowidgets.cap.service.api.plugin.IBeanInitializerPlugin in project jo-client-platform by jo-source.

the class BeanPropertyMapInitializer method initialize.

@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public void initialize(final IBeanPropertyMap bean, final IBeanData beanData) {
    // plugin before invocation
    final List<IBeanInitializerPlugin<?>> plugins;
    plugins = PluginProvider.getPlugins(IBeanInitializerPlugin.ID, pluginProperties);
    for (final IBeanInitializerPlugin plugin : plugins) {
        plugin.beforeInitialize(bean, beanData);
    }
    // set the values
    for (final String propertyName : propertyNames) {
        if (!IBean.ID_PROPERTY.equals(propertyName) && !IBean.VERSION_PROPERTY.equals(propertyName)) {
            bean.setValue(propertyName, beanData.getValue(propertyName));
        }
    }
    // plugin after invocation
    for (final IBeanInitializerPlugin plugin : plugins) {
        plugin.afterInitialize(bean, beanData);
    }
}
Also used : IBeanInitializerPlugin(org.jowidgets.cap.service.api.plugin.IBeanInitializerPlugin)

Aggregations

IBeanInitializerPlugin (org.jowidgets.cap.service.api.plugin.IBeanInitializerPlugin)2 IntrospectionException (java.beans.IntrospectionException)1 Method (java.lang.reflect.Method)1 IPropertyMap (org.jowidgets.cap.common.api.bean.IPropertyMap)1