Interface BeanWrapper<T>

Type Parameters:
T - The bean type.
All Superinterfaces:
AnnotationMetadataProvider, AnnotationSource

public interface BeanWrapper<T> extends AnnotationMetadataProvider
Wraps a bean allowing to read and write its properties via a underlying BeanIntrospection.
Since:
1.1
Author:
graemerocher
  • Method Details

    • getIntrospection

      @NonNull BeanIntrospection<T> getIntrospection()
      Returns:
      The introspection.
    • getBean

      @NonNull T getBean()
      Returns:
      The bean;
    • getPropertyNames

      @NonNull default String[] getPropertyNames()
      The property names.
      Returns:
      The property names
    • getBeanProperties

      @NonNull default Collection<BeanProperty<T,Object>> getBeanProperties()
      The properties.
      Returns:
      The properties
    • getRequiredProperty

      @NonNull default <P> P getRequiredProperty(@NonNull String name, @NonNull Class<P> type)
      Get the property value of the given type or throw an exception if it is unobtainable.
      Type Parameters:
      P - The property generic type
      Parameters:
      name - The name
      type - The type
      Returns:
      The property value
      Throws:
      IntrospectionException - if no property exists
      ConversionErrorException - if the property cannot be converted to the given type
    • getRequiredProperty

      default <P> P getRequiredProperty(@NonNull String name, @NonNull Argument<P> argument)
      Get the property value of the given type or throw an exception if it is unobtainable.
      Type Parameters:
      P - The property generic type
      Parameters:
      name - The name
      argument - The argument type
      Returns:
      The property value
      Throws:
      IntrospectionException - if no property exists
      ConversionErrorException - if the property cannot be converted to the given type
    • getRequiredProperty

      @NonNull default <P> P getRequiredProperty(@NonNull String name, @NonNull ArgumentConversionContext<P> context)
      Get the property value of the given type or throw an exception if it is unobtainable.
      Type Parameters:
      P - The property generic type
      Parameters:
      name - The name
      context - The type
      Returns:
      The property value
      Throws:
      IntrospectionException - if no property exists
      ConversionErrorException - if the property cannot be converted to the given type
    • getProperty

      @NonNull default <P> Optional<P> getProperty(@NonNull String name, @NonNull Class<P> type)
      Get the property of the given name and type.
      Type Parameters:
      P - The required generic type
      Parameters:
      name - The name
      type - The required type
      Returns:
      The property if found and can be converted to the given type
    • getProperty

      default <P> Optional<P> getProperty(@NonNull String name, Argument<P> type)
      Get the property of the given name and type.
      Type Parameters:
      P - The required generic type
      Parameters:
      name - The name
      type - The required type
      Returns:
      The property if found and can be converted to the given type
    • getProperty

      default <P> Optional<P> getProperty(@NonNull String name, ArgumentConversionContext<P> context)
      Get the property of the given name and type.
      Type Parameters:
      P - The required generic type
      Parameters:
      name - The name
      context - The conversion context
      Returns:
      The property if found and can be converted to the given type
    • setProperty

      default BeanWrapper<T> setProperty(@NonNull String name, @Nullable Object value)
      Sets a property of the given name to the given value.
      Parameters:
      name - The name
      value - The value
      Returns:
      This wrapper
      Throws:
      ConversionErrorException - if the value cannot be converted to the underlying property type.
    • getWrapper

      @NonNull static <T2> BeanWrapper<T2> getWrapper(@NonNull T2 bean)
      Obtain a bean wrapper for the given bean.
      Type Parameters:
      T2 - The bean type
      Parameters:
      bean - The bean
      Returns:
      The wrapper
      Throws:
      IntrospectionException - If the wrapper cannot be created
    • findWrapper

      @NonNull static <T2> Optional<BeanWrapper<T2>> findWrapper(@NonNull T2 bean)
      Obtain a bean wrapper for the given bean.
      Type Parameters:
      T2 - The bean type
      Parameters:
      bean - The bean
      Returns:
      The wrapper
      Throws:
      IntrospectionException - If the wrapper cannot be created
    • findWrapper

      @NonNull static <T2> Optional<BeanWrapper<T2>> findWrapper(Class<T2> type, @NonNull T2 bean)
      Obtain a bean wrapper for the given bean.
      Type Parameters:
      T2 - The bean type
      Parameters:
      type - the type
      bean - The bean
      Returns:
      The wrapper
      Throws:
      IntrospectionException - If the wrapper cannot be created
    • getWrapper

      @NonNull static <T2> BeanWrapper<T2> getWrapper(Class<T2> type, @NonNull T2 bean)
      Obtain a bean wrapper for the given bean.
      Type Parameters:
      T2 - The bean type
      Parameters:
      type - the type
      bean - The bean
      Returns:
      The wrapper
      Throws:
      IntrospectionException - If the wrapper cannot be created