- All Superinterfaces:
AttributeReadOnly,io.github.mmm.marshall.MarshallableObject,io.github.mmm.marshall.Marshaller<Object>,io.github.mmm.value.ReadablePath,io.github.mmm.validation.Validatable
- All Known Subinterfaces:
VirtualBean,WritableBean
- All Known Implementing Classes:
AbstractBean,AbstractVirtualBean,AdvancedBean,Bean,BeanAccessor,DynamicBean
public interface ReadableBean
extends io.github.mmm.validation.Validatable, io.github.mmm.marshall.MarshallableObject, AttributeReadOnly, io.github.mmm.value.ReadablePath
Read interface of a
Bean holding arbitrary properties. Unlike plain old Java
Beans this offers a lot of advanced features:
- Simple - no need to write boiler-plate code for implementation such as getters, setters, equals, or hashCode.
- Generic - fast, easy and reliable introspection via
iteration of all properties. No more greedy and slow reflection at runtime (after bootstrapping). - Dynamic - supports combination of Java's strong typing with
dynamicbeans. E.g. if read data from Database, XML, or JSON you can still map "undefined" properties in yourBean. This way a client can receive an object from a newer version of a database or service with added properties that will be kept in the object and send back when theBeanis written back. - ReadOnly-Support - create a
read-onlycopyof your object to pass by reference without side-effects. - Powerful -
WritablePropertysupports listeners and bindings as well asgeneric type information. - Validation - build-in
validation support. - Marshalling - build-in support to
readandwritetheBeanfrom/to JSON, XML, or other formats. Implement custom datatypes aspropertyand you will not need separate classes or configurations for mapping. - Portable - everything relies only on established Java standard mechanisms. No customization of build processes, IDEs, etc. needed. It just works with any build tool (maven, gradle, buildr, ant, etc.) and IDE (Eclipse, IntelliJ, NetBeans, etc.) without plugins and therefore will also work in the future whatever may come.
-
Nested Class Summary
Nested classes/interfaces inherited from interface io.github.mmm.value.ReadablePath
io.github.mmm.value.ReadablePath.PathBuilder -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringThe optional suffix for a property method (when following JavaFx conventions what is not recommended by mmm-bean). -
Method Summary
Modifier and TypeMethodDescriptioncopy(boolean readOnly) static <B extends ReadableBean>
Bcopy(B bean) static <B extends ReadableBean>
Bcopy(B bean, boolean readOnly) static <B extends ReadableBean>
BcopyReadOnly(B bean) default booleandoEquals(ReadableBean other) Method to implementdirectly in a bean interface as default method.invalid reference
#equals(Object)default StringMethod to implementdirectly in a bean interface as default method.invalid reference
#toString()default <V> Vdefault Class<?> static <B extends ReadableBean>
Class<B> getJavaClass(B bean) Collection<? extends ReadableProperty<?>> getProperty(String name) intdefault ReadableProperty<?> getRequiredProperty(String name) getType()booleandefault booleanisEqual(ReadableBean other) ABeanimplementation shall not overrideObject.equals(Object)andObject.hashCode()for efficient usage inCollections andMaps.default booleanABeanmay be polymorphic to allow mappings to and from other representations without knowing the exact type.booleandefault voidmapPropertyIds(PropertyIdCollector mapping) Defines how thepropertiesof thisReadableBeanare mapped to numeric IDs.static <B extends ReadableBean>
BnewInstance(B bean) default voiddefault io.github.mmm.validation.ValidationResultvalidate()Methods inherited from interface io.github.mmm.property.AttributeReadOnly
isReadOnlyMethods inherited from interface io.github.mmm.marshall.MarshallableObject
write, writeObjectMethods inherited from interface io.github.mmm.value.ReadablePath
parentPath, path, path, path, pathSegmentMethods inherited from interface io.github.mmm.validation.Validatable
validateOrThrow
-
Field Details
-
SUFFIX_PROPERTY
The optional suffix for a property method (when following JavaFx conventions what is not recommended by mmm-bean).- See Also:
-
-
Method Details
-
getProperty
- Parameters:
name- thenameof the requested property or a potentialaliasof the property.- Returns:
- the requested
WritablePropertyornullif no such property exists. - See Also:
-
getProperties
Collection<? extends ReadableProperty<?>> getProperties()- Returns:
- a
Collectionwith allpropertiesof this bean.
-
getPropertyCount
int getPropertyCount()- Returns:
- the number of
propertiesof thisReadableBean.
-
getRequiredProperty
- Parameters:
name- thenameof the requested property.- Returns:
- the requested
property. - Throws:
RuntimeException- if the requested property does not exist.
-
get
- Type Parameters:
V- type of theproperty value.- Parameters:
name- theproperty name.- Returns:
- the
valueof theproperty with the given name. Will benullif no such property exists or theproperty valueisnull.
-
getAliases
BeanAliasMap getAliases()- Returns:
- the
BeanAliasMapwith potential aliases forpropertynames.
-
getType
BeanType getType() -
getJavaClass
- Returns:
- the
Classreflecting this bean. Please note thatVirtualBeans may implement multiple interfaces as a virtual type that does not physically exist as JavaClassand in such case the method will return the primary of theseClasses (interfaces).
-
isDynamic
boolean isDynamic()- Returns:
trueif thisBeanis dynamic meaning that is not strictly typed but allows to dynamically add properties,falseotherwise.- See Also:
-
isPrototype
boolean isPrototype() -
isPolymorphic
default boolean isPolymorphic()ABeanmay be polymorphic to allow mappings to and from other representations without knowing the exact type. So assuming a service accepts or returns aBeanof a specific type that has sub-types. If that type is declared as polymorphic then it is possible to unarshall theBeanof the exact sub-type back from its serialized data.
By default aBeanis not polymorphic. Once you declare your customBeanas polymorphic by overriding this method returningtrue, you may not this method it again. Hence, if you override this method in a class, you should declare it as final. -
validate
default io.github.mmm.validation.ValidationResult validate()- Specified by:
validatein interfaceio.github.mmm.validation.Validatable
-
isEqual
ABeanimplementation shall not overrideObject.equals(Object)andObject.hashCode()for efficient usage inCollections andMaps. Hence the regularequalsmethod will just check for object identity. For a logical equals check you may use this method. Be aware that is may be expensive as it recursively traverses into all properties that may again contain aReadableBean.- Parameters:
other- theReadableBeanto compare with.- Returns:
trueif thisReadableBeanis logically equal to the givenReadableBean, that is it has the same type and allpropertiesareequal,falseotherwise.
-
copy
- Parameters:
readOnly- -trueif the copy shall beread-only.- Returns:
- a copy of this
WritableBeanthat has the same values for allproperties.
-
newInstance
WritableBean newInstance()- Returns:
- a new instance of this
WritableBean.
-
mapPropertyIds
Defines how thepropertiesof thisReadableBeanare mapped to numeric IDs. This is only relevant in case you want to use binary protocols ProtoBuf/GRPC.- Parameters:
mapping- thePropertyIdCollectorused to receive the mapping.
-
doEquals
Method to implementdirectly in a bean interface as default method. For simplification it is only called if the object to compare to is notinvalid reference
#equals(Object)nulland has the sametypeso you do not have to handle these cases in your custom implementation.
ATTENTION: It is rather discouraged to override this method. Simply useisEqual(ReadableBean)instead ofwhen you want comparison by value (e.g. to check for duplicates).invalid reference
#equals(Object)- Parameters:
other- the object to compare to. Will not benulland has the sametypeas this bean.- Returns:
trueif this and the givenReadableBeanare considered equals,falseotherwise.- See Also:
-
doToString
Method to implementdirectly in a bean interface as default method.invalid reference
#toString()- Returns:
- the
string representation of this bean.
-
toString
- Parameters:
sb- theStringBuilderwhere to append the details (the properties) of thisBeanfor-Representation.invalid reference
#toString()
-
newInstance
- Type Parameters:
B- type of theWritableBean.- Parameters:
bean- theWritableBeanto create anew instanceof.- Returns:
- the
new instance.
-
copy
- Type Parameters:
B- type of theReadableBean.- Parameters:
bean- thebeantocopy.- Returns:
- the
copy.
-
copy
- Type Parameters:
B- type of theReadableBean.- Parameters:
bean- thebeantocopy.readOnly- -trueif the copy shall beread-only.- Returns:
- the
copy.
-
copyReadOnly
- Type Parameters:
B- type of theReadableBean.- Parameters:
bean- thebeantocopy.- Returns:
- the
read-onlycopy.
-
getJavaClass
- Type Parameters:
B- type of theReadableBean.- Parameters:
bean- thebeanto get the JavaClassfor.- Returns:
- the
Classreflecting the givenbean.
-