BNZObservation



Abstract

Class for managing listener registrations. Combines a change type with a target object and associates some callback methods with them.

Discussion

This class is used for storing all the registrations in the BNZTransactionalNotificationCenter. It combines a record about a change type on a certain target object.

Instances of this class are used in BNZTransactionObserverRecord to indicate that a listener is interested in changes of the given type on the given target. Additionally, the callback selectors for "changeWillBeMade", "changeHasBeenMade" and "changeHasBeenRolledBack" are stored



Methods

changeType

- (id)changeType; 

Result: returns the change type this observation observes. nil if all changes on the target object are observed

hasCommittedCallback

- (SEL)hasCommittedCallback; 

Result: the selector to call back to the observer after a commit

hasRolledBackCallback

- (SEL)hasRolledBackCallback; 

Result: the selector to call back to the observer after a rollback

initWithObserver:forChangeType:onTarget:

- (id)initWithObserver:(id)observer forChangeType:(id)changeType onTarget:(id)target; 

calls initWithObserver:forChangeType:onTarget:withWillCommitCallback:hasCommittedCallback:andHasRolledBackCallback: with all callbacks nil


initWithObserver:forChangeType:onTarget:withHasCommittedCallback:

- (id)initWithObserver:(id)observer forChangeType:(id)changeType onTarget:(id)target withHasCommittedCallback:(SEL)hcCallback; 

calls initWithObserver:forChangeType:onTarget:withWillCommitCallback:hasCommittedCallback:andHasRolledBackCallback: with wcCallback and hrbCallback nil


initWithObserver:forChangeType:onTarget:withHasRolledBackCallback:

- (id)initWithObserver:(id)observer forChangeType:(id)changeType onTarget:(id)target withHasRolledBackCallback:(SEL)hrbCallback; 

calls initWithObserver:forChangeType:onTarget:withWillCommitCallback:hasCommittedCallback:andHasRolledBackCallback: with wcCallback and hcCallback nil


initWithObserver:forChangeType:onTarget:withWillCommitCallback:

- (id)initWithObserver:(id)observer forChangeType:(id)changeType onTarget:(id)target withWillCommitCallback:(SEL)wcCallback; 

calls initWithObserver:forChangeType:onTarget:withWillCommitCallback:hasCommittedCallback:andHasRolledBackCallback: with hcCallback and hrbCallback nil


initWithObserver:forChangeType:onTarget:withWillCommitCallback:hasCommittedCallback:andHasRolledBackCallback:

Abstract: construct a new observation record
- (id)initWithObserver:(id)observer forChangeType:(id)changeType onTarget:(id)target withWillCommitCallback:(SEL)wcCallback hasCommittedCallback:(SEL)hcCallback andHasRolledBackCallback:(SEL)hrbCallback; 

all the callbacks are expected to take one parameter of type BNZTransaction

Parameters

NameDescription
observerthe object that observes the target for changes
changeTypethe change type that shall be observed. nil if any change on the target should be observed
targetthe target object that shall be observed for changes. nil if all changes of the given type shall be observed
wcCallbacka callback called before a commit
hcCallbackcallback called after commit
hrbCallbackcallback called after rollback
Result: a new observation object

isObservationWithType:onTarget:

Abstract: YES if an exact match is found
- (BOOL)isObservationForType:(id)changeType onTarget:(id)target; 

this is different to a match! Example: imagine an observation of "FirstNameChange" on target o

while e.g., [observation observesChangesOfType:"FirstNameChange" onTarget:nil] returns true, the this method only returns true when "FirstNameChange" and the target are really equal


matches:

Abstract: checks if this observation matches the given change (i.e., if it "fires")
- (BOOL)matches:(id)change; 

Parameters

NameDescription
changethe change in question
Result: BOOL value, YES if this observation's target and change typew meet the change

observeChangesOfType:onTarget:

Abstract: very similar to matches: however, this method does not need an exiscing change but can work with the more abstract changeType and target.
- (BOOL)observeChangesOfType:(id)changeType onTarget:(id)target; 

Parameters

NameDescription
changeTypethe type in question
targetthe target in question
Result: BOOL value, YES if this observation's target and change typew meet the change

observer

- (id)observer; 

Result: the observer of the observation (the observer)

setHasCommittedCallback:

-  setHasCommittedCallback:(SEL)hcCallback; 

Parameters

NameDescription
thecallback that is called after a commit. nil if observer does not want to be informed
Result: returns self

setHasRolledBackCallback:

-  setHasRolledBackCallback:(SEL)hrbCallback; 

Parameters

NameDescription
thecallback that is called after a rollback. nil if observer does not want to be informed
Result: returns self

setWillCommitCallback:

-  setWillCommitCallback:(SEL)wcCallback; 

Parameters

NameDescription
thecallback that is called before a commit. nil if observer does not want to be informed
Result: returns self

target

- (id)target; 

Result: the target object that is observed. nil if all changes of the changeType on any object are observed

willCommitCallback

- (SEL)willCommitCallback; 

Result: the selector to call back to the observer before a commit

(Last Updated 8/31/2006)