Class ApiEventInjector
java.lang.Object
com.seibel.distanthorizons.coreapi.DependencyInjection.DependencyInjector<IDhApiEvent>
com.seibel.distanthorizons.coreapi.DependencyInjection.ApiEventInjector
- All Implemented Interfaces:
IDhApiEventInjector,IDependencyInjector<IDhApiEvent>
public class ApiEventInjector
extends DependencyInjector<IDhApiEvent>
implements IDhApiEventInjector
This class takes care of dependency injection for API events.
-
Field Summary
FieldsFields inherited from class com.seibel.distanthorizons.coreapi.DependencyInjection.DependencyInjector
allowDuplicateBindings, bindableInterface, dependencies -
Method Summary
Modifier and TypeMethodDescriptionvoidbind(Class<? extends IDhApiEvent> abstractEvent, IDhApiEvent eventImplementation) Links the given implementation object to an interface, so it can be referenced later.static <T> DhApiEventParam<T> createEventParamWrapper(IDhApiEvent<T> event, T parameter) Wraps the event parameter object in aDhApiCancelableEventParamorDhApiEventParamdepending on if it should allow cancellation or not.<T,U extends IDhApiEvent<T>>
booleanfireAllEvents(Class<U> abstractEventClass, T eventInput) Fires all bound events of the given type (does nothing if no events are bound).booleanunbind(Class<? extends IDhApiEvent> abstractEvent, Class<? extends IDhApiEvent> eventClassToRemove) Unlinks the given event handler, preventing the handler from being called in the future.Methods inherited from class com.seibel.distanthorizons.coreapi.DependencyInjection.DependencyInjector
checkIfClassExtends, checkIfClassImplements, clear, get, get, getAll, runDelayedSetupMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.seibel.distanthorizons.coreapi.interfaces.dependencyInjection.IDependencyInjector
checkIfClassExtends, checkIfClassImplements, clear, get, get, getAll, runDelayedSetup
-
Field Details
-
INSTANCE
-
-
Method Details
-
bind
public void bind(Class<? extends IDhApiEvent> abstractEvent, IDhApiEvent eventImplementation) throws IllegalStateException, IllegalArgumentException Description copied from interface:IDependencyInjectorLinks the given implementation object to an interface, so it can be referenced later.- Specified by:
bindin interfaceIDependencyInjector<IDhApiEvent>- Overrides:
bindin classDependencyInjector<IDhApiEvent>- Parameters:
abstractEvent- The interface (or parent class) the implementation object should implement.eventImplementation- An object that implements the dependencyInterface interface.- Throws:
IllegalStateException- if the interface has already been bound and duplicates aren't allowedIllegalArgumentException- if the implementation object doesn't implement the interface
-
unbind
public boolean unbind(Class<? extends IDhApiEvent> abstractEvent, Class<? extends IDhApiEvent> eventClassToRemove) throws IllegalArgumentException Description copied from interface:IDhApiEventInjectorUnlinks the given event handler, preventing the handler from being called in the future.- Specified by:
unbindin interfaceIDhApiEventInjector- Parameters:
abstractEvent- the base interface for theIDhApiEventeventClassToRemove- the concreteIDhApiEventclass to remove- Returns:
- true if the handler was unbound, false if the handler wasn't bound.
- Throws:
IllegalArgumentException- if the implementation object doesn't implement the interface
-
fireAllEvents
public <T,U extends IDhApiEvent<T>> boolean fireAllEvents(Class<U> abstractEventClass, T eventInput) Description copied from interface:IDhApiEventInjectorFires all bound events of the given type (does nothing if no events are bound).- Specified by:
fireAllEventsin interfaceIDhApiEventInjector- Type Parameters:
T- the parameter type taken by the event handlers.U- theIDhApiEvent's class- Parameters:
abstractEventClass- event typeeventInput- event parameter- Returns:
- if any of the bound event handlers notified that this event should be canceled.
-
createEventParamWrapper
Wraps the event parameter object in aDhApiCancelableEventParamorDhApiEventParamdepending on if it should allow cancellation or not.- Type Parameters:
T- the event parameter type- Parameters:
event- the event instanceparameter- the event's parameter object- Returns:
- the event parameter wrapped in a
DhApiCancelableEventParamorDhApiEventParam
-