net.sf.okapi.common.observer

## Class WeakReferenceObservable

- java.lang.Object
- - net.sf.okapi.common.observer.BaseObservable
  - - net.sf.okapi.common.observer.WeakReferenceObservable

- All Implemented Interfaces:
    IObservable

      public class WeakReferenceObservable
      extends BaseObservable

  Implementation of `IObservable` that holds references to Observers as WeakReferences. 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 the notification is then done also in the transaction.

  This class is based on the work done by Martin Fischer. See references below.

  Author:
    Martin Fischer (original author), Richard Gomes, Srinivas Hasti
  See Also:
    Martin Fischer: Observer and Observable interfaces, Improved Observer/Observable, `IObservable`, `IObserver`, `BaseObservable`

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `WeakReferenceObservable(IObservable observable)` Creates a new WeakReferenceObservable object with a given `IObservable` object.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `addObserver(IObserver observer)` Attaches a observer to the Observable.
    `void` | `deleteObserver(IObserver observer)` Detaches a previously attached observer to the observable.

    - ### Methods inherited from class net.sf.okapi.common.observer.BaseObservable

      `countObservers, deleteObservers, getObservers, notifyObservers, notifyObservers, wrappedNotify`

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

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

- - ### Constructor Detail

    - #### WeakReferenceObservable

          public WeakReferenceObservable(IObservable observable)

      Creates a new WeakReferenceObservable object with a given `IObservable` object.
      Parameters:
        `observable` - the object to observe.

  - ### 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`
      Overrides:
        `addObserver` in class `BaseObservable`
      Parameters:
        `observer` - The observer to attach to the observable

    - #### 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`
      Overrides:
        `deleteObserver` in class `BaseObservable`
      Parameters:
        `observer` - The observer to detach from the observable