Search in sources :

Example 1 with EzyExceptionHandlerImplementer

use of com.tvd12.ezyfoxserver.support.asm.EzyExceptionHandlerImplementer in project ezyfox-server by youngmonkeys.

the class EzyExceptionHandlersImplementer method implement.

public Map<Class<?>, EzyUncaughtExceptionHandler> implement(Object exceptionHandler) {
    Map<Class<?>, EzyUncaughtExceptionHandler> handlers = new HashMap<>();
    EzyExceptionHandlerProxy proxy = new EzyExceptionHandlerProxy(exceptionHandler);
    for (EzyExceptionHandlerMethod method : proxy.getExceptionHandlerMethods()) {
        EzyExceptionHandlerImplementer implementer = newImplementer(proxy, method);
        EzyUncaughtExceptionHandler handler = implementer.implement();
        for (Class<?> exceptionClass : method.getExceptionClasses()) {
            handlers.put(exceptionClass, handler);
        }
    }
    return handlers;
}
Also used : EzyExceptionHandlerProxy(com.tvd12.ezyfoxserver.support.reflect.EzyExceptionHandlerProxy) HashMap(java.util.HashMap) EzyExceptionHandlerMethod(com.tvd12.ezyfoxserver.support.reflect.EzyExceptionHandlerMethod) EzyUncaughtExceptionHandler(com.tvd12.ezyfoxserver.support.handler.EzyUncaughtExceptionHandler)

Example 2 with EzyExceptionHandlerImplementer

use of com.tvd12.ezyfoxserver.support.asm.EzyExceptionHandlerImplementer in project ezyfox-server by youngmonkeys.

the class EzyExceptionHandlerImplementerTest method testFailedCase.

@Test(expectedExceptions = IllegalStateException.class)
public void testFailedCase() throws Exception {
    EzyExceptionHandlerProxy handlerProxy = new EzyExceptionHandlerProxy(new ExceptionHandlerFail());
    EzyExceptionHandlerMethod method = new EzyExceptionHandlerMethod(new EzyMethod(ExceptionHandlerFail.class.getDeclaredMethod("handle", Exception.class, int.class)));
    new EzyExceptionHandlerImplementer(handlerProxy, method) {

        @SuppressWarnings("rawtypes")
        @Override
        protected EzyUncaughtExceptionHandler doImplement() {
            throw new IllegalStateException("test");
        }
    }.implement();
}
Also used : EzyExceptionHandlerImplementer(com.tvd12.ezyfoxserver.support.asm.EzyExceptionHandlerImplementer) EzyExceptionHandlerProxy(com.tvd12.ezyfoxserver.support.reflect.EzyExceptionHandlerProxy) EzyExceptionHandlerMethod(com.tvd12.ezyfoxserver.support.reflect.EzyExceptionHandlerMethod) EzyUncaughtExceptionHandler(com.tvd12.ezyfoxserver.support.handler.EzyUncaughtExceptionHandler) EzyMethod(com.tvd12.ezyfox.reflect.EzyMethod) Test(org.testng.annotations.Test)

Aggregations

EzyUncaughtExceptionHandler (com.tvd12.ezyfoxserver.support.handler.EzyUncaughtExceptionHandler)2 EzyExceptionHandlerMethod (com.tvd12.ezyfoxserver.support.reflect.EzyExceptionHandlerMethod)2 EzyExceptionHandlerProxy (com.tvd12.ezyfoxserver.support.reflect.EzyExceptionHandlerProxy)2 EzyMethod (com.tvd12.ezyfox.reflect.EzyMethod)1 EzyExceptionHandlerImplementer (com.tvd12.ezyfoxserver.support.asm.EzyExceptionHandlerImplementer)1 HashMap (java.util.HashMap)1 Test (org.testng.annotations.Test)1