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
-
Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Enum
Enum.EnumDesc<E extends Enum<E>>
-
Enum Constant Summary
Enum ConstantsEnum ConstantDescriptionReads and writes property according to the JavaBean-Spec.In some cases the builder supports multiple ways to fillCollection
based elements, e.g.Writes a property in a builder usingBuilderMetadata#getBuilderAddMethodName()
to determine the correct write method.This strategy is for cases wherePropertyUtil
is not capable of writing an attribute. -
Method Summary
Modifier and TypeMethodDescriptionabstract Object
readProperty
(Object target, PropertyMetadata propertyMetadata) Reads the property from the given target;static PropertyAccessStrategy
Returns the enum constant of this class with the specified name.static PropertyAccessStrategy[]
values()
Returns an array containing the constants of this enum class, in the order they are declared.abstract Object
writeProperty
(Object target, PropertyMetadata propertyMetadata, Object propertyValue) Writes the property into the given target;
-
Enum Constant Details
-
BEAN_PROPERTY
Reads and writes property according to the JavaBean-Spec. It usesPropertyUtil
to do so. It acts as part of JUnit testing, therefore it will translate many of the more technical Exceptions to correspondingAssertionError
-
BUILDER_COLLECTION_AND_SINGLE_ELEMENT
In some cases the builder supports multiple ways to fillCollection
based elements, e.g. there is a field with the structureprivate List<String> name;
public Builder names(List<String> names); public Builder names(String name);
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 byBuilderMetadata#getBuilderAddMethodName()
. In case there is different methodName for adding, e.g.public Builder names(List<String> names); public Builder name(String name);
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 usingBuilderMetadata#getBuilderAddMethodName()
to determine the correct write method. The parameter type is exactly the same as defined atPropertyMetadata.getPropertyClass()
. The read method delegates toBEAN_PROPERTY
because it can not be read from an actual builder but from the later created bean. -
FLUENT_WRITER
This strategy is for cases wherePropertyUtil
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 toBEAN_PROPERTY
-
-
Method Details
-
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
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 nameNullPointerException
- 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 nullpropertyValue
- to be set, may be null- Returns:
- the modified object
- Throws:
AssertionError
- in case the property can not be written.
-
readProperty
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.
-