Search in sources :

Example 1 with ApplicationException

use of javax.ejb.ApplicationException in project Payara by payara.

the class ApplicationExceptionHandler method processAnnotation.

public HandlerProcessingResult processAnnotation(AnnotationInfo ainfo) throws AnnotationProcessorException {
    AnnotatedElement ae = ainfo.getAnnotatedElement();
    Annotation annotation = ainfo.getAnnotation();
    AnnotatedElementHandler aeHandler = ainfo.getProcessingContext().getHandler();
    if (aeHandler instanceof EjbBundleContext) {
        EjbBundleContext ejbBundleContext = (EjbBundleContext) aeHandler;
        EjbBundleDescriptorImpl ejbBundle = (EjbBundleDescriptorImpl) ejbBundleContext.getDescriptor();
        ApplicationException appExcAnn = (ApplicationException) annotation;
        EjbApplicationExceptionInfo appExcInfo = new EjbApplicationExceptionInfo();
        Class annotatedClass = (Class) ae;
        appExcInfo.setExceptionClassName(annotatedClass.getName());
        appExcInfo.setRollback(appExcAnn.rollback());
        appExcInfo.setInherited(appExcAnn.inherited());
        // in ejb-jar.xml
        if (!ejbBundle.getApplicationExceptions().containsKey(annotatedClass.getName())) {
            ejbBundle.addApplicationException(appExcInfo);
        }
    }
    return getDefaultProcessedResult();
}
Also used : ApplicationException(javax.ejb.ApplicationException) EjbBundleContext(com.sun.enterprise.deployment.annotation.context.EjbBundleContext) EjbApplicationExceptionInfo(org.glassfish.ejb.deployment.descriptor.EjbApplicationExceptionInfo) AnnotatedElement(java.lang.reflect.AnnotatedElement) AnnotatedElementHandler(org.glassfish.apf.AnnotatedElementHandler) Annotation(java.lang.annotation.Annotation) EjbBundleDescriptorImpl(org.glassfish.ejb.deployment.descriptor.EjbBundleDescriptorImpl)

Example 2 with ApplicationException

use of javax.ejb.ApplicationException in project tomee by apache.

the class BeanContext method getExceptionType.

public ExceptionType getExceptionType(final Throwable e) {
    // Errors are always system exceptions
    if (!(e instanceof Exception)) {
        return ExceptionType.SYSTEM;
    }
    // check the registered app exceptions
    Class<?> exceptionClass = e.getClass();
    boolean inherited = false;
    while (exceptionClass != Object.class) {
        final ExceptionType type = exceptions.get(exceptionClass);
        if (type == ExceptionType.APPLICATION || type == ExceptionType.APPLICATION_ROLLBACK) {
            return type;
        }
        if (type != null) {
            if (inherited) {
                return ExceptionType.SYSTEM;
            }
            if (type == ExceptionType.APPLICATION_NOT_INHERITED) {
                return ExceptionType.APPLICATION;
            }
            return ExceptionType.APPLICATION_ROLLBACK;
        }
        exceptionClass = exceptionClass.getSuperclass();
        inherited = true;
    }
    // Unregistered - runtime exceptions are system exception and the rest are application exceptions
    final Class<? extends Throwable> eClass = e.getClass();
    final ApplicationException applicationException = eClass.getAnnotation(ApplicationException.class);
    if (applicationException != null) {
        addApplicationException(eClass, applicationException.rollback(), applicationException.inherited());
        return getExceptionType(e);
    }
    if (e instanceof RuntimeException) {
        return ExceptionType.SYSTEM;
    }
    return ExceptionType.APPLICATION;
}
Also used : ExceptionType(org.apache.openejb.core.ExceptionType) ApplicationException(javax.ejb.ApplicationException) ApplicationException(javax.ejb.ApplicationException) ConstructionException(org.apache.xbean.recipe.ConstructionException)

Aggregations

ApplicationException (javax.ejb.ApplicationException)2 EjbBundleContext (com.sun.enterprise.deployment.annotation.context.EjbBundleContext)1 Annotation (java.lang.annotation.Annotation)1 AnnotatedElement (java.lang.reflect.AnnotatedElement)1 ExceptionType (org.apache.openejb.core.ExceptionType)1 ConstructionException (org.apache.xbean.recipe.ConstructionException)1 AnnotatedElementHandler (org.glassfish.apf.AnnotatedElementHandler)1 EjbApplicationExceptionInfo (org.glassfish.ejb.deployment.descriptor.EjbApplicationExceptionInfo)1 EjbBundleDescriptorImpl (org.glassfish.ejb.deployment.descriptor.EjbBundleDescriptorImpl)1