org.gvsig.tools.observer.impl
Class BaseWeakReferencingObservable

java.lang.Object
  extended by org.gvsig.tools.observer.impl.BaseWeakReferencingObservable
All Implemented Interfaces:
Cloneable, ComplexObservable, ComplexWeakReferencingObservable, Observable, WeakReferencingObservable
Direct Known Subclasses:
DelegateWeakReferencingObservable

public class BaseWeakReferencingObservable
extends Object
implements ComplexWeakReferencingObservable, Cloneable

Implementation for observers based on the use of Reference, instead of direct Observer references. This way an Observer may be Garbagge collected if its unique reference is the one registered into the Observable.

Author:
José Manuel Vivó, Cèsar Ordiñana

Constructor Summary
BaseWeakReferencingObservable()
           
 
Method Summary
 void addObserver(Observer observer)
          Adds an observer to the set of observers for this object, provided that it is not the same as some observer already in the set.
 void addObserver(Reference ref)
           
 void addObservers(BaseWeakReferencingObservable observable)
           
 void beginComplexNotification()
          Sets the Observable in complex notification mode.
protected  void clearChanged()
          Indicates that this object has no longer changed, or that it has already notified all of its observers of its most recent change, so that the hasChanged method will now return false.
 Object clone()
           
 int countObservers()
          Returns the number of observers of this object.
 void deleteObserver(Observer observer)
          Deletes an observer from the set of observers of this object.
 void deleteObserver(Reference ref)
           
 void deleteObservers()
          Clears the observer list so that this object no longer has any observers.
 void disableNotifications()
          Disable the notification of events to registered Observers.
 void enableNotifications()
          Enable (default) the notification of events to registered Observers.
 void endComplexNotification()
          Ends the complex notification mode.
protected  boolean hasChanged()
          Tests if this object has changed.
 boolean inComplex()
           
 boolean isEnabledNotifications()
           
protected  void notify(WeakReferencingObservable observable, Object object)
           
 void notifyObservers()
          If this object has changed, as indicated by the hasChanged method, then notify all of its observers and then call the clearChanged method to indicate that this object has no longer changed.
 void notifyObservers(Object arg)
          If this object has changed, as indicated by the hasChanged method, then notify all of its observers and then call the clearChanged method to indicate that this object has no longer changed.
protected  void setChanged()
          Marks this DefaultObservable object as having been changed; the hasChanged method will now return true.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BaseWeakReferencingObservable

public BaseWeakReferencingObservable()
Method Detail

addObserver

public void addObserver(Observer observer)
Adds an observer to the set of observers for this object, provided that it is not the same as some observer already in the set. The order in which notifications will be delivered to multiple observers is not specified. See the class comment.

Specified by:
addObserver in interface Observable
Parameters:
observer - an observer to be added.
Throws:
NullPointerException - if the parameter o is null.

addObserver

public void addObserver(Reference ref)

addObservers

public void addObservers(BaseWeakReferencingObservable observable)

deleteObserver

public void deleteObserver(Observer observer)
Deletes an observer from the set of observers of this object. Passing null to this method will have no effect.

Specified by:
deleteObserver in interface Observable
Parameters:
observer - the observer to be deleted.

deleteObserver

public void deleteObserver(Reference ref)

notifyObservers

public void notifyObservers()
If this object has changed, as indicated by the hasChanged method, then notify all of its observers and then call the clearChanged method to indicate that this object has no longer changed.

Each observer has its update method called with two arguments: this observable object and null. In other words, this method is equivalent to:

notifyObservers(null)

See Also:
Observable.clearChanged(), Observable.hasChanged(), Observer.update(java.util.Observable, java.lang.Object)

notifyObservers

public void notifyObservers(Object arg)
If this object has changed, as indicated by the hasChanged method, then notify all of its observers and then call the clearChanged method to indicate that this object has no longer changed.

Each observer has its update method called with two arguments: this observable object and the arg argument. public void visit(Object obj) throws VisitCanceledException, BaseException { // TODO Auto-generated method stub }

Parameters:
arg - any object.
See Also:
Observable.clearChanged(), Observable.hasChanged(), Observer.update(java.util.Observable, java.lang.Object)

deleteObservers

public void deleteObservers()
Clears the observer list so that this object no longer has any observers.

Specified by:
deleteObservers in interface Observable

countObservers

public int countObservers()
Returns the number of observers of this object.

Returns:
the number of observers of this object.

enableNotifications

public void enableNotifications()
Description copied from interface: ComplexObservable
Enable (default) the notification of events to registered Observers.

Specified by:
enableNotifications in interface ComplexObservable

disableNotifications

public void disableNotifications()
Description copied from interface: ComplexObservable
Disable the notification of events to registered Observers.

Specified by:
disableNotifications in interface ComplexObservable

isEnabledNotifications

public boolean isEnabledNotifications()

inComplex

public boolean inComplex()

beginComplexNotification

public void beginComplexNotification()
Description copied from interface: ComplexObservable
Sets the Observable in complex notification mode. All notifications must be stored, until the mode ends, and then notify all Observers with all the notifications.

Specified by:
beginComplexNotification in interface ComplexObservable

endComplexNotification

public void endComplexNotification()
Description copied from interface: ComplexObservable
Ends the complex notification mode. All notifications stored while in complex notification mode, will be notified to the registered Observers.

Specified by:
endComplexNotification in interface ComplexObservable

clone

public Object clone()
             throws CloneNotSupportedException
Overrides:
clone in class Object
Throws:
CloneNotSupportedException

notify

protected void notify(WeakReferencingObservable observable,
                      Object object)

hasChanged

protected boolean hasChanged()
Tests if this object has changed.

Returns:
true if and only if the setChanged method has been called more recently than the clearChanged method on this object; false otherwise.
See Also:
Observable.clearChanged(), Observable.setChanged()

setChanged

protected void setChanged()
Marks this DefaultObservable object as having been changed; the hasChanged method will now return true.


clearChanged

protected void clearChanged()
Indicates that this object has no longer changed, or that it has already notified all of its observers of its most recent change, so that the hasChanged method will now return false. This method is called automatically by the notifyObservers methods.

See Also:
Observable.notifyObservers(), Observable.notifyObservers(java.lang.Object)


Copyright © 2004-2011 gvSIG. All Rights Reserved.