Interface ReadableBean

  • 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.WritablePath
    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 dynamic beans. E.g. if read data from Database, XML, or JSON you can still map "undefined" properties in your Bean. 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 the Bean is written back.
    • ReadOnly-Support - create a read-only copy of your object to pass by reference without side-effects.
    • Powerful - WritableProperty supports listeners and bindings as well as generic type information.
    • Validation - build-in validation support.
    • Marshalling - build-in support to read and write the Bean from/to JSON, XML, or other formats. Implement custom datatypes as property and 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.
    • Method Detail

      • getProperties

        Collection<? extends io.github.mmm.property.ReadableProperty<?>> getProperties()
        Returns:
        a Collection with all properties of this bean.
      • getRequiredProperty

        default io.github.mmm.property.ReadableProperty<?> getRequiredProperty​(String name)
        Parameters:
        name - the name of the requested property.
        Returns:
        the requested property.
        Throws:
        RuntimeException - if the requested property does not exist.
      • get

        default Object get​(String name)
        Parameters:
        name - the property name.
        Returns:
        the value of the property with the given name. Will be null if no such property exists or the property value is null.
      • getPropertyNameForAlias

        default String getPropertyNameForAlias​(String alias)
        An alias is an alternative for a property name. 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 name or null if no such alias is defined.
      • isDynamic

        boolean isDynamic()
        Returns:
        true if this Bean is dynamic meaning that is not strictly typed but allows to dynamically add properties, false otherwise.
        See Also:
        VirtualBean
      • isPolymorphic

        default boolean isPolymorphic()
        A Bean may be polymorphic to allow mappings to and from other representations without knowing the exact type. So assuming a service accepts or returns a Bean of a specific type that has sub-types. If that type is declared as polymorphic then it is possible to unarshall the Bean of the exact sub-type back from its serialized data.
        By default a Bean is not polymorphic. Once you declare your custom Bean as polymorphic by overriding this method returning true, you may not this method it again. Hence, if you override this method in a class, you should declare it as final.
        Returns:
        true if this Bean is polymorphic meaning it represents an entire hierarchy of Bean types, false otherwise.
      • path

        String path()
        Specified by:
        path in interface io.github.mmm.value.ReadablePath
        Returns:
        the path of this bean. It will be appended as prefix to the path() of all properties. 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:
        validate in interface io.github.mmm.validation.Validatable
      • write

        default void write​(io.github.mmm.marshall.StructuredWriter writer)
        Specified by:
        write in interface io.github.mmm.marshall.MarshallableObject
      • copy

        WritableBean copy​(boolean readOnly)
        Parameters:
        readOnly - - true if the copy shall be read-only.
        Returns:
        a copy of this WritableBean that has the same values for all properties.
      • copy

        static <B extends ReadableBean> B copy​(B bean,
                                               boolean readOnly)
        Type Parameters:
        B - type of the WritableBean.
        Parameters:
        bean - the WritableBean to copy.
        readOnly - - true if the copy shall be read-only.
        Returns:
        the copy.