Enum Class PropertyAccessStrategy

java.lang.Object
java.lang.Enum<PropertyAccessStrategy>
de.cuioss.test.valueobjects.property.util.PropertyAccessStrategy
All Implemented Interfaces:
Serializable, Comparable<PropertyAccessStrategy>, Constable

Defines different ways for reading / writing properties.
Author:
Oliver Wolff
  • Enum Constant Details

    • BEAN_PROPERTY

      Reads and writes property according to the JavaBean-Spec. It uses PropertyUtil to do so. It acts as part of JUnit testing, therefore it will translate many of the more technical Exceptions to corresponding AssertionError
    • BUILDER_COLLECTION_AND_SINGLE_ELEMENT

      In some cases the builder supports multiple ways to fill Collection based elements, e.g. there is a field with the structure
       
           private List<String> name;
       
       
      There can be two methods to fill this elements in the builder:
       
        public Builder names(List<String> names);
        public Builder names(String name);
       
       
      This strategy writes the property using both methods. Therefore it uses BuilderMetadata#getBuilderSingleAddMethodName() in order to find the single addMethod. The plural add method is supposed to be the name of the property itself therefore derived by BuilderMetadata#getBuilderAddMethodName(). In case there is different methodName for adding, e.g.
       
        public Builder names(List<String> names);
        public Builder name(String name);
       
       
      you can specify the method-name explicitly by using BuilderMetadata.BuilderMetadataBuilder.builderSingleAddMethodName(String)

      The read method delegates to BEAN_PROPERTY because it can not be read from an actual builder but from the later created bean.

    • BUILDER_DIRECT

      Writes a property in a builder using BuilderMetadata#getBuilderAddMethodName() to determine the correct write method. The parameter type is exactly the same as defined at PropertyMetadata.getPropertyClass(). The read method delegates to BEAN_PROPERTY because it can not be read from an actual builder but from the later created bean.
    • FLUENT_WRITER

      This strategy is for cases where PropertyUtil is not capable of writing an attribute. This is usually the case for elements that defined a fluent-api (not void as return value). The read method delegates to BEAN_PROPERTY
  • Method Details

    • values

      public static PropertyAccessStrategy[] values()
      Returns an array containing the constants of this enum class, in the order they are declared.
      Returns:
      an array containing the constants of this enum class, in the order they are declared
    • valueOf

      public static PropertyAccessStrategy valueOf(String name)
      Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)
      Parameters:
      name - the name of the enum constant to be returned.
      Returns:
      the enum constant with the specified name
      Throws:
      IllegalArgumentException - if this enum class has no constant with the specified name
      NullPointerException - if the argument is null
    • writeProperty

      public abstract Object writeProperty(Object target, PropertyMetadata propertyMetadata, Object propertyValue)
      Writes the property into the given target;
      Parameters:
      target - to be written to.
      propertyMetadata - identifying the concrete property, must not be null
      propertyValue - to be set, may be null
      Returns:
      the modified object
      Throws:
      AssertionError - in case the property can not be written.
    • readProperty

      public abstract Object readProperty(Object target, PropertyMetadata propertyMetadata)
      Reads the property from the given target;
      Parameters:
      target - to be written to.
      propertyMetadata - identifying the concrete property, must not be null
      Returns:
      the read property, may be null
      Throws:
      AssertionError - in case the property can not be read.