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();
}
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;
}
Aggregations