org.nuiton.util.beans
Class BeanMonitor

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

public class BeanMonitor
extends 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:
tchemit

Field Summary
protected  Object bean
          The bean to monitor.
protected  PropertyChangeListener listener
          The PropertyChangeListener which listen modification on bean only on monitored properties.
protected  Set<String> modifiedProperties
          Names of monitored and modified properties for the attached bean.
protected  Map<String,Object> originalValues
          To store the original values when watched properties are changing.
protected  List<String> propertyNames
          Names of properties to watch on attached bean.
 
Constructor Summary
BeanMonitor(String... propertyNames)
          Constructor of monitor with property names to monitor.
 
Method Summary
 void clearModified()
          To clear the modified states.
 Object getBean()
          Obtains the monitored bean.
 String[] getModifiedProperties()
          Obtains the names of monitored properties which has been touched for the attached bean since last call to clearModified() or setBean(Object).
 Map<String,Object> getOriginalValues()
          Obtains the original values for all modified properties.
 void setBean(Object bean)
          Sets the bean to monitor.
 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 Detail

propertyNames

protected final List<String> propertyNames
Names of properties to watch on attached bean.


modifiedProperties

protected final Set<String> modifiedProperties
Names of monitored and modified properties for the attached bean.


originalValues

protected final Map<String,Object> originalValues
To store the original values when watched properties are changing.


listener

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


bean

protected Object bean
The bean to monitor.

Constructor Detail

BeanMonitor

public BeanMonitor(String... propertyNames)
Constructor of monitor with property names to monitor.

Parameters:
propertyNames - the names of properties to monitor
Method Detail

getBean

public 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 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 Map<String,Object> getOriginalValues()
Obtains the original values for all modified properties.

Returns:
the dictionnary of original values for modified properties

setBean

public void setBean(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.



Copyright © 2004-2011 CodeLutin. All Rights Reserved.