Handling Partner Events

Partner events allow you to be informed of partners entering or leaving a project, of newly created or deleted partners or teams, and of edited partner or team information. The icc.db.Partner class provides additional functionality to help you in storing and maintaining a hashtable of partners and teams. The icc.db.Project class provides additional functionality to help you in storing and maintaining project partners information.

Partner events In all these events, the event source is null.

a. Entering events A partner ENTERS event is posted when a partner is added to a project. The event object is an Integer array containing the project and partner identifiers.

b. Leaving events A partner LEAVES event is posted when a partner is removed from a project. The event object is an Integer array containing the project and partner identifiers.

c. Creation events A partner CREATION event is posted when a partner or team is newly created. The event object is the partner or team information.

d. Deletion events A partner DELETION event is posted when a partner or team is deleted. The event object is the partner or team identifier.

e. Edit events A partner EDIT event is posted when a partner or team information is altered (except when the members of a team are changed). The event object is the partner or team information; if a team, the team members information may not be correct.

f. Modification events A partner MODIFICATION event is posted when the members of a team are changed. The event object is the team identifier.

Handling partner events The following example updates the partner or team information in the Partner and Project classes as appropriate.

public void handlePartnerEvent(Event event) {
    Integer id = null, projectid = null;
    Partner partner = null;
    switch (event.type) {
    case Event.ENTERS:
	id = ((Integer[]) event.object)[0];
        projectid = ((Integer[]) event.object)[1];
	if (!Partner.contains(id))
            this.send(new Package(IDCard.SERVICE,
                Partner.retrieve(id)));
	Project.get(projectid).setPartner(id, "");
	break;
    case Event.LEAVES:
	id = ((Integer[]) event.object)[0];
        projectid = ((Integer[]) event.object)[1];
	Project.get(projectid).removePartner(id);
	break;
    case Event.CREATION:
	partner = (Partner) event.object;
        partner.put();
        break;
    case Event.DELETION:
	id = (Integer) event.object;
	Partner.remove(id);
	break;
    case Event.MODIFICATION:
        id = (Integer) event.object;
	this.send(new Package(IDCard.SERVICE,
            Partner.retrieve(id)));
	break;
    case Event.EDIT:
	partner = (Partner) event.object;
	if (partner instanceof Team)
	    this.send(new Package(IDCard.SERVICE,
                Partner.retrieve(partner.id())));
	else partner.put();
	break;
    }
}
Note: All of the following assumptions were made. The instance method send sends a package through the speaker and catches any IOException that may be thrown. Project information, including project partners, are known and stored in the Project class.


Last modified on 5 May 1999 by Rudi Stouffs

This website has been archived and is no longer maintained.