protected boolean isSystemUncheckedException(Throwable exception) { if ( exception != null && ( exception instanceof RuntimeException || exception instanceof Error || exception instanceof RemoteException ) ) { Class clazz = exception.getClass(); String exceptionClassName = clazz.getName(); Map<String, EjbApplicationExceptionInfo> appExceptions = ejbDescriptor.getEjbBundleDescriptor().getApplicationExceptions(); while (clazz != null) { String eClassName = clazz.getName(); if (appExceptions.containsKey(eClassName)) { if( exceptionClassName.equals(eClassName)) { // Exact exception is specified as an ApplicationException return false; } else { // Superclass exception is not inherited return !appExceptions.get(eClassName).getInherited(); } } clazz = clazz.getSuperclass(); } return true; } else { return false; } }
/** * Returns true if this exception is an Application Exception and * it requires rollback of the transaction in which it was thrown. */ protected boolean isAppExceptionRequiringRollback (Throwable exception) { boolean appExceptionRequiringRollback = false; if ( exception != null ) { Class clazz = exception.getClass(); String exceptionClassName = clazz.getName(); Map<String, EjbApplicationExceptionInfo> appExceptions = ejbDescriptor.getEjbBundleDescriptor().getApplicationExceptions(); while (clazz != null) { String eClassName = clazz.getName(); if (appExceptions.containsKey(eClassName)) { if( exceptionClassName.equals(eClassName) || appExceptions.get(eClassName).getInherited() == true) { // Exact exception is specified as an ApplicationException // or superclass exception is inherited appExceptionRequiringRollback = appExceptions.get(eClassName).getRollback(); } break; } clazz = clazz.getSuperclass(); } } return appExceptionRequiringRollback; }
bundleDescriptor.getApplicationExceptions().values()) {
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; EjbBundleDescriptor ejbBundle = 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()); // Set on descriptor unless the same application exception was defined // in ejb-jar.xml if( !ejbBundle.getApplicationExceptions().containsKey(annotatedClass.getName()) ) { ejbBundle.addApplicationException(appExcInfo); } } return getDefaultProcessedResult(); }