Class BeanMonitor

java.lang.Object
org.nuiton.util.beans.BeanMonitor

public class BeanMonitor
extends java.lang.Object
A monitor of beans. You indicates which properties to monitor (via the constructor). Then attach a bean to monitor via the method setBean(Object). The method clearModified() reset the states about modified properties. The method wasModified() tells if there was any modification on monitored properties for the attached bean since the last call to clearModified() (or setBean(Object). the method getModifiedProperties() gives you the names of monitored properties for the attached bean since the last call to clearModified() (or setBean(Object).
Since:
1.4.1
Author:
Tony Chemit - chemit@codelutin.com
  • Field Summary

    Fields 
    Modifier and Type Field Description
    protected java.lang.Object bean
    The bean to monitor.
    protected boolean excludeMode
    If true, then listen to the properties which are not in the propertyNames
    protected java.beans.PropertyChangeListener listener
    The PropertyChangeListener which listen modification on bean only on monitored properties.
    protected java.util.Map<java.lang.String,​PropertyDiff> propertyDiffs
    Names of monitored and modified properties for the attached bean.
    protected java.util.List<java.lang.String> propertyNames
    Names of properties to watch or not on attached bean.
  • Constructor Summary

    Constructors 
    Constructor Description
    BeanMonitor​(boolean exclude, java.lang.String... propertyNames)  
    BeanMonitor​(java.lang.String... propertyNames)
    Constructor of monitor with property names to monitor.
  • Method Summary

    Modifier and Type Method Description
    void clearModified()
    To clear the modified states.
    java.lang.Object getBean()
    Obtains the monitored bean.
    java.lang.String[] getModifiedProperties()
    Obtains the names of monitored properties which has been touched for the attached bean since last call to clearModified() or setBean(Object).
    java.util.Map<java.lang.String,​java.lang.Object> getOriginalValues()
    Obtains the original values for all modified properties.
    PropertyDiff[] getPropertyDiffs()
    Obtains the property diffs since the bean is monitoried.
    boolean isExcludeMode()  
    void setBean​(java.lang.Object bean)
    Sets the bean to monitor.
    void setExcludeMode​(boolean excludeMode)  
    void setProperties​(java.lang.String... properties)
    To change the list of properties to watch.
    boolean wasModified()
    Tells if any of the monitored properties were modified on the attached bean since last call to clearModified() or setBean(Object).

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • propertyNames

      protected final java.util.List<java.lang.String> propertyNames
      Names of properties to watch or not on attached bean.
    • excludeMode

      protected boolean excludeMode
      If true, then listen to the properties which are not in the propertyNames
    • propertyDiffs

      protected final java.util.Map<java.lang.String,​PropertyDiff> propertyDiffs
      Names of monitored and modified properties for the attached bean.
    • listener

      protected final java.beans.PropertyChangeListener listener
      The PropertyChangeListener which listen modification on bean only on monitored properties.
    • bean

      protected java.lang.Object bean
      The bean to monitor.
  • Constructor Details

    • BeanMonitor

      public BeanMonitor​(java.lang.String... propertyNames)
      Constructor of monitor with property names to monitor.
      Parameters:
      propertyNames - the names of properties to monitor
    • BeanMonitor

      public BeanMonitor​(boolean exclude, java.lang.String... propertyNames)
  • Method Details

    • getBean

      public java.lang.Object getBean()
      Obtains the monitored bean.
      Returns:
      the attached bean, or null if none attached.
    • wasModified

      public boolean wasModified()
      Tells if any of the monitored properties were modified on the attached bean since last call to clearModified() or setBean(Object).
      Returns:
      true if there were a modified monitored property on the attached bean, false otherwise.
    • getModifiedProperties

      public java.lang.String[] getModifiedProperties()
      Obtains the names of monitored properties which has been touched for the attached bean since last call to clearModified() or setBean(Object).
      Returns:
      the array of property names to monitor.
    • getOriginalValues

      public java.util.Map<java.lang.String,​java.lang.Object> getOriginalValues()
      Obtains the original values for all modified properties.
      Returns:
      the dictionnary of original values for modified properties
    • getPropertyDiffs

      public PropertyDiff[] getPropertyDiffs()
      Obtains the property diffs since the bean is monitoried.
      Returns:
      the property diffs since the bean is monitoried.
      Since:
      2.4
    • setBean

      public void setBean​(java.lang.Object bean)
      Sets the bean to monitor. As a side effect, it will attach the listener to new bean (if not null) and remove it from the previous bean attached (if not null). As a second side effect, it will always clean the modified states, using the method clearModified().
      Parameters:
      bean - the new bean to monitor
    • clearModified

      public void clearModified()
      To clear the modified states.
    • setProperties

      public void setProperties​(java.lang.String... properties)
      To change the list of properties to watch. Note: As a side-effect, we call a clearModified() method after having changed the list of properties to watch.
      Parameters:
      properties - the list of properties to watch on the bean.
      Since:
      3.0
    • isExcludeMode

      public boolean isExcludeMode()
    • setExcludeMode

      public void setExcludeMode​(boolean excludeMode)