net.wotonomy.control
Class EOObserverCenter

java.lang.Object
  extended by net.wotonomy.control.EOObserverCenter
All Implemented Interfaces:
java.util.Observer

public class EOObserverCenter
extends java.lang.Object
implements java.util.Observer

EOObserverCenter is a static singleton-like class that manages EOObservings that want to be notified of changes to those objects that call notifyObserversObjectWillChange() before their properties change.

Implementation note: Because Java implements the Observer pattern in java.util.Observable, this class knows how to register itself as an Observer with Observables as well. However, users should note that Observables only notify their Observers of changes after their property has changed. EODelayedObservers would see no difference because they always receive their notification after all changes have taken place.

This implementation uses weak references for observers and observables. The advantage to this approach is that you do not need to explicitly unregister observers or observables; they will be unregistered when they are garbage-collected. Note that you will need to retain a reference to any objects you register or they may become unregistered if no other object references them.

Version:
$Revision: 894 $
Author:
michael@mpowers.net, $Author: cgruber $

Constructor Summary
EOObserverCenter()
           
 
Method Summary
static void addObserver(EOObserving anObserver, java.lang.Object anObject)
          Registers the specified EOObserving for notifications from the specified object.
static void addOmniscientObserver(EOObserving anObserver)
          Registers the specified EOObserving for notifications on all object changes.
static void enableObserverNotification()
          Enables notifications after they have been suppressed by suppressObserverNotification.
static void notifyObserversObjectWillChange(java.lang.Object anObject)
          Notifies all EOObservings registered for notifications for the specified object.
static EOObserving observerForObject(java.lang.Object anObject, java.lang.Class aClass)
          Returns an observer that is an instance of the specified class and that is registered for notifications about the specified object.
static int observerNotificationSuppressCount()
          Returns the number of times that notifications have been suppressed.
static net.wotonomy.foundation.NSArray observersForObject(java.lang.Object anObject)
          Returns a List of observers for the specified object.
static void removeObserver(EOObserving anObserver, java.lang.Object anObject)
          Unregisters the specified observer for notifications from the specified object.
static void removeOmniscientObserver(EOObserving anObserver)
          Unregisters the specified omniscient observer.
static void suppressObserverNotification()
          Causes notifications to be suppressed until the next matching call to enableObserverNotification.
 void update(java.util.Observable o, java.lang.Object arg)
          Interface Observer
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

EOObserverCenter

public EOObserverCenter()
Method Detail

addObserver

public static void addObserver(EOObserving anObserver,
                               java.lang.Object anObject)
Registers the specified EOObserving for notifications from the specified object. An EOObserving can only be registered once for a given object.


addOmniscientObserver

public static void addOmniscientObserver(EOObserving anObserver)
Registers the specified EOObserving for notifications on all object changes. An EOObserving can be registered as an omniscient observer at most once. Use omniscient observers with caution.


notifyObserversObjectWillChange

public static void notifyObserversObjectWillChange(java.lang.Object anObject)
Notifies all EOObservings registered for notifications for the specified object. This method is typically called by objects that wish to broadcast a notification before a property change takes place, passing itself as the argument.


observerForObject

public static EOObserving observerForObject(java.lang.Object anObject,
                                            java.lang.Class aClass)
Returns an observer that is an instance of the specified class and that is registered for notifications about the specified object. If more than one such observer exists, which observer is returned is undetermined - use observersForObject instead. If no observer exists, returns null.


observerNotificationSuppressCount

public static int observerNotificationSuppressCount()
Returns the number of times that notifications have been suppressed. This is also the number of times that enableObserverNotification must be called to allow notifications to take place.


observersForObject

public static net.wotonomy.foundation.NSArray observersForObject(java.lang.Object anObject)
Returns a List of observers for the specified object. Returns an empty List if no observer has registered for that object.


removeObserver

public static void removeObserver(EOObserving anObserver,
                                  java.lang.Object anObject)
Unregisters the specified observer for notifications from the specified object.


removeOmniscientObserver

public static void removeOmniscientObserver(EOObserving anObserver)
Unregisters the specified omniscient observer.


enableObserverNotification

public static void enableObserverNotification()
Enables notifications after they have been suppressed by suppressObserverNotification. If notifications have been suppressed multiple times, this method must be called an equal number of times to resume notifications. If notifications are not currently suppressed, this method does nothing.


suppressObserverNotification

public static void suppressObserverNotification()
Causes notifications to be suppressed until the next matching call to enableObserverNotification. If this method is called more than once, enableObserverNotification must be called an equal number of times for notifications to resume. This method always causes notifications to cease immediately.


update

public void update(java.util.Observable o,
                   java.lang.Object arg)
Interface Observer

Specified by:
update in interface java.util.Observer


Copyright © 2006 null. All Rights Reserved.