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 java.lang.Object
      implements IObservable

  Default implementation of an `IObservable`.

  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 and Description
    `BaseObservable(IObservable observable)`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `addObserver(IObserver observer)` Attaches a observer to the Observable.
    `int` | `countObservers()` Counts how many Observers were attached to this class.
    `void` | `deleteObserver(IObserver observer)` Detaches a previously attached observer to the observable.
    `void` | `deleteObservers()` Detaches all previously attached observer to the observable.
    `java.util.List<IObserver>` | `getObservers()` Returns list of observers registered with the Observable.
    `void` | `notifyObservers()` Notifies all attached observers about changes in the observable.
    `void` | `notifyObservers(java.lang.Object arg)` Notifies all attached observers about changes in the observable.
    `protected void` | `wrappedNotify(IObserver observer, IObservable observable, java.lang.Object arg)` This method is intended to encapsulate the notification semantics, in order to let extended classes to implement their own version.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### BaseObservable

          public BaseObservable(IObservable observable)

  - ### Method Detail

    - #### addObserver

          public void addObserver(IObserver observer)

      Description copied from interface: `IObservable`
      Attaches a observer to the Observable. After attachment the observer gets informed about changes in the Observable.
      Specified by:
        `addObserver` in interface `IObservable`
      Parameters:
        `observer` - The observer to attach to the observable

    - #### countObservers

          public int countObservers()

      Description copied from interface: `IObservable`
      Counts how many Observers were attached to this class.
      Specified by:
        `countObservers` in interface `IObservable`
      Returns:
        the number of Observers
      See Also:
        `IObserver`

    - #### getObservers

          public java.util.List<IObserver> getObservers()

      Description copied from interface: `IObservable`
      Returns list of observers registered with the Observable. List returned is unmodifiable list.
      Specified by:
        `getObservers` in interface `IObservable`
      Returns:
        list of observers

    - #### deleteObserver

          public void deleteObserver(IObserver observer)

      Description copied from interface: `IObservable`
      Detaches a previously attached observer to the observable. After detachment the observer does no longer receive change notifications from the observable.
      Specified by:
        `deleteObserver` in interface `IObservable`
      Parameters:
        `observer` - The observer to detach from the observable

    - #### deleteObservers

          public void deleteObservers()

      Description copied from interface: `IObservable`
      Detaches all previously attached observer to the observable. After detachment observers do not longer receive change notifications from the observable.
      Specified by:
        `deleteObservers` in interface `IObservable`

    - #### notifyObservers

          public void notifyObservers()

      Description copied from interface: `IObservable`
      Notifies all attached observers about changes in the observable.
      Specified by:
        `notifyObservers` in interface `IObservable`

    - #### notifyObservers

          public void notifyObservers(java.lang.Object arg)

      Description copied from interface: `IObservable`
      Notifies all attached observers about changes in the observable.
      Specified by:
        `notifyObservers` in interface `IObservable`
      Parameters:
        `arg` - an arbitrary Object to be passed to the Observer

    - #### wrappedNotify

          protected void wrappedNotify(IObserver observer,
                           IObservable observable,
                           java.lang.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.