Package org.coliper.ibean.proxy
Interface BeanStyleHandler
-
public interface BeanStyleHandlerBeanStyleHandlers are used by theProxyIBeanFactoryto deal withBeanStyles that differ from the classic bean style in their runtime behavior.BeanStyleHandlerss are necessary in two cases:- Setter methods of a bean style do not return
void. - Getter methods of a bean style return a type that does not match to the type of the corresponding field.
If you want to provide your own bean style and at least one of the two conditions above match to your custom bean style then you need to also provide a
BeanStyleHandler. Style and its matching handler are configured when assembling aProxyIBeanFactoryusing methodProxyIBeanFactory.Builder.withBeanStyle(BeanStyle, BeanStyleHandler). - Setter methods of a bean style do not return
-
-
Field Summary
Fields Modifier and Type Field Description static BeanStyleHandlerCLASSIC_WITH_OPTIONAL_SUPPORT_HANDLERBeanStyleHandlerforClassicBeanStyleWithOptionalSupport.static BeanStyleHandlerDEFAULT_HANDLERBeanStyleHandlerforClassicBeanStyle.static BeanStyleHandlerMODERN_HANDLERBeanStyleHandlerforModernBeanStyle.
-
Method Summary
All Methods Instance Methods Default Methods Modifier and Type Method Description default ObjectconvertReturnValueOfGetterCall(Class<?> expectedReturnType, Object returnValueWithWrongType)This method is called during runtime of a bean, more precisely, always when getters of a bean are called to adjust the type of the return value of the getter method.
This method is only called for bean styles that allow getter methods that do not match to the type of the field.default ObjectcreateReturnValueForSetterCall(Object instance, Method setterMethod, Object newValue)This method is called during runtime of a bean, more precisely, always when setters of a bean are called to assemble the return value of the setter method.
This method is only called for bean styles that allow setter methods that do not returnvoid.
-
-
-
Field Detail
-
DEFAULT_HANDLER
static final BeanStyleHandler DEFAULT_HANDLER
BeanStyleHandlerforClassicBeanStyle.
-
CLASSIC_WITH_OPTIONAL_SUPPORT_HANDLER
static final BeanStyleHandler CLASSIC_WITH_OPTIONAL_SUPPORT_HANDLER
BeanStyleHandlerforClassicBeanStyleWithOptionalSupport.
-
MODERN_HANDLER
static final BeanStyleHandler MODERN_HANDLER
BeanStyleHandlerforModernBeanStyle.
-
-
Method Detail
-
createReturnValueForSetterCall
default Object createReturnValueForSetterCall(Object instance, Method setterMethod, Object newValue)
This method is called during runtime of a bean, more precisely, always when setters of a bean are called to assemble the return value of the setter method.
This method is only called for bean styles that allow setter methods that do not returnvoid. Therefore this method only needs to be implemented for those type of bean styles. This default implementation throwsIllegalStateException.See
ModernBeanStylefor a concrete implementation of this method.- Parameters:
instance- the IBean instancesetterMethod- the setter method in whose return value should be creatednewValue- the new value of the field, given as a parameter to the setter- Returns:
- the value that will then be returned from the setter
-
convertReturnValueOfGetterCall
default Object convertReturnValueOfGetterCall(Class<?> expectedReturnType, Object returnValueWithWrongType)
This method is called during runtime of a bean, more precisely, always when getters of a bean are called to adjust the type of the return value of the getter method.
This method is only called for bean styles that allow getter methods that do not match to the type of the field. Therefore this method only needs to be implemented for those type of bean styles. This default implementation throwsIllegalStateException.See
ModernBeanStylefor a concrete implementation of this method.- Parameters:
expectedReturnType- the type the field value needs to be converted toreturnValueWithWrongType- the field value that needs to be converted- Returns:
- the value that will then be returned from the getter
-
-