org.openpermis.editor.policy.beans
Class PropertyChangeDispatcher

java.lang.Object
  extended by org.openpermis.editor.policy.beans.PropertyChangeDispatcher
All Implemented Interfaces:
PropertyChangeListener, EventListener

public class PropertyChangeDispatcher
extends Object
implements PropertyChangeListener

Dispatcher for property change events.

Create a dispatcher for a bean and a target class which contains PropertyChange annotations and the dispatcher will automatically dispatch property change events properly.

The dispatcher expects the following signuare:

 @PropertyChange(bean=MyBean.class, property="someProperty", parameter=MyValue.class)
 public someChangeHandler (MyBean source, String property, MyValue oldValue, MyValue newValue) {
   ...
 }

The first parameter has to be the source of the property change event and must match the bean class of the PropertyChange annotation. Parameters two and three correspond to the old and new value received in the property change event and must match the parameter class of the PropertyChange annotation.

The dispatcher will perform the casts necessary automatically and throw ClassCastExceptions if the cast is not possible. This should not occur unless the bean sends invalid property change notifications since the parameter types are checked when the dispatcher is created.

Since:
0.1.0

Constructor Summary
PropertyChangeDispatcher(Object bean, Object target)
          Creates a bean support object for the specified Java Bean.
 
Method Summary
 void dispose()
          Disposes this bean support instance.
protected  Object getBean()
          Returns the Java Bean this bean support operates on.
protected  Method getPropertyChangeMethod(String property)
          Returns the method to execute for property changes on the specified property.
protected  Object getTarget()
          Returns the target to dispatch property change events to.
 boolean isActive()
          Check if the dispatcher is active or has been disposed.
 void propertyChange(PropertyChangeEvent event)
          Listener for property changes.
protected  void setActive(boolean active)
          Sets the internal flag which indicates if this bean support is active.
protected  void warn(String message, Throwable cause)
          Logs a warning with the specified message and cause.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PropertyChangeDispatcher

public PropertyChangeDispatcher(Object bean,
                                Object target)
Creates a bean support object for the specified Java Bean.

Parameters:
bean - the Java Bean to operate on, must not be null.
target - the target to dispatch property change events to, must not be null.
Since:
0.1.0
Method Detail

getBean

protected final Object getBean()
Returns the Java Bean this bean support operates on.

Returns:
the Java Bean this bean support operates on, never null.
Since:
0.1.0

getTarget

protected final Object getTarget()
Returns the target to dispatch property change events to.

Returns:
the target to dispatch property change events to, may be null.
Since:
0.1.0

getPropertyChangeMethod

protected final Method getPropertyChangeMethod(String property)
Returns the method to execute for property changes on the specified property.

Parameters:
property - the property for which to find the method.
Returns:
the method, null if there is none.
Since:
0.1.0

setActive

protected final void setActive(boolean active)
Sets the internal flag which indicates if this bean support is active.

Parameters:
active - the new registered flag value.
See Also:
dispose(), isActive()
Since:
0.1.0

isActive

public boolean isActive()
Check if the dispatcher is active or has been disposed.

Returns:
true if the dispatcher is active and dispatches events, false if it has been disposed.
See Also:
dispose()
Since:
0.1.0

dispose

public void dispose()
Disposes this bean support instance.

Once disposed you may no longer execute property methods on it.

See Also:
isActive()
Since:
0.1.0

warn

protected void warn(String message,
                    Throwable cause)
Logs a warning with the specified message and cause.

Parameters:
message - the message to log.
cause - the cause.
Since:
0.1.0

propertyChange

public void propertyChange(PropertyChangeEvent event)
Listener for property changes.

Dispatches to methods annotated with PropertyChange on the target of this bean support instance.

Specified by:
propertyChange in interface PropertyChangeListener
Parameters:
event - the property change event to dispatch.
Since:
0.1.0


PERMIS Role Based Access Control 0.4.0 (Build 15)
2009/05/20 08:15:11
Copyright (c) 2002-2007 Ergon Informatik AG