Search in sources :

Example 1 with IPropertyMap

use of org.jowidgets.cap.common.api.bean.IPropertyMap 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 IPropertyMap

use of org.jowidgets.cap.common.api.bean.IPropertyMap in project jo-client-platform by jo-source.

the class BeanDtoFactoryImpl method createDto.

@Override
public IBeanDto createDto(final BEAN_TYPE bean) {
    Assert.paramNotNull(bean, "bean");
    final IBeanDtoBuilder builder = CapCommonToolkit.dtoBuilder(beanType);
    // interceptor annotation before
    if (interceptor != null) {
        interceptor.beforeCreate(bean, builder);
    }
    // plugin before invocation
    for (final IBeanDtoFactoryPlugin<BEAN_TYPE> plugin : interceptorPlugins) {
        plugin.beforeCreate(bean, builder);
    }
    builder.setId(identityResolver.getId(bean));
    builder.setVersion(identityResolver.getVersion(bean));
    for (final String propertyName : propertyNames) {
        final Method method = methods.get(propertyName);
        if (method != null) {
            try {
                builder.setValue(propertyName, method.invoke(bean));
            } catch (final Exception e) {
                throw new RuntimeException(e);
            }
        } else if (bean instanceof IPropertyMap) {
            builder.setValue(propertyName, ((IPropertyMap) bean).getValue(propertyName));
        }
    }
    // interceptor annotation after
    if (interceptor != null) {
        interceptor.afterCreate(bean, builder);
    }
    // plugin after invocation
    for (final IBeanDtoFactoryPlugin<BEAN_TYPE> plugin : interceptorPlugins) {
        plugin.afterCreate(bean, builder);
    }
    return builder.build();
}
Also used : IPropertyMap(org.jowidgets.cap.common.api.bean.IPropertyMap) Method(java.lang.reflect.Method) IBeanDtoBuilder(org.jowidgets.cap.common.api.bean.IBeanDtoBuilder) IntrospectionException(java.beans.IntrospectionException)

Example 3 with IPropertyMap

use of org.jowidgets.cap.common.api.bean.IPropertyMap 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 4 with IPropertyMap

use of org.jowidgets.cap.common.api.bean.IPropertyMap in project jo-client-platform by jo-source.

the class BeanPropertyAccessorImpl method getValue.

@Override
public Object getValue(final BEAN_TYPE bean, final String propertyName) {
    Assert.paramNotNull(bean, "bean");
    final Method method = methods.get(propertyName);
    if (method != null) {
        try {
            return method.invoke(bean);
        } catch (final Exception e) {
            throw new RuntimeException(e);
        }
    } else if (bean instanceof IPropertyMap) {
        return ((IPropertyMap) bean).getValue(propertyName);
    } else {
        throw new IllegalArgumentException("The property with the name '" + propertyName + "' cannot be accessed for the bean: " + bean);
    }
}
Also used : IPropertyMap(org.jowidgets.cap.common.api.bean.IPropertyMap) Method(java.lang.reflect.Method) IntrospectionException(java.beans.IntrospectionException)

Aggregations

Method (java.lang.reflect.Method)4 IPropertyMap (org.jowidgets.cap.common.api.bean.IPropertyMap)4 IntrospectionException (java.beans.IntrospectionException)3 IBeanDtoBuilder (org.jowidgets.cap.common.api.bean.IBeanDtoBuilder)1 BeanException (org.jowidgets.cap.common.api.exception.BeanException)1 IBeanInitializerPlugin (org.jowidgets.cap.service.api.plugin.IBeanInitializerPlugin)1 IBeanModifierPlugin (org.jowidgets.cap.service.api.plugin.IBeanModifierPlugin)1