All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.blazebit.storage.testsuite.common.EjbAwareThrowableProcessingInterceptor Maven / Gradle / Ivy

There is a newer version: 0.3.3
Show newest version
package com.blazebit.storage.testsuite.common;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

import javax.ejb.EJBException;
import javax.transaction.RollbackException;

import com.blazebit.exception.ExceptionUtils;
import com.blazebit.storage.core.api.StorageException;
import com.googlecode.catchexception.internal.ExceptionProcessingInterceptor;

public class EjbAwareThrowableProcessingInterceptor extends ExceptionProcessingInterceptor {

    @SuppressWarnings("unchecked")
    private static final Class[] UNWRAP_WITH_CORE = (Class[]) new Class[]{InvocationTargetException.class, EJBException.class, RollbackException.class, StorageException.class};
    @SuppressWarnings("unchecked")
    private static final Class[] UNWRAP_WITHOUT_CORE = (Class[]) new Class[]{InvocationTargetException.class, EJBException.class, RollbackException.class};
    
    private final Class[] unwraps;
    
    /**
     * @param target
     * @param clazz
     * @param assertThrowable
     */
    public EjbAwareThrowableProcessingInterceptor(Object target, Class clazz) {
        super(target, clazz, true);
        unwraps = StorageException.class.isAssignableFrom(clazz) ? UNWRAP_WITHOUT_CORE : UNWRAP_WITH_CORE;
    }
    
    @Override
    protected Object afterInvocationThrowsException(Exception e, Method method)
    		throws Error, Exception {
    	Exception realException = (Exception) ExceptionUtils.unwrap(e, unwraps);
        
        if (realException == null) {
            realException = e;
        }
        
        return super.afterInvocationThrowsException(realException, method);
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy