- 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 DefaultPropertyBuildersadd()protected <V,P extends WritableProperty<V>>
Padd(P property)Internal method foraddProperty(WritableProperty), without verification.<P extends WritableProperty<?>>
PaddProperty(P property)Adds the givenWritablePropertyto this bean.WritableBeancopy(boolean isReadOnly)protected AbstractBeancreate()Creates a new instance of thisBeanimplementation.<V> WritableProperty<V>createProperty(String name, Class<V> valueClass, Type valueType)protected PropertyBuilderscreatePropertyBuilders()Internal method that may be overridden to replace thePropertyBuildersimplementation.Iterable<? extends WritableProperty<?>>getProperties()WritableProperty<?>getProperty(String name)intgetPropertyCount()booleanisDynamic()booleanisReadOnly()protected booleanisThreadSafe()AbstractBeannewInstance()protected voidonPropertyAdded(WritableProperty<?> property)protected voidrequireDynamic()protected voidrequireWritable()StringtoString()voidtoString(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:
trueif theBeanshall be thread-safe (use concurrent collections, etc.),falseotherwise.
-
isDynamic
public boolean isDynamic()
- Specified by:
isDynamicin interfaceReadableBean- Returns:
trueif thisBeanis dynamic meaning that is not strictly typed but allows to dynamically add properties,falseotherwise.- See Also:
VirtualBean
-
requireWritable
protected void requireWritable()
-
requireDynamic
protected void requireDynamic()
-
newInstance
public AbstractBean newInstance()
- Specified by:
newInstancein interfaceReadableBean- Returns:
- a new instance of this
WritableBean.
-
copy
public WritableBean copy(boolean isReadOnly)
- Specified by:
copyin interfaceReadableBean- Parameters:
isReadOnly- -trueif the copy shall beread-only.- Returns:
- a
copyof thisWritableBean. IfreadOnlyistrueand this bean is alreadyread-only, the same instance will be returned.
-
isReadOnly
public final boolean isReadOnly()
- Specified by:
isReadOnlyin interfaceReadableBean- Returns:
trueif thisBeanis read-only (immutable),falseotherwise.
-
create
protected AbstractBean create()
Creates a new instance of thisBeanimplementation. 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
Beaninstance. Has to be of the same type as thecurrent class.
-
getProperties
public Iterable<? extends WritableProperty<?>> getProperties()
- Specified by:
getPropertiesin interfaceReadableBean- Specified by:
getPropertiesin interfaceWritableBean- Returns:
- an
Iterableof all properties of this bean.
-
getProperty
public WritableProperty<?> getProperty(String name)
- Specified by:
getPropertyin interfaceReadableBean- Specified by:
getPropertyin interfaceWritableBean- Parameters:
name- thenameof the requested property or a potentialaliasof the property.- Returns:
- the requested
WritablePropertyornullif no such property exists. - See Also:
WritableBean.addProperty(WritableProperty),WritableBean.getOrCreateProperty(String, Class)
-
getPropertyCount
public int getPropertyCount()
- Specified by:
getPropertyCountin interfaceReadableBean- Returns:
- the number of
propertiesof thisReadableBean.
-
createProperty
public <V> WritableProperty<V> createProperty(String name, Class<V> valueClass, Type valueType)
Description copied from interface:WritableBean- Specified by:
createPropertyin interfaceWritableBean- Type Parameters:
V- the generic type of thevalue class.- Parameters:
name- theproperty name.valueClass- thevalue class.valueType- theTypereflecting theproperty value.- Returns:
- the newly created and added property.
-
addProperty
public <P extends WritableProperty<?>> P addProperty(P property)
Description copied from interface:WritableBeanAdds the givenWritablePropertyto this bean.- Specified by:
addPropertyin interfaceWritableBean- Type Parameters:
P- type of theWritablePropertyto add.- Parameters:
property- theWritablePropertyto 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 theWritablePropertyto add.- Parameters:
property- theWritablePropertyto 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 thePropertyBuildersimplementation.- Returns:
- the
PropertyBuildersinstance.
-
onPropertyAdded
protected void onPropertyAdded(WritableProperty<?> property)
- Parameters:
property- theWritablePropertythat has been added.
-
toString
public void toString(StringBuilder sb)
- Parameters:
sb- theStringBuilderwhere to append the details (the properties) of thisBeanfortoString()-Representation.
-
-