-
- All Superinterfaces:
io.github.mmm.property.AttributeReadOnly,io.github.mmm.marshall.MarshallableObject,io.github.mmm.marshall.Marshaller<Object>,io.github.mmm.value.ReadablePath,io.github.mmm.validation.Validatable,io.github.mmm.value.WritablePath
- All Known Subinterfaces:
VirtualBean,WritableBean
- All Known Implementing Classes:
AbstractBean,AbstractVirtualBean,AdvancedBean,Bean,DynamicBean
public interface ReadableBean extends io.github.mmm.validation.Validatable, io.github.mmm.marshall.MarshallableObject, io.github.mmm.property.AttributeReadOnly, io.github.mmm.value.WritablePathRead interface of aBeanholding arbitraryproperties. 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.
-
-
Field Summary
Fields Modifier and Type Field Description static StringPROPERTY_TYPEstatic StringSUFFIX_PROPERTYThe optional suffix for a property method (when following JavaFx conventions what is not recommended by mmm-bean).
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description WritableBeancopy(boolean readOnly)static <B extends ReadableBean>
Bcopy(B bean, boolean readOnly)static <B extends ReadableBean>
BcopyReadOnly(B bean)default Objectget(String name)Collection<? extends io.github.mmm.property.ReadableProperty<?>>getProperties()io.github.mmm.property.ReadableProperty<?>getProperty(String name)intgetPropertyCount()default StringgetPropertyNameForAlias(String alias)An alias is an alternative for apropertyname.default io.github.mmm.property.ReadableProperty<?>getRequiredProperty(String name)BeanTypegetType()booleanisDynamic()default booleanisEqualTo(ReadableBean other)ABeanimplementation shall not overrideObject.equals(Object)andObject.hashCode()for efficient usage inCollections andMaps.default booleanisPolymorphic()ABeanmay be polymorphic to allow mappings to and from other representations without knowing the exact type.booleanisPrototype()WritableBeannewInstance()static <B extends ReadableBean>
BnewInstance(B bean)Stringpath()default io.github.mmm.validation.ValidationResultvalidate()default voidwrite(io.github.mmm.marshall.StructuredWriter writer)
-
-
-
Field Detail
-
SUFFIX_PROPERTY
static final String SUFFIX_PROPERTY
The optional suffix for a property method (when following JavaFx conventions what is not recommended by mmm-bean).- See Also:
- Constant Field Values
-
PROPERTY_TYPE
static final String PROPERTY_TYPE
-
-
Method Detail
-
getProperty
io.github.mmm.property.ReadableProperty<?> getProperty(String name)
- 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)
-
getProperties
Collection<? extends io.github.mmm.property.ReadableProperty<?>> getProperties()
- Returns:
- a
Collectionwith allpropertiesof this bean.
-
getPropertyCount
int getPropertyCount()
- Returns:
- the number of
propertiesof thisReadableBean.
-
getRequiredProperty
default io.github.mmm.property.ReadableProperty<?> getRequiredProperty(String name)
- Parameters:
name- thenameof the requested property.- Returns:
- the requested
property. - Throws:
RuntimeException- if the requested property does not exist.
-
get
default Object get(String name)
- Parameters:
name- theproperty name.- Returns:
- the
valueof theproperty with the given name. Will benullif no such property exists or theproperty valueisnull.
-
getPropertyNameForAlias
default String getPropertyNameForAlias(String alias)
An alias is an alternative for apropertyname. It allows to support a property under a legacy name after it has been renamed as well as to use a technical name containing special characters (e.g. "@" or ".") for very specific cases.- Parameters:
alias- the alias name.- Returns:
- the resolved
property nameornullif no such alias is defined.
-
getType
BeanType getType()
- Returns:
- the
BeanTypereflecting thisBean. - See Also:
VirtualBean.getType(),BeanClass
-
isDynamic
boolean isDynamic()
- Returns:
trueif thisBeanis dynamic meaning that is not strictly typed but allows to dynamically add properties,falseotherwise.- See Also:
VirtualBean
-
isPrototype
boolean isPrototype()
- Returns:
trueif thisBeanis aBeanClass,falseotherwise (it is a regular instance).- See Also:
BeanClass.getPrototype()
-
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.
-
path
String path()
- Specified by:
pathin interfaceio.github.mmm.value.ReadablePath- Returns:
- the path of this bean. It will be appended as prefix to the
path()of allproperties. This is useful for criteria API to build queries. So e.g. set to "e." if this bean should have the query alias "e".
-
validate
default io.github.mmm.validation.ValidationResult validate()
- Specified by:
validatein interfaceio.github.mmm.validation.Validatable
-
isEqualTo
default boolean isEqualTo(ReadableBean other)
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.
-
write
default void write(io.github.mmm.marshall.StructuredWriter writer)
- Specified by:
writein interfaceio.github.mmm.marshall.MarshallableObject
-
copy
WritableBean copy(boolean readOnly)
- 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.
-
newInstance
static <B extends ReadableBean> B newInstance(B bean)
- Type Parameters:
B- type of theWritableBean.- Parameters:
bean- theWritableBeanto create anew instanceof.- Returns:
- the
new instance.
-
copy
static <B extends ReadableBean> B copy(B bean, boolean readOnly)
- Type Parameters:
B- type of theWritableBean.- Parameters:
bean- theWritableBeantocopy.readOnly- -trueif the copy shall beread-only.- Returns:
- the
copy.
-
copyReadOnly
static <B extends ReadableBean> B copyReadOnly(B bean)
- Type Parameters:
B- type of theWritableBean.- Parameters:
bean- theWritableBeantocopy.- Returns:
- the
read-onlycopy.
-
-