java.lang.Object
io.github.mmm.bean.AbstractBean
- All Implemented Interfaces:
ReadableBean,WritableBean,io.github.mmm.marshall.id.StructuredIdMappingObject,io.github.mmm.marshall.MarshallableObject,io.github.mmm.marshall.Marshaller<Object>,io.github.mmm.marshall.Marshalling<Object>,io.github.mmm.marshall.MarshallingObject,io.github.mmm.marshall.UnmarshallableObject,io.github.mmm.marshall.Unmarshaller<Object>,AttributeReadOnly,io.github.mmm.validation.Validatable,io.github.mmm.value.ReadablePath,io.github.mmm.value.WritablePath
- Direct Known Subclasses:
AbstractVirtualBean,Bean,BeanAccessor
Abstract base implementation of
ATTENTION:
If you plan to implement beans as Java class instead of using interfaces, you always need to have a public constructor with
WritableBean.ATTENTION:
If you plan to implement beans as Java class instead of using interfaces, you always need to have a public constructor with
WritableBean as a single argument. Otherwise read-only support can
not work.- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from interface io.github.mmm.value.ReadablePath
io.github.mmm.value.ReadablePath.PathBuilder -
Field Summary
Fields inherited from interface io.github.mmm.bean.ReadableBean
SUFFIX_PROPERTY -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected PropertyBuildersadd()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.copy()protected AbstractBeancreate(WritableBean writable) Creates a new instance of thisBeanimplementation.<V> WritableProperty<V> createProperty(String name, Class<V> valueClass) protected StandardPropertyBuildersInternal method that may be overridden to replace theStandardPropertyBuildersimplementation.Collection<? extends WritableProperty<?>> getProperty(String name) intfinal AbstractBeanbooleanprotected booleanfinal booleanprotected booleanprotected static booleanisThreadSafe(AbstractBean bean) Internal method to get access toisThreadSafe().protected voidonPropertyAdded(WritableProperty<?> property) io.github.mmm.value.ReadablePathvoidparentPath(io.github.mmm.value.ReadablePath parent) path(boolean fixed) voidpathSegment(String path) Used to set an alias as described inWritableBean.pathSegment().protected voidregisterAlias(String propertyName, String alias) protected voidregisterAliases(String propertyName, String... propertyAliases) protected voidprotected voidtoString()Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface io.github.mmm.marshall.MarshallableObject
writeObjectMethods inherited from interface io.github.mmm.bean.ReadableBean
doEquals, doToString, get, getJavaClass, isEqual, isPolymorphic, isPrototype, mapPropertyIds, toString, validateMethods inherited from interface io.github.mmm.value.ReadablePath
path, pathMethods inherited from interface io.github.mmm.marshall.UnmarshallableObject
readObjectMethods inherited from interface io.github.mmm.validation.Validatable
validateOrThrowMethods inherited from interface io.github.mmm.bean.WritableBean
asTypeKey, defineIdMapping, getOrCreateProperty, getRequiredProperty, getType, read, set, set, setDynamic, write
-
Constructor Details
-
AbstractBean
The constructor.- Parameters:
writable- theWritableBeanto wrap asread-onlybean ornullto create a mutable bean.
-
-
Method Details
-
pathSegment
- Specified by:
pathSegmentin interfaceio.github.mmm.value.ReadablePath- Specified by:
pathSegmentin interfaceWritableBean- Returns:
- the optional alias of this bean. It will be appended as prefix to the
ReadablePath.path()of allproperties. This is useful for API to build queries. So e.g. set to "alias" and your contained property will have the path "alias.MyProperty".
-
pathSegment
Description copied from interface:WritableBeanUsed to set an alias as described inWritableBean.pathSegment(). ATTENTION: End users should never use this method directly but use designated methods such asas(String alias)provided by according SQL clauses.- Specified by:
pathSegmentin interfaceWritableBean- Specified by:
pathSegmentin interfaceio.github.mmm.value.WritablePath
-
parentPath
public io.github.mmm.value.ReadablePath parentPath()- Specified by:
parentPathin interfaceio.github.mmm.value.ReadablePath
-
parentPath
public void parentPath(io.github.mmm.value.ReadablePath parent) - Specified by:
parentPathin interfaceio.github.mmm.value.WritablePath
-
path
- Specified by:
pathin interfaceio.github.mmm.value.ReadablePath
-
isThreadSafe
protected boolean isThreadSafe()- Returns:
trueif theBeanwill be access concurrently and is required to be thread-safe (use concurrent collections, etc.),falseotherwise. Please note we strongly encourage you not useBeans concurrently and overriding this method to returntrue. We also will not thoroughly test such concurrency and just support it as best-guess implementation since it is relatively easy for us but rather impossible to solve from the outside. So in case you are blocked by a concurrency issue that you do not want to solve otherwise, you may consider overriding this method to returntruefor your beans. Please also be warned that this causes quite some overhead and will reduce performance.
-
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:
-
requireWritable
protected void requireWritable() -
requireDynamic
protected void requireDynamic() -
getReadOnly
- Specified by:
getReadOnlyin interfaceWritableBean- Returns:
- the
read onlyview on thisbean. - See Also:
-
newInstance
- Specified by:
newInstancein interfaceReadableBean- Returns:
- a new instance of this
WritableBean.
-
copy
- Specified by:
copyin interfaceReadableBean- Returns:
- a copy of this
WritableBeanthat has the same values for allproperties.
-
isReadOnly
public final boolean isReadOnly()- Specified by:
isReadOnlyin interfaceAttributeReadOnly
-
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.- Parameters:
writable- theAdvancedBeanto wrap asread-onlybean ornullto create a mutable bean.- Returns:
- the new
Beaninstance. Has to be of the same type as thecurrent class.
-
getProperties
- Specified by:
getPropertiesin interfaceReadableBean- Specified by:
getPropertiesin interfaceWritableBean- Returns:
- a
Collectionwith allpropertiesof this bean.
-
getProperty
- 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:
-
getPropertyCount
public int getPropertyCount()- Specified by:
getPropertyCountin interfaceReadableBean- Returns:
- the number of
propertiesof thisReadableBean.
-
createProperty
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.- Returns:
- the newly created and added property.
-
addProperty
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
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.
-
isLockOwnerInternal
- Parameters:
lock- thelockto check.- Returns:
trueif this bean is the lock owner,falseotherwise.
-
add
- Returns:
- the builder factory to build properties to be added to this bean.
-
createPropertyBuilders
Internal method that may be overridden to replace theStandardPropertyBuildersimplementation.- Returns:
- the
StandardPropertyBuildersinstance.
-
onPropertyAdded
- Parameters:
property- theWritablePropertythat has been added.
-
registerAlias
- Parameters:
propertyName- theproperty name.alias- thealiasto add.
-
registerAliases
- Parameters:
propertyName- theproperty name.propertyAliases- thealiasesto add.
-
getAliases
- Specified by:
getAliasesin interfaceReadableBean- Returns:
- the
BeanAliasMapwith potential aliases forpropertynames.
-
toString
-
isThreadSafe
Internal method to get access toisThreadSafe().- Parameters:
bean- theAbstractBean.- Returns:
- the value of
isThreadSafe().
-