Class AbstractBean

java.lang.Object
rs.baselib.bean.AbstractBean
All Implemented Interfaces:
IBean, IPropertyChangeProvider, IDirtyable
Direct Known Subclasses:
Address

public abstract class AbstractBean
extends java.lang.Object
implements IBean
Abstract support for beans.
Author:
ralph
  • Field Summary

    Fields inherited from interface rs.baselib.util.IDirtyable

    DIRTY
  • Constructor Summary

    Constructors 
    Constructor Description
    AbstractBean()
    Constructor.
  • Method Summary

    Modifier and Type Method Description
    void addPropertyChangeListener​(java.beans.PropertyChangeListener listener)
    Add a change listener.
    void addPropertyChangeListener​(java.lang.String propertyName, java.beans.PropertyChangeListener listener)
    Add a change listener.
    void copyTo​(java.lang.Object destination)
    Copies all properties to the given object.
    protected boolean fireIndexedPropertyChange​(java.lang.String propertyName, int index, boolean oldValue, boolean newValue)
    Fires an indexed change event.
    protected boolean fireIndexedPropertyChange​(java.lang.String propertyName, int index, int oldValue, int newValue)
    Fires an indexed change event.
    protected boolean fireIndexedPropertyChange​(java.lang.String propertyName, int index, java.lang.Object oldValue, java.lang.Object newValue)
    Fires an indexed change event.
    protected boolean firePropertyChange​(java.beans.PropertyChangeEvent event)
    Fires a change event.
    protected boolean firePropertyChange​(java.beans.PropertyChangeEvent event, boolean makeDirty)
    Fires a change event.
    protected boolean firePropertyChange​(java.lang.String propertyName, boolean oldValue, boolean newValue)
    Fires an event if property changed.
    protected boolean firePropertyChange​(java.lang.String propertyName, boolean oldValue, boolean newValue, boolean makeDirty)
    Fires an event if property changed.
    boolean firePropertyChange​(java.lang.String propertyName, float oldValue, float newValue)
    Fires an event if property changed.
    boolean firePropertyChange​(java.lang.String propertyName, float oldValue, float newValue, boolean makeDirty)
    Fires an event if property changed.
    protected boolean firePropertyChange​(java.lang.String propertyName, int oldValue, int newValue)
    Fires an event if property changed.
    protected boolean firePropertyChange​(java.lang.String propertyName, int oldValue, int newValue, boolean makeDirty)
    Fires an event if property changed.
    protected boolean firePropertyChange​(java.lang.String propertyName, java.lang.Object oldValue, java.lang.Object newValue)
    Fires an event if property changed.
    protected boolean firePropertyChange​(java.lang.String propertyName, java.lang.Object oldValue, java.lang.Object newValue, boolean makeDirty)
    Fires an event if property changed.
    java.lang.Object get​(java.lang.String name)
    Gets the property with given name
    java.util.Collection<java.beans.PropertyChangeEvent> getChanges()
    Returns the list of changes that this bean has performed since loading.
    protected java.lang.Object getOriginalValue​(java.lang.String propertyName)
    Returns the original value.
    protected java.beans.PropertyChangeListener[] getPropertyChangeListeners()
    Returns all listeners.
    protected java.beans.PropertyChangeListener[] getPropertyChangeListeners​(java.lang.String propertyName)
    Returns change listeners on a specific property.
    java.lang.Iterable<java.lang.String> getPropertyNames()
    Returns the property names of this bean.
    protected boolean hasListeners​(java.lang.String propertyName)
    Returns true when the specified property has listeners attached.
    protected boolean isCopyAllowed​(java.beans.PropertyDescriptor descriptor)
    Returns true when copyTo(Object) is allowed to copy the given property.
    protected boolean isCopyAllowed​(java.lang.String name)
    Returns true when copyTo(Object) is allowed to copy the given property.
    boolean isDirty()
    Returns whether this object has changed.
    protected void registerChange​(java.lang.String propertyName, java.lang.Object oldValue, java.lang.Object newValue)
    Register the property change.
    void removePropertyChangeListener​(java.beans.PropertyChangeListener listener)
    Remove a change listener.
    void removePropertyChangeListener​(java.lang.String propertyName, java.beans.PropertyChangeListener listener)
    Remove a change listener.
    void reset()
    Reset all changes.
    void set​(java.lang.String name, java.lang.Object value)
    Set the property with given name to the value
    protected void setDirty​(boolean dirty)
    Sets the dirty flag.
    java.lang.String toString()

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details

  • Method Details

    • isDirty

      public boolean isDirty()
      Returns whether this object has changed.
      Specified by:
      isDirty in interface IDirtyable
      Returns:
      true or false
    • setDirty

      protected void setDirty​(boolean dirty)
      Sets the dirty flag.
      Parameters:
      dirty - true when bean shall be marked dirty. If the bean is marked as not dirty then all registered changes will be removed.
    • addPropertyChangeListener

      public void addPropertyChangeListener​(java.beans.PropertyChangeListener listener)
      Add a change listener.
      Specified by:
      addPropertyChangeListener in interface IPropertyChangeProvider
      Parameters:
      listener - the listener to be added
    • removePropertyChangeListener

      public void removePropertyChangeListener​(java.beans.PropertyChangeListener listener)
      Remove a change listener.
      Specified by:
      removePropertyChangeListener in interface IPropertyChangeProvider
      Parameters:
      listener - the listener to be removed
    • addPropertyChangeListener

      public void addPropertyChangeListener​(java.lang.String propertyName, java.beans.PropertyChangeListener listener)
      Add a change listener.
      Specified by:
      addPropertyChangeListener in interface IPropertyChangeProvider
      Parameters:
      propertyName - the property name the listener will be registered for
      listener - the listener to be added
    • removePropertyChangeListener

      public void removePropertyChangeListener​(java.lang.String propertyName, java.beans.PropertyChangeListener listener)
      Remove a change listener.
      Specified by:
      removePropertyChangeListener in interface IPropertyChangeProvider
      Parameters:
      propertyName - the property name the listener will not listen for anymore
      listener - the listener to be removed
    • getPropertyChangeListeners

      protected java.beans.PropertyChangeListener[] getPropertyChangeListeners()
      Returns all listeners.
      Returns:
      all listeners
      See Also:
      PropertyChangeSupport.getPropertyChangeListeners()
    • getPropertyChangeListeners

      protected java.beans.PropertyChangeListener[] getPropertyChangeListeners​(java.lang.String propertyName)
      Returns change listeners on a specific property.
      Parameters:
      propertyName - name of property
      Returns:
      the listeners for this property
      See Also:
      PropertyChangeSupport.getPropertyChangeListeners(java.lang.String)
    • firePropertyChange

      protected boolean firePropertyChange​(java.lang.String propertyName, java.lang.Object oldValue, java.lang.Object newValue)
      Fires an event if property changed.
      Parameters:
      propertyName - name of property
      oldValue - old value
      newValue - new value
      Returns:
      true when the event was fired (because values were not equal)
    • firePropertyChange

      protected boolean firePropertyChange​(java.lang.String propertyName, java.lang.Object oldValue, java.lang.Object newValue, boolean makeDirty)
      Fires an event if property changed.
      Parameters:
      propertyName - name of property
      oldValue - old value
      newValue - new value
      makeDirty - whether to make this object dirty (register the change)
      Returns:
      true when the event was fired (because values were not equal)
    • firePropertyChange

      protected boolean firePropertyChange​(java.lang.String propertyName, int oldValue, int newValue)
      Fires an event if property changed.
      Parameters:
      propertyName - name of property
      oldValue - old value
      newValue - new value
      Returns:
      true when the event was fired (because values were not equal)
    • firePropertyChange

      protected boolean firePropertyChange​(java.lang.String propertyName, int oldValue, int newValue, boolean makeDirty)
      Fires an event if property changed.
      Parameters:
      propertyName - name of property
      oldValue - old value
      newValue - new value
      makeDirty - true when the object shall be marked dirty
      Returns:
      true when the event was fired (because values were not equal)
    • firePropertyChange

      protected boolean firePropertyChange​(java.lang.String propertyName, boolean oldValue, boolean newValue)
      Fires an event if property changed.
      Parameters:
      propertyName - name of property
      oldValue - old value
      newValue - new value
      Returns:
      true when the event was fired (because values were not equal)
    • firePropertyChange

      protected boolean firePropertyChange​(java.lang.String propertyName, boolean oldValue, boolean newValue, boolean makeDirty)
      Fires an event if property changed.
      Parameters:
      propertyName - name of property
      oldValue - old value
      newValue - new value
      makeDirty - true when the object shall be marked dirty
      Returns:
      true when the event was fired (because values were not equal)
    • firePropertyChange

      public boolean firePropertyChange​(java.lang.String propertyName, float oldValue, float newValue)
      Fires an event if property changed.
      Parameters:
      propertyName - name of property
      oldValue - old value
      newValue - new value
      Returns:
      true when the event was fired (because values were not equal)
    • firePropertyChange

      public boolean firePropertyChange​(java.lang.String propertyName, float oldValue, float newValue, boolean makeDirty)
      Fires an event if property changed.
      Parameters:
      propertyName - name of property
      oldValue - old value
      newValue - new value
      makeDirty - true when the object shall be marked dirty
      Returns:
      true when the event was fired (because values were not equal)
    • firePropertyChange

      protected boolean firePropertyChange​(java.beans.PropertyChangeEvent event)
      Fires a change event.
      Parameters:
      event - event to be fired
      Returns:
      true when the event was fired (because values were not equal)
    • firePropertyChange

      protected boolean firePropertyChange​(java.beans.PropertyChangeEvent event, boolean makeDirty)
      Fires a change event.
      Parameters:
      event - event to be fired
      makeDirty - true when the object shall be marked dirty
      Returns:
      true when the event was fired (because values were not equal)
    • fireIndexedPropertyChange

      protected boolean fireIndexedPropertyChange​(java.lang.String propertyName, int index, java.lang.Object oldValue, java.lang.Object newValue)
      Fires an indexed change event.
      Parameters:
      propertyName - name of property
      index - index of property
      oldValue - old value
      newValue - new value
      Returns:
      true when the event was fired (because values were not equal)
    • fireIndexedPropertyChange

      protected boolean fireIndexedPropertyChange​(java.lang.String propertyName, int index, int oldValue, int newValue)
      Fires an indexed change event.
      Parameters:
      propertyName - name of property
      index - index of property
      oldValue - old value
      newValue - new value
      Returns:
      true when the event was fired (because values were not equal)
    • fireIndexedPropertyChange

      protected boolean fireIndexedPropertyChange​(java.lang.String propertyName, int index, boolean oldValue, boolean newValue)
      Fires an indexed change event.
      Parameters:
      propertyName - name of property
      index - index of property
      oldValue - old value
      newValue - new value
      Returns:
      true when the event was fired (because values were not equal)
    • hasListeners

      protected boolean hasListeners​(java.lang.String propertyName)
      Returns true when the specified property has listeners attached.
      Parameters:
      propertyName - name of property
      Returns:
      true when there are listeners on that property
      See Also:
      PropertyChangeSupport.hasListeners(java.lang.String)
    • registerChange

      protected void registerChange​(java.lang.String propertyName, java.lang.Object oldValue, java.lang.Object newValue)
      Register the property change.
      Parameters:
      propertyName - name of property
      oldValue - old value
      newValue - new value
    • getOriginalValue

      protected java.lang.Object getOriginalValue​(java.lang.String propertyName)
      Returns the original value. The original value is the value of a property that existed at the time when isDirty() returned false. The value will be compared to the value currently held by this object in order to detect any changes.
      Parameters:
      propertyName - name of property
      Returns:
      persistent value
    • set

      public void set​(java.lang.String name, java.lang.Object value)
      Set the property with given name to the value
      Specified by:
      set in interface IBean
      Parameters:
      name - property name
      value - value
    • get

      public java.lang.Object get​(java.lang.String name)
      Gets the property with given name
      Specified by:
      get in interface IBean
      Parameters:
      name - property name
      Returns:
      the value of the property
    • getChanges

      public java.util.Collection<java.beans.PropertyChangeEvent> getChanges()
      Returns the list of changes that this bean has performed since loading.
      Specified by:
      getChanges in interface IBean
      Returns:
      the list of changes so far
    • copyTo

      public void copyTo​(java.lang.Object destination)
      Copies all properties to the given object.

      The method will ask isCopyAllowed(PropertyDescriptor) for each property of this bean.

      Specified by:
      copyTo in interface IBean
      Parameters:
      destination - destination object
      Throws:
      java.lang.IllegalArgumentException - when the destination is not of same type as this class
    • getPropertyNames

      public java.lang.Iterable<java.lang.String> getPropertyNames()
      Returns the property names of this bean.
      Specified by:
      getPropertyNames in interface IBean
      Returns:
      the property names
    • isCopyAllowed

      protected boolean isCopyAllowed​(java.beans.PropertyDescriptor descriptor)
      Returns true when copyTo(Object) is allowed to copy the given property.

      This method relies on the NoCopy and Transient annotations on read methods.

      Parameters:
      descriptor - the descriptor of th eproperty to be checked
      Returns:
      true when copy is allowed
      See Also:
      BeanSupport.isCopyForbidden(Class, String)
    • isCopyAllowed

      protected boolean isCopyAllowed​(java.lang.String name)
      Returns true when copyTo(Object) is allowed to copy the given property.

      This method relies on the NoCopy and Transient annotations on read methods.

      Parameters:
      name - - the name of the property to be checked
      Returns:
      true when copy is allowed
      See Also:
      BeanSupport.isCopyForbidden(Class, String)
    • reset

      public void reset()
      Reset all changes.
      Specified by:
      reset in interface IBean
    • toString

      public java.lang.String toString()
      Overrides:
      toString in class java.lang.Object