Search in sources :

Example 1 with IBeanModifierPlugin

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

the class BeanModifierImpl method modify.

@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public void modify(final BEAN_TYPE bean, final IBeanModification modification) {
    final Method writeMethod = writeMethods.get(modification.getPropertyName());
    if (writeMethod != null || bean instanceof IPropertyMap) {
        // plugin before invocation
        final List<IBeanModifierPlugin<?>> plugins;
        plugins = PluginProvider.getPlugins(IBeanModifierPlugin.ID, pluginProperties);
        for (final IBeanModifierPlugin plugin : plugins) {
            plugin.beforeModification(bean, modification);
        }
        // do modification
        if (writeMethod != null) {
            try {
                writeMethod.invoke(bean, modification.getNewValue());
            } catch (final Exception e) {
                throw new RuntimeException(e);
            }
        } else if (bean instanceof IPropertyMap) {
            ((IPropertyMap) bean).setValue(modification.getPropertyName(), modification.getNewValue());
        }
        // plugin after invocation
        for (final IBeanModifierPlugin plugin : plugins) {
            plugin.afterModification(bean, modification);
        }
    } else {
        throw new BeanException(modification.getId(), "Tryed to set the property '" + modification.getPropertyName() + "', but the property is not defined / allowed for this bean.");
    }
}
Also used : IPropertyMap(org.jowidgets.cap.common.api.bean.IPropertyMap) BeanException(org.jowidgets.cap.common.api.exception.BeanException) Method(java.lang.reflect.Method) IBeanModifierPlugin(org.jowidgets.cap.service.api.plugin.IBeanModifierPlugin) BeanException(org.jowidgets.cap.common.api.exception.BeanException)

Example 2 with IBeanModifierPlugin

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

the class BeanPropertyMapModifier method modify.

@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public void modify(final IBeanPropertyMap bean, final IBeanModification modification) {
    // plugin before invocation
    final List<IBeanModifierPlugin<?>> plugins;
    plugins = PluginProvider.getPlugins(IBeanModifierPlugin.ID, pluginProperties);
    for (final IBeanModifierPlugin plugin : plugins) {
        plugin.beforeModification(bean, modification);
    }
    // do modification
    bean.setValue(modification.getPropertyName(), modification.getNewValue());
    // plugin after invocation
    for (final IBeanModifierPlugin plugin : plugins) {
        plugin.afterModification(bean, modification);
    }
}
Also used : IBeanModifierPlugin(org.jowidgets.cap.service.api.plugin.IBeanModifierPlugin)

Aggregations

IBeanModifierPlugin (org.jowidgets.cap.service.api.plugin.IBeanModifierPlugin)2 Method (java.lang.reflect.Method)1 IPropertyMap (org.jowidgets.cap.common.api.bean.IPropertyMap)1 BeanException (org.jowidgets.cap.common.api.exception.BeanException)1