Class org.as2lib.env.event.distributor.AbstractCompositeEventDistributorControl

org.as2lib.env.event.distributor.AbstractCompositeEventDistributorControl

Implemented Interfaces

CompositeEventDistributorControl

Description

AbstractCompositeEventDistributorControl is the default implementation of the CompositeEventDistributorControl interface.

To use its functionalities, simply extend it and set a factory for the default event distributors.

Method Index

new AbstractCompositeEventDistributorControl()

acceptListenerType(), addAllListeners(), addListener(), getAllListeners(), getDistributor(), hasListener(), registerDefaultEventDistributorControl(), registerEventDistributorControl(), removeAllListeners(), removeListener()

Constructor Detail

AbstractCompositeEventDistributorControl

public function AbstractCompositeEventDistributorControl(eventDistributorControlFactory:EventDistributorControlFactory)

Creates a new AbstractCompositeEventDistributorControl instance.

Parameters

eventDistributorControlFactorythe factory to create event distributor controls for the different listener types

Method Detail

addListener

public function addListener(l):Void

Adds a the given listener to this event distributor control.

It validates if the passed-in listener is of any of the accepted listener types.

The listener will be added to all matching distributors.

Parameters

lthe Listener to add to the control

Throws

IllegalArgumentExceptionif the given listener does not match any of the accepted types.

removeListener

public function removeListener(l):Void

Removes the given listener from this distributor control and thus from listening to events.

Parameters

lthe listener to remove

addAllListeners

public function addAllListeners(listeners:Array):Void

Adds a list of listeners to this event distributor control to listen to events.

Parameters

listenersthe list of listeners to add

Throws

IllegalArgumentExceptionif any listener is not accepted (the listeners before the certain listener will be added)

removeAllListeners

public function removeAllListeners(Void):Void

Removes all added listeners.

getAllListeners

public function getAllListeners(Void):Array

Returns a list that contains all listeners.

Return

the list that contains all listeners

hasListener

public function hasListener(l):Boolean

Checks if the given listener has already been added.

Parameters

lthe listener to check whether it has already been added

Return

true if the listener has been added

acceptListenerType

public function acceptListenerType(listenerType:Function):Void

Adds acception for the given listenerType.

addListener does not allow listeners that do not match (instanceof) at least one of the accepted listener types.

Parameters

Specified By

acceptListenerType() in org.as2lib.env.event.distributor.CompositeEventDistributorControl

getDistributor

public function getDistributor(type:Function)

Returns the distributor that can be used to broadcast an event to all added listeners that match the distributor's type.

Note that the returned distributor will not be updated if you add a new distributor control for the given type after you obtained a distributor. You must get a new distributor if you want an updated one.

Return

the distributor to distribute events

Throws

IllegalArgumentExceptionif there is no distributor for the given type

Specified By

getDistributor() in org.as2lib.env.event.distributor.CompositeEventDistributorControl

registerEventDistributorControl

public function registerEventDistributorControl(eventDistributorControl:EventDistributorControl):Void

Registers the given eventDistributorControl with its listener and distributor type returned by its EventDistributorControl.getType method.

The type is then automatically an accepted listener type.

If there is already a distributor control registered for the given type, it will be overwritten.

If you hold references to distributors of this type, returned by the getDistributor method, you will have to update them, else events will not be distributed to newly registered listeners of that type.

You use this method if you have a specific event that should be executed with a special kind of distributor, for example with a consumable one.

Parameters

eventDistributorControlthe event distributor control to use for event distribution for the given type

Throws

IllegalArgumentExceptionif the given argument eventDistributorControl is null or undefined

Specified By

registerEventDistributorControl() in org.as2lib.env.event.distributor.CompositeEventDistributorControl

registerDefaultEventDistributorControl

public function registerDefaultEventDistributorControl(type:Function):Void

Registers a default event distributor control with the given listener and distributor type.

The type is then automatically an accepted listener type.

If there is already a distributor control registered for the given type, it will be overwritten.

Parameters

typethe type to register a default distributor control with

Throws

IllegalArgumentExceptionif argument type is null or undefined

Specified By

registerDefaultEventDistributorControl() in org.as2lib.env.event.distributor.CompositeEventDistributorControl