KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > deployment > annotation > handlers > ApplicationExceptionHandler


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23 package com.sun.enterprise.deployment.annotation.handlers;
24
25 import java.lang.annotation.Annotation JavaDoc;
26 import java.lang.reflect.AnnotatedElement JavaDoc;
27
28 import javax.ejb.ApplicationException JavaDoc;
29
30 import com.sun.enterprise.deployment.EjbDescriptor;
31 import com.sun.enterprise.deployment.EjbBundleDescriptor;
32 import com.sun.enterprise.deployment.EjbApplicationExceptionInfo;
33
34 import com.sun.enterprise.deployment.annotation.HandlerProcessingResult;
35 import com.sun.enterprise.deployment.annotation.AnnotationInfo;
36 import com.sun.enterprise.deployment.annotation.AnnotatedElementHandler;
37 import com.sun.enterprise.deployment.annotation.AnnotationProcessorException;
38 import com.sun.enterprise.deployment.annotation.context.EjbBundleContext;
39
40 /**
41  * Handles @javax.ejb.ApplicationException
42  */

43 public class ApplicationExceptionHandler extends AbstractHandler {
44     
45     public ApplicationExceptionHandler() {
46     }
47     
48     /**
49      * @return the annoation type this annotation handler is handling
50      */

51     public Class JavaDoc<? extends Annotation JavaDoc> getAnnotationType() {
52         return ApplicationException JavaDoc.class;
53     }
54
55      public HandlerProcessingResult processAnnotation
56          (AnnotationInfo ainfo) throws AnnotationProcessorException {
57
58         AnnotatedElement JavaDoc ae = ainfo.getAnnotatedElement();
59         Annotation JavaDoc annotation = ainfo.getAnnotation();
60
61         AnnotatedElementHandler aeHandler =
62             ainfo.getProcessingContext().getHandler();
63         
64
65         if (aeHandler instanceof EjbBundleContext) {
66             EjbBundleContext ejbBundleContext = (EjbBundleContext)aeHandler;
67             
68             EjbBundleDescriptor ejbBundle = ejbBundleContext.getDescriptor();
69
70             ApplicationException JavaDoc appExcAnn = (ApplicationException JavaDoc) annotation;
71
72             EjbApplicationExceptionInfo appExcInfo = new
73                 EjbApplicationExceptionInfo();
74             Class JavaDoc annotatedClass = (Class JavaDoc) ae;
75             appExcInfo.setExceptionClassName(annotatedClass.getName());
76             appExcInfo.setRollback(appExcAnn.rollback());
77
78             ejbBundle.addApplicationException(appExcInfo);
79
80         }
81
82         return getDefaultProcessedResult();
83
84      }
85
86     protected boolean supportTypeInheritance() {
87         return true;
88     }
89 }
90
Popular Tags