Hook up the API events (some are missing parameter objects)

This commit is contained in:
James Seibel
2022-09-13 21:44:00 -05:00
parent f6a1901ef8
commit 92a98aba96
5 changed files with 61 additions and 19 deletions
@@ -2,15 +2,19 @@ package com.seibel.lod.api.methods.events;
import com.seibel.lod.api.items.objects.DhApiResult;
import com.seibel.lod.api.methods.events.interfaces.IDhApiEvent;
import com.seibel.lod.core.interfaces.dependencyInjection.ApiCoreInjectors;
import com.seibel.lod.core.interfaces.dependencyInjection.IDhApiEventInjector;
/**
* Handles adding/removing event handlers.
*
* @author James Seibel
* @version 2022-9-8
* @version 2022-9-13
*/
public class DhApiEventRegister
{
private static final IDhApiEventInjector EVENT_INJECTOR = ApiCoreInjectors.getInstance().eventInjector;
/**
* Registers the given event handler. <Br>
* Only one eventHandler of a specific class can be registered at a time.
@@ -21,7 +25,7 @@ public class DhApiEventRegister
{
try
{
// DhApiEventInjector.INSTANCE.bind(eventInterface, eventHandlerImplementation);
EVENT_INJECTOR.bind(eventInterface, eventHandlerImplementation);
return DhApiResult.createSuccess();
}
catch (IllegalStateException e)
@@ -37,14 +41,14 @@ public class DhApiEventRegister
*/
public static DhApiResult off(Class<? extends IDhApiEvent> eventInterface, Class<IDhApiEvent> eventHandlerClass)
{
// if (DhApiEventInjector.INSTANCE.unbind(eventInterface, eventHandlerClass))
// {
// return DhApiResult.createSuccess();
// }
// else
// {
if (EVENT_INJECTOR.unbind(eventInterface, eventHandlerClass))
{
return DhApiResult.createSuccess();
}
else
{
return DhApiResult.createFail("No event handler [" + eventHandlerClass.getSimpleName() + "] was bound for the event [" + eventInterface.getSimpleName() + "].");
// }
}
}
}
@@ -0,0 +1,32 @@
package com.seibel.lod.core.interfaces.dependencyInjection;
import com.seibel.lod.core.DependencyInjection.DhApiEventInjector;
/**
* This singleton holds the dependency injectors used
* between Core and the API.
* IE: this is how Core and the API talk to each other.
*
* @author James Seibel
* @version 2022-9-13
*/
public class ApiCoreInjectors
{
private static ApiCoreInjectors INSTANCE;
public final IDhApiEventInjector eventInjector = new DhApiEventInjector();
public static ApiCoreInjectors getInstance()
{
if (INSTANCE == null)
{
INSTANCE = new ApiCoreInjectors();
}
return INSTANCE;
}
}
@@ -14,7 +14,7 @@ import java.util.ArrayList;
*/
public class EventInjectorTest
{
// //@Test
// public void testEventDependencies() // this also tests list dependencies since there can be more than one event handler bound per event
// {