Package net.sf.okapi.common.observer
Class BaseObservable
- java.lang.Object
-
- net.sf.okapi.common.observer.BaseObservable
-
- All Implemented Interfaces:
IObservable
- Direct Known Subclasses:
WeakReferenceObservable
public class BaseObservable extends Object implements IObservable
Default implementation of anIObservable.This implementation notifies the observers in a synchronous fashion. Note that this can cause trouble if you notify the observers while in a transactional context because once the notification is done it cannot be rolled back.
- Author:
- Richard Gomes, Srinivas Hasti
- See Also:
-
Martin Fischer: Observer and Observable interfaces,
Improved
Observer/Observable,
IObservable,IObserver,WeakReferenceObservable
-
-
Constructor Summary
Constructors Constructor Description BaseObservable(IObservable observable)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddObserver(IObserver observer)Attaches a observer to the Observable.intcountObservers()Counts how many Observers were attached to this class.voiddeleteObserver(IObserver observer)Detaches a previously attached observer to the observable.voiddeleteObservers()Detaches all previously attached observer to the observable.List<IObserver>getObservers()Returns list of observers registered with the Observable.voidnotifyObservers()Notifies all attached observers about changes in the observable.voidnotifyObservers(Object arg)Notifies all attached observers about changes in the observable.protected voidwrappedNotify(IObserver observer, IObservable observable, Object arg)This method is intended to encapsulate the notification semantics, in order to let extended classes to implement their own version.
-
-
-
Constructor Detail
-
BaseObservable
public BaseObservable(IObservable observable)
-
-
Method Detail
-
addObserver
public void addObserver(IObserver observer)
Description copied from interface:IObservableAttaches a observer to the Observable. After attachment the observer gets informed about changes in the Observable.- Specified by:
addObserverin interfaceIObservable- Parameters:
observer- The observer to attach to the observable
-
countObservers
public int countObservers()
Description copied from interface:IObservableCounts how many Observers were attached to this class.- Specified by:
countObserversin interfaceIObservable- Returns:
- the number of Observers
- See Also:
IObserver
-
getObservers
public List<IObserver> getObservers()
Description copied from interface:IObservableReturns list of observers registered with the Observable. List returned is unmodifiable list.- Specified by:
getObserversin interfaceIObservable- Returns:
- list of observers
-
deleteObserver
public void deleteObserver(IObserver observer)
Description copied from interface:IObservableDetaches a previously attached observer to the observable. After detachment the observer does no longer receive change notifications from the observable.- Specified by:
deleteObserverin interfaceIObservable- Parameters:
observer- The observer to detach from the observable
-
deleteObservers
public void deleteObservers()
Description copied from interface:IObservableDetaches all previously attached observer to the observable. After detachment observers do not longer receive change notifications from the observable.- Specified by:
deleteObserversin interfaceIObservable
-
notifyObservers
public void notifyObservers()
Description copied from interface:IObservableNotifies all attached observers about changes in the observable.- Specified by:
notifyObserversin interfaceIObservable
-
notifyObservers
public void notifyObservers(Object arg)
Description copied from interface:IObservableNotifies all attached observers about changes in the observable.- Specified by:
notifyObserversin interfaceIObservable- Parameters:
arg- an arbitrary Object to be passed to the Observer
-
wrappedNotify
protected void wrappedNotify(IObserver observer, IObservable observable, Object arg)
This method is intended to encapsulate the notification semantics, in order to let extended classes to implement their own version. Possible implementations are:- remote notification;
- notification via SwingUtilities.invokeLater
- others...
The default notification simply does
observer.update(observable, arg);
- Parameters:
observer- the observer.observable- the object to be observed.arg- additional arguments.
-
-