Package org.nuiton.util.beans
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.ObjectbeanThe bean to monitor.protected booleanexcludeModeIf true, then listen to the properties which are not in the propertyNamesprotected java.beans.PropertyChangeListenerlistenerThePropertyChangeListenerwhich listen modification on bean only on monitored properties.protected java.util.Map<java.lang.String,PropertyDiff>propertyDiffsNames of monitored and modified properties for the attached bean.protected java.util.List<java.lang.String>propertyNamesNames 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 voidclearModified()To clear the modified states.java.lang.ObjectgetBean()Obtains the monitoredbean.java.lang.String[]getModifiedProperties()Obtains the names of monitored properties which has been touched for the attached bean since last call toclearModified()orsetBean(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.booleanisExcludeMode()voidsetBean(java.lang.Object bean)Sets thebeanto monitor.voidsetExcludeMode(boolean excludeMode)voidsetProperties(java.lang.String... properties)To change the list of properties to watch.booleanwasModified()Tells if any of the monitored properties were modified on the attached bean since last call toclearModified()orsetBean(Object).
-
Field Details
-
propertyNames
protected final java.util.List<java.lang.String> propertyNamesNames of properties to watch or not on attached bean. -
excludeMode
protected boolean excludeModeIf true, then listen to the properties which are not in the propertyNames -
propertyDiffs
Names of monitored and modified properties for the attached bean. -
listener
protected final java.beans.PropertyChangeListener listenerThePropertyChangeListenerwhich listen modification on bean only on monitored properties. -
bean
protected java.lang.Object beanThe 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 monitoredbean.- Returns:
- the attached bean, or
nullif none attached.
-
wasModified
public boolean wasModified()Tells if any of the monitored properties were modified on the attached bean since last call toclearModified()orsetBean(Object).- Returns:
trueif there were a modified monitored property on the attached bean,falseotherwise.
-
getModifiedProperties
public java.lang.String[] getModifiedProperties()Obtains the names of monitored properties which has been touched for the attached bean since last call toclearModified()orsetBean(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
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 thebeanto monitor. As a side effect, it will attach thelistenerto 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 methodclearModified().- 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 aclearModified()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)
-