Package org.joda.beans.impl
Class BasicBeanBuilder<T extends Bean>
- java.lang.Object
-
- org.joda.beans.impl.BasicBeanBuilder<T>
-
- Type Parameters:
T
- the bean type
- All Implemented Interfaces:
BeanBuilder<T>
- Direct Known Subclasses:
DirectBeanBuilder
public class BasicBeanBuilder<T extends Bean> extends Object implements BeanBuilder<T>
Basic implementation ofBeanBuilder
that wraps a real bean.This approach saves creating a temporary map, but is only suitable if the bean has a no-arg constructor and allows properties to be set.
-
-
Constructor Summary
Constructors Constructor Description BasicBeanBuilder(T bean)
Constructs the builder wrapping the target bean.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description T
build()
Builds the bean from the state of the builder.Object
get(String propertyName)
Gets the value of a single property previously added to the builder.<P> P
get(MetaProperty<P> metaProperty)
Gets the value of a single property previously added to the builder.protected T
getTargetBean()
Gets the target bean.BeanBuilder<T>
set(String propertyName, Object value)
Sets the value of a single property into the builder.BeanBuilder<T>
set(MetaProperty<?> metaProperty, Object value)
Sets the value of a single property into the builder.String
toString()
Returns a string that summarises the builder.protected void
validate(T bean)
Hook to allow a subclass to validate the bean.
-
-
-
Constructor Detail
-
BasicBeanBuilder
public BasicBeanBuilder(T bean)
Constructs the builder wrapping the target bean.- Parameters:
bean
- the target bean, not null
-
-
Method Detail
-
getTargetBean
protected T getTargetBean()
Gets the target bean.- Returns:
- the target bean, not null
-
get
public Object get(String propertyName)
Description copied from interface:BeanBuilder
Gets the value of a single property previously added to the builder.- Specified by:
get
in interfaceBeanBuilder<T extends Bean>
- Parameters:
propertyName
- the property name to query, not null- Returns:
- the previously set value, null if none
-
get
public <P> P get(MetaProperty<P> metaProperty)
Description copied from interface:BeanBuilder
Gets the value of a single property previously added to the builder.- Specified by:
get
in interfaceBeanBuilder<T extends Bean>
- Type Parameters:
P
- the type of the property.- Parameters:
metaProperty
- the meta-property to query, not null- Returns:
- the previously set value, null if none
-
set
public BeanBuilder<T> set(String propertyName, Object value)
Description copied from interface:BeanBuilder
Sets the value of a single property into the builder.This will normally behave as per a
Map
, however it may not and as a general rule callers should only set each property once.- Specified by:
set
in interfaceBeanBuilder<T extends Bean>
- Parameters:
propertyName
- the property name to set, not nullvalue
- the property value, may be null- Returns:
this
, for chaining, not null
-
set
public BeanBuilder<T> set(MetaProperty<?> metaProperty, Object value)
Description copied from interface:BeanBuilder
Sets the value of a single property into the builder.This will normally behave as per a
Map
, however it may not and as a general rule callers should only set each property once.- Specified by:
set
in interfaceBeanBuilder<T extends Bean>
- Parameters:
metaProperty
- the meta-property to set, not nullvalue
- the property value, may be null- Returns:
this
, for chaining, not null
-
build
public T build()
Description copied from interface:BeanBuilder
Builds the bean from the state of the builder.Once this method has been called, the builder is in an invalid state. The effect of further method calls is undetermined.
- Specified by:
build
in interfaceBeanBuilder<T extends Bean>
- Returns:
- the created bean, not null
-
validate
protected void validate(T bean)
Hook to allow a subclass to validate the bean.- Parameters:
bean
- the bean to validate, not null
-
-