- java.lang.Object
-
- io.github.mmm.bean.AbstractBean
-
- All Implemented Interfaces:
ReadableBean
,WritableBean
,MarshallableObject
,Marshaller<Object>
,Marshalling<Object>
,MarshallingObject
,UnmarshallableObject
,Unmarshaller<Object>
,Validatable
- Direct Known Subclasses:
AbstractVirtualBean
,Bean
public abstract class AbstractBean extends Object implements WritableBean
Abstract base implementation ofWritableBean
.- See Also:
Bean
-
-
Field Summary
-
Fields inherited from interface io.github.mmm.bean.ReadableBean
PROPERTY_TYPE
-
-
Constructor Summary
Constructors Constructor Description AbstractBean()
The constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected DefaultPropertyBuilders
add()
protected <V,P extends WritableProperty<V>>
Padd(P property)
Internal method foraddProperty(WritableProperty)
, without verification.<P extends WritableProperty<?>>
PaddProperty(P property)
Adds the givenWritableProperty
to this bean.WritableBean
copy(boolean isReadOnly)
protected AbstractBean
create()
Creates a new instance of thisBean
implementation.<V> WritableProperty<V>
createProperty(String name, Class<V> valueClass, Type valueType)
protected PropertyBuilders
createPropertyBuilders()
Internal method that may be overridden to replace thePropertyBuilders
implementation.Iterable<? extends WritableProperty<?>>
getProperties()
WritableProperty<?>
getProperty(String name)
int
getPropertyCount()
boolean
isDynamic()
boolean
isReadOnly()
protected boolean
isThreadSafe()
AbstractBean
newInstance()
protected void
onPropertyAdded(WritableProperty<?> property)
protected void
requireDynamic()
protected void
requireWritable()
String
toString()
void
toString(StringBuilder sb)
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface io.github.mmm.marshall.MarshallableObject
writeObject
-
Methods inherited from interface io.github.mmm.bean.ReadableBean
copy, get, getPropertyNameForAlias, getType, isEqualTo, isPolymorphic, isPrototype, validate, write
-
Methods inherited from interface io.github.mmm.marshall.UnmarshallableObject
readObject
-
Methods inherited from interface io.github.mmm.bean.WritableBean
createProperty, getOrCreateProperty, getOrCreateProperty, getRequiredProperty, read, set, set, set
-
-
-
-
Method Detail
-
isThreadSafe
protected boolean isThreadSafe()
- Returns:
true
if theBean
shall be thread-safe (use concurrent collections, etc.),false
otherwise.
-
isDynamic
public boolean isDynamic()
- Specified by:
isDynamic
in interfaceReadableBean
- Returns:
true
if thisBean
is dynamic meaning that is not strictly typed but allows to dynamically add properties,false
otherwise.- See Also:
VirtualBean
-
requireWritable
protected void requireWritable()
-
requireDynamic
protected void requireDynamic()
-
newInstance
public AbstractBean newInstance()
- Specified by:
newInstance
in interfaceReadableBean
- Returns:
- a new instance of this
WritableBean
.
-
copy
public WritableBean copy(boolean isReadOnly)
- Specified by:
copy
in interfaceReadableBean
- Parameters:
isReadOnly
- -true
if the copy shall beread-only
.- Returns:
- a
copy
of thisWritableBean
. IfreadOnly
istrue
and this bean is alreadyread-only
, the same instance will be returned.
-
isReadOnly
public final boolean isReadOnly()
- Specified by:
isReadOnly
in interfaceReadableBean
- Returns:
true
if thisBean
is read-only (immutable),false
otherwise.
-
create
protected AbstractBean create()
Creates a new instance of thisBean
implementation. The default implementation uses reflection. To improve performance please override this method. Please note, that if you do so, you also need to override this method again for all sub-classes of the hierarchy.- Returns:
- the new
Bean
instance. Has to be of the same type as thecurrent class
.
-
getProperties
public Iterable<? extends WritableProperty<?>> getProperties()
- Specified by:
getProperties
in interfaceReadableBean
- Specified by:
getProperties
in interfaceWritableBean
- Returns:
- an
Iterable
of all properties of this bean.
-
getProperty
public WritableProperty<?> getProperty(String name)
- Specified by:
getProperty
in interfaceReadableBean
- Specified by:
getProperty
in interfaceWritableBean
- Parameters:
name
- thename
of the requested property or a potentialalias
of the property.- Returns:
- the requested
WritableProperty
ornull
if no such property exists. - See Also:
WritableBean.addProperty(WritableProperty)
,WritableBean.getOrCreateProperty(String, Class)
-
getPropertyCount
public int getPropertyCount()
- Specified by:
getPropertyCount
in interfaceReadableBean
- Returns:
- the number of
properties
of thisReadableBean
.
-
createProperty
public <V> WritableProperty<V> createProperty(String name, Class<V> valueClass, Type valueType)
Description copied from interface:WritableBean
- Specified by:
createProperty
in interfaceWritableBean
- Type Parameters:
V
- the generic type of thevalue class
.- Parameters:
name
- theproperty name
.valueClass
- thevalue class
.valueType
- theType
reflecting theproperty value
.- Returns:
- the newly created and added property.
-
addProperty
public <P extends WritableProperty<?>> P addProperty(P property)
Description copied from interface:WritableBean
Adds the givenWritableProperty
to this bean.- Specified by:
addProperty
in interfaceWritableBean
- Type Parameters:
P
- type of theWritableProperty
to add.- Parameters:
property
- theWritableProperty
to add.- Returns:
- the given
property
.
-
add
protected <V,P extends WritableProperty<V>> P add(P property)
Internal method foraddProperty(WritableProperty)
, without verification. Will be called from constructor of bean class implementations to register properties.- Type Parameters:
V
- type of theproperty value
.P
- type of theWritableProperty
to add.- Parameters:
property
- theWritableProperty
to add.- Returns:
- the given
property
.
-
add
protected DefaultPropertyBuilders add()
- Returns:
- the builder factory to build properties to be added to this bean.
-
createPropertyBuilders
protected PropertyBuilders createPropertyBuilders()
Internal method that may be overridden to replace thePropertyBuilders
implementation.- Returns:
- the
PropertyBuilders
instance.
-
onPropertyAdded
protected void onPropertyAdded(WritableProperty<?> property)
- Parameters:
property
- theWritableProperty
that has been added.
-
toString
public void toString(StringBuilder sb)
- Parameters:
sb
- theStringBuilder
where to append the details (the properties) of thisBean
fortoString()
-Representation.
-
-