Package org.coliper.ibean.proxy.handler
Class FreezableHandler
- java.lang.Object
-
- org.coliper.ibean.proxy.handler.StatefulExtensionHandler
-
- org.coliper.ibean.proxy.handler.FreezableHandler
-
- All Implemented Interfaces:
Freezable<Object>,TempFreezable<Object>,ExtensionHandler
public class FreezableHandler extends StatefulExtensionHandler implements TempFreezable<Object>
-
-
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 FreezableHandler()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Objectfreeze()Set the bean to immutable and prevents all further setter calls.ObjectinterceptSetterCall(IBeanContext<?> context, IBeanFieldMetaInfo fieldMeta, Object newValue, Object proxyInstance)Called as an optional hook with every setter call on an IBean.booleanisFrozen()voidonInitStateful(Object proxyInstance, IBeanTypeMetaInfo<?> metaInfo, IBeanFactory unused)Initialization method for stateful handlers that is called after initialization of the IBean.Objectunfreeze()-
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
-
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
-
freeze
public Object freeze()
Description copied from interface:FreezableSet the bean to immutable and prevents all further setter calls.- Specified by:
freezein interfaceFreezable<Object>- Returns:
- this (the bean itself); used for chaining with setter calls in
ModernBeanStyle
-
isFrozen
public boolean isFrozen()
- Specified by:
isFrozenin interfaceFreezable<Object>- Returns:
trueif the bean was switched to immutable with a previousFreezable.freeze()call
-
unfreeze
public Object unfreeze()
- Specified by:
unfreezein interfaceTempFreezable<Object>
-
-