Package org.coliper.ibean.proxy.handler
Class ModificationAwareHandler
- java.lang.Object
-
- org.coliper.ibean.proxy.handler.StatefulExtensionHandler
-
- org.coliper.ibean.proxy.handler.ModificationAwareHandler
-
- All Implemented Interfaces:
ModificationAware,ModificationAwareExt,ExtensionHandler
public class ModificationAwareHandler extends StatefulExtensionHandler implements ModificationAwareExt
ExtensionHandlerimplementation for bean extension interfaceModificationAwareandModificationAwareExt.
-
-
Field Summary
Fields Modifier and Type Field Description static ExtensionSupportSUPPORTExtensionSupportrelated to this handler supposed to be used when configuring extension handlers inIBeanFactorys, for example inProxyIBeanFactory.Builder.withInterfaceSupport(ExtensionSupport).
-
Constructor Summary
Constructors Constructor Description ModificationAwareHandler()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanallFieldsModified()Checks if every field has been set since creation orModificationAware.resetModified().String[]getModifiedFieldNames()Gives the names of all bean fields that have been modified since creation or respectively since the last call ofModificationAware.resetModified().ObjectinterceptSetterCall(IBeanContext<?> context, IBeanFieldMetaInfo fieldMeta, Object newValue, Object proxyInstance)Called as an optional hook with every setter call on an IBean.booleanisModified()voidonInitStateful(Object proxyInstance, IBeanTypeMetaInfo<?> metaInfo, IBeanFactory unused)Initialization method for stateful handlers that is called after initialization of the IBean.voidresetModified()Sets a bean to not modified.-
Methods inherited from class org.coliper.ibean.proxy.handler.StatefulExtensionHandler
handleExtendedInterfaceCall
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.coliper.ibean.proxy.ExtensionHandler
interceptGetterCall
-
-
-
-
Field Detail
-
SUPPORT
public static final ExtensionSupport SUPPORT
ExtensionSupportrelated to this handler supposed to be used when configuring extension handlers inIBeanFactorys, for example inProxyIBeanFactory.Builder.withInterfaceSupport(ExtensionSupport).
-
-
Method Detail
-
onInitStateful
public void onInitStateful(Object proxyInstance, IBeanTypeMetaInfo<?> metaInfo, IBeanFactory unused)
Description copied from interface:ExtensionHandlerInitialization method for stateful handlers that is called after initialization of the IBean. If a handler is registered as stateful a new instance of theExtensionHandlerimplementation is created for each new IBean. After the IBean itself and all handlers created this method is called on all stateful handlers. This method should therefore be overwritten if a handler needs some initialization after creation.The default implementation does nothing.
- Specified by:
onInitStatefulin interfaceExtensionHandler- Parameters:
proxyInstance- the IBean instancemetaInfo- meta information about the IBeanunused- the factory that creates the IBean instance
-
isModified
public boolean isModified()
- Specified by:
isModifiedin interfaceModificationAware- Returns:
trueif the bean is dirty, that is, if a setter has been called since creation or lastModificationAware.resetModified()
-
resetModified
public void resetModified()
Description copied from interface:ModificationAwareSets a bean to not modified. If the bean was not dirty it does nothing.- Specified by:
resetModifiedin interfaceModificationAware
-
interceptSetterCall
public Object interceptSetterCall(IBeanContext<?> context, IBeanFieldMetaInfo fieldMeta, Object newValue, Object proxyInstance)
Description copied from interface:ExtensionHandlerCalled as an optional hook with every setter call on an IBean. Setter calls on IBeans are handled by the IBean implementation itself but anExtensionHandlercan implement this method to hook into the setter call. It can just peak on the new value or it can even change it or throw an exception.When you have several extension handlers registered for an IBean type the intercept calls will be called in the order in which the handlers are registered in the
ProxyIBeanFactory. See alsoProxyIBeanFactory.Builder.withInterfaceSupport(ExtensionSupport).The default implementation just returns
newValue.- Specified by:
interceptSetterCallin interfaceExtensionHandler- Parameters:
context- provides meta information about the IBeanfieldMeta- provides meta information about the field related to the setternewValue- the current new value of the field. This must not match to the initial value given in the setter call of the IBean as the value might have already been changed by intercept calls from other handlersproxyInstance- the IBean instance itself- Returns:
- the value the field is supposed to be set to. If you do not want
to change the value just pass the value provided in
newValue
-
getModifiedFieldNames
public String[] getModifiedFieldNames()
Description copied from interface:ModificationAwareExtGives the names of all bean fields that have been modified since creation or respectively since the last call ofModificationAware.resetModified().- Specified by:
getModifiedFieldNamesin interfaceModificationAwareExt- Returns:
- a string array containing the names of the modified fields. If no
fields have been modified an empty array will be returned. The
names of the fields are deducible from the getter and setter
names depending on the bean style.
The order of field names returned is random and not be reliable!
-
allFieldsModified
public boolean allFieldsModified()
Description copied from interface:ModificationAwareExtChecks if every field has been set since creation orModificationAware.resetModified(). Can for example be used as a runtime check if an initialization has been complete.- Specified by:
allFieldsModifiedin interfaceModificationAwareExt- Returns:
trueif each setter had been called
-
-