Interface WritableBean

All Superinterfaces:
AttributeReadOnly, io.github.mmm.marshall.MarshallableObject, io.github.mmm.marshall.Marshaller<Object>, io.github.mmm.marshall.Marshalling<Object>, io.github.mmm.marshall.MarshallingObject, ReadableBean, io.github.mmm.value.ReadablePath, io.github.mmm.marshall.id.StructuredIdMappingObject, io.github.mmm.marshall.UnmarshallableObject, io.github.mmm.marshall.Unmarshaller<Object>, io.github.mmm.validation.Validatable, io.github.mmm.value.WritablePath
All Known Subinterfaces:
VirtualBean
All Known Implementing Classes:
AbstractBean, AbstractVirtualBean, AdvancedBean, Bean, BeanAccessor, DynamicBean

@AbstractInterface public interface WritableBean extends ReadableBean, io.github.mmm.value.WritablePath, io.github.mmm.marshall.MarshallingObject, io.github.mmm.marshall.id.StructuredIdMappingObject
Writable interface of ReadableBean.
  • Method Details

    • getProperty

      WritableProperty<?> getProperty(String name)
      Specified by:
      getProperty in interface ReadableBean
      Parameters:
      name - the name of the requested property or a potential alias of the property.
      Returns:
      the requested WritableProperty or null if no such property exists.
      See Also:
    • getProperties

      Collection<? extends WritableProperty<?>> getProperties()
      Specified by:
      getProperties in interface ReadableBean
      Returns:
      a Collection with all properties of this bean.
    • getRequiredProperty

      default WritableProperty<?> getRequiredProperty(String name)
      Specified by:
      getRequiredProperty in interface ReadableBean
      Parameters:
      name - the name of the requested property.
      Returns:
      the requested property.
    • set

      default void set(String name, Object value)
      Sets the value of the required property with the given name to the given value.
      Parameters:
      name - the name of the property.
      value - new value of the specified property.
    • setDynamic

      default void setDynamic(String name, Object value)
      Sets the value of the property with the given name to the given value. If no such property exists, it will be created dynamically if the given value is not null.
      Parameters:
      name - the name of the property.
      value - new value of the specified property.
    • set

      default <V> void set(String name, V value, Class<V> valueClass)
      /** Sets the value of the existing or newly created property with the given name to the given value.
      Type Parameters:
      V - the generic type of the value class.
      Parameters:
      name - the property name.
      value - new value of the specified property.
      valueClass - the value class.
      See Also:
    • addProperty

      <P extends WritableProperty<?>> P addProperty(P property)
      Adds the given WritableProperty to this bean.
      Type Parameters:
      P - type of the WritableProperty to add.
      Parameters:
      property - the WritableProperty to add.
      Returns:
      the given property.
      Throws:
      IllegalStateException - if this WritableBean is read-only or not dynamic.
    • createProperty

      <V> WritableProperty<V> createProperty(String name, Class<V> valueClass)
      Creates and adds a WritableProperty with the given value class dynamically.
      Type Parameters:
      V - the generic type of the value class.
      Parameters:
      name - the property name.
      valueClass - the value class.
      Returns:
      the newly created and added property.
      Throws:
      IllegalStateException - if this WritableBean already has such property, is read-only, or not dynamic.
    • getOrCreateProperty

      default <V> WritableProperty<V> getOrCreateProperty(String name, Class<V> valueClass)
      Gets or creates the specified property dynamically.
      Type Parameters:
      V - the generic type of the property value.
      Parameters:
      name - the property name.
      valueClass - the value class of the requested property.
      Returns:
      the requested property. Will be created if it does not already exist.
      Throws:
      IllegalArgumentException - if the requested property already exists but has an incompatible value class.
      IllegalStateException - if the requested property does not exist but this WritableBean is read-only, or not dynamic.
    • getType

      BeanType getType()
      Specified by:
      getType in interface ReadableBean
      Returns:
      the BeanType reflecting this Bean.
      See Also:
    • read

      default WritableBean read(io.github.mmm.marshall.StructuredReader reader)
      Specified by:
      read in interface io.github.mmm.marshall.UnmarshallableObject
    • write

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

      default io.github.mmm.marshall.id.StructuredIdMapping defineIdMapping()
      Specified by:
      defineIdMapping in interface io.github.mmm.marshall.id.StructuredIdMappingObject
    • asTypeKey

      default Object asTypeKey()
      Specified by:
      asTypeKey in interface io.github.mmm.marshall.id.StructuredIdMappingObject
    • pathSegment

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

      void pathSegment(String pathSegment)
      Used to set an alias as described in pathSegment(). ATTENTION: End users should never use this method directly but use designated methods such as as(String alias) provided by according SQL clauses.
      Specified by:
      pathSegment in interface io.github.mmm.value.WritablePath
    • from

      static <B extends WritableBean> B from(WritableProperty<?> property)
      Type Parameters:
      B - type of the WritableBean owning the property.
      Parameters:
      property - the WritableProperty for which the owning WritableBean is requested.
      Returns:
      the WritableBean owning the given property. Will be null if the WritableProperty is manually created from outside a bean.
    • readArray

      static <B extends WritableBean> List<B> readArray(B template, io.github.mmm.marshall.StructuredReader reader)
      Type Parameters:
      B - type of the WritableBean to read.
      Parameters:
      template - an instance of the WritableBean to read acting as template.
      reader - the StructuredReader to read the data from.
      Returns:
      the List with the the unmarshalled beans.
    • readArray

      static <B extends WritableBean> void readArray(B template, io.github.mmm.marshall.StructuredReader reader, Collection<B> collection)
      Type Parameters:
      B - type of the WritableBean to read.
      Parameters:
      template - an instance of the WritableBean to read acting as template.
      reader - the StructuredReader to read the data from.
      collection - the Collection where to add the unmarshalled beans.
    • writeArray

      static <B extends WritableBean> void writeArray(Collection<B> beans, io.github.mmm.marshall.StructuredWriter writer)
      Type Parameters:
      B - type of the WritableBean to write.
      Parameters:
      beans - the Collection with the beans to write.
      writer - the StructuredWriter to write to.