I'm trying to develop an application where in the people will get notified if there is any change in the PartNumber. Its a Spring based application. Following is the code snippet.
I've abstracted the storing mechanism here in SaveSubscriptionIF
. The actual details of storing and retrieving are in the implementation class of this interface. The implementation class will be injected by Spring.
The external application calls my setState()
method- passing the new information.
The store.getObservers()
method returns me the Map
which have the Observers and the corresponding info to update.
So far so good. Am struck in the implementation part of store.getObservers()
. This method implementation needs the state
data - i.e the new information passed from the external application.
How do i pass the 'state' data to an implementation class of 'SaveSubscriptionIF'??
public class PartNumberSubject implements Observable {
private SaveSubscriptionIF store;
private Object state;
@Override
public void addObserver(final ObserverIF o, final Object subscriptionDetails) {
store.addObserver(o, subscriptionDetails);
}
@Override
public void notifyObservers() {
@SuppressWarnings("unchecked")
final Map<ObserverIF, List<PartInformationVO>> observers =(Map<ObserverIF,List<PartInformationVO>>) store .getObservers();
for (final Entry<ObserverIF, List<PartInformationVO>> observer : observers
.entrySet()) {
observer.getKey().update(observer.getValue());
}
}
@Override
public void setState(final Object state) {
this.state = state;
notifyObservers();
}
}