Class AbstractBean

java.lang.Object
io.github.mmm.bean.AbstractBean
All Implemented Interfaces:
ReadableBean, WritableBean, 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

public abstract class AbstractBean extends Object implements WritableBean
Abstract base implementation of WritableBean.
See Also:
  • Constructor Details

    • AbstractBean

      public AbstractBean()
      The constructor.
  • Method Details

    • pathSegment

      public String pathSegment()
      Specified by:
      pathSegment in interface io.github.mmm.value.ReadablePath
      Specified by:
      pathSegment in interface WritableBean
      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

      public void pathSegment(String path)
      Description copied from interface: WritableBean
      Used to set an alias as described in WritableBean.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 WritableBean
      Specified by:
      pathSegment in interface io.github.mmm.value.WritablePath
    • parentPath

      public io.github.mmm.value.ReadablePath parentPath()
      Specified by:
      parentPath in interface io.github.mmm.value.ReadablePath
    • parentPath

      public void parentPath(io.github.mmm.value.ReadablePath parent)
      Specified by:
      parentPath in interface io.github.mmm.value.WritablePath
    • isThreadSafe

      protected boolean isThreadSafe()
      Returns:
      true if the Bean shall be thread-safe (use concurrent collections, etc.), false otherwise.
    • isDynamic

      public boolean isDynamic()
      Specified by:
      isDynamic in interface ReadableBean
      Returns:
      true if this Bean is dynamic meaning that is not strictly typed but allows to dynamically add properties, false otherwise.
      See Also:
    • requireWritable

      protected void requireWritable()
      Verifies that this Bean is writable (not read-only).
    • requireDynamic

      protected void requireDynamic()
      Verifies that this Bean is dynamic (extensible).
    • newInstance

      public AbstractBean newInstance()
      Specified by:
      newInstance in interface ReadableBean
      Returns:
      a new instance of this WritableBean.
    • copy

      public WritableBean copy(boolean isReadOnly)
      Specified by:
      copy in interface ReadableBean
      Parameters:
      isReadOnly - - true if the copy shall be read-only.
      Returns:
      a copy of this WritableBean that has the same values for all properties.
    • isReadOnly

      public final boolean isReadOnly()
      Specified by:
      isReadOnly in interface AttributeReadOnly
    • create

      protected AbstractBean create()
      Creates a new instance of this Bean implementation. 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.
      Returns:
      the new Bean instance. Has to be of the same type as the current class.
    • getProperties

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

      public WritableProperty<?> getProperty(String name)
      Specified by:
      getProperty in interface ReadableBean
      Specified by:
      getProperty in interface WritableBean
      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:
    • getPropertyCount

      public int getPropertyCount()
      Specified by:
      getPropertyCount in interface ReadableBean
      Returns:
      the number of properties of this ReadableBean.
    • createProperty

      public <V> WritableProperty<V> createProperty(String name, Class<V> valueClass, Type valueType)
      Description copied from interface: WritableBean
      Creates and adds a WritableProperty with the given value class dynamically.
      Specified by:
      createProperty in interface WritableBean
      Type Parameters:
      V - the generic type of the value class.
      Parameters:
      name - the property name.
      valueClass - the value class.
      valueType - the Type reflecting the property value.
      Returns:
      the newly created and added property.
    • addProperty

      public <P extends WritableProperty<?>> P addProperty(P property)
      Description copied from interface: WritableBean
      Adds the given WritableProperty to this bean.
      Specified by:
      addProperty in interface WritableBean
      Type Parameters:
      P - type of the WritableProperty to add.
      Parameters:
      property - the WritableProperty to add.
      Returns:
      the given property.
    • add

      protected <V, P extends WritableProperty<V>> P add(P property)
      Internal method for addProperty(WritableProperty), without verification. Will be called from constructor of bean class implementations to register properties.
      Type Parameters:
      V - type of the property value.
      P - type of the WritableProperty to add.
      Parameters:
      property - the WritableProperty to add.
      Returns:
      the given property.
    • isLockOwnerInternal

      protected boolean isLockOwnerInternal(AttributeReadOnly lock)
      Parameters:
      lock - the lock to check.
      Returns:
      true if this bean is the lock owner, false otherwise.
    • add

      protected PropertyBuilders add()
      Returns:
      the builder factory to build properties to be added to this bean.
    • createPropertyBuilders

      protected StandardPropertyBuilders createPropertyBuilders()
      Internal method that may be overridden to replace the StandardPropertyBuilders implementation.
      Returns:
      the StandardPropertyBuilders instance.
    • onPropertyAdded

      protected void onPropertyAdded(WritableProperty<?> property)
      Parameters:
      property - the WritableProperty that has been added.
    • write

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

      public String toString()
      Overrides:
      toString in class Object