KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > verifier > tests > ejb > ejb30 > CallbackMethodException


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
24 package com.sun.enterprise.tools.verifier.tests.ejb.ejb30;
25
26 import com.sun.enterprise.tools.verifier.tests.ejb.EjbTest;
27 import com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor;
28 import com.sun.enterprise.tools.verifier.Result;
29 import com.sun.enterprise.deployment.EjbDescriptor;
30 import com.sun.enterprise.deployment.EjbSessionDescriptor;
31 import com.sun.enterprise.deployment.LifecycleCallbackDescriptor;
32 import com.sun.enterprise.deployment.EjbInterceptor;
33
34 import java.util.Set JavaDoc;
35 import java.util.HashSet JavaDoc;
36 import java.lang.reflect.Method JavaDoc;
37
38 /**
39  * Lifecycle callback interceptor methods must not throw application exceptions.
40  *
41  * Any exception other than derived from java.lang.RuntimeException or
42  * java.rmi.RemoteException is an application exception.
43  *
44  * @author Vikas Awasthi
45  */

46 public class CallbackMethodException extends EjbTest {
47
48     public Result check(EjbDescriptor descriptor) {
49         Result result = getInitializedResult();
50         ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
51         ClassLoader JavaDoc cl = getVerifierContext().getClassLoader();
52
53         Set JavaDoc<LifecycleCallbackDescriptor> callbackDescs =
54                                         new HashSet JavaDoc<LifecycleCallbackDescriptor>();
55         
56         for (EjbInterceptor interceptor : descriptor.getInterceptorClasses()) {
57             callbackDescs.addAll(interceptor.getPostConstructDescriptors());
58             callbackDescs.addAll(interceptor.getPreDestroyDescriptors());
59             callbackDescs.addAll(interceptor.getCallbackDescriptors(
60                         LifecycleCallbackDescriptor.CallbackType.PRE_PASSIVATE));
61             callbackDescs.addAll(interceptor.getCallbackDescriptors(
62                         LifecycleCallbackDescriptor.CallbackType.POST_ACTIVATE));
63         }
64
65         if(descriptor.hasPostConstructMethod())
66             callbackDescs.addAll(descriptor.getPostConstructDescriptors());
67         if(descriptor.hasPreDestroyMethod())
68             callbackDescs.addAll(descriptor.getPreDestroyDescriptors());
69         
70         // session descriptor has two extra interceptor methods.
71
if(descriptor instanceof EjbSessionDescriptor) {
72             EjbSessionDescriptor ejbSessionDescriptor = ((EjbSessionDescriptor)descriptor);
73             if(ejbSessionDescriptor.hasPostActivateMethod())
74                 callbackDescs.addAll(ejbSessionDescriptor.getPostActivateDescriptors());
75             if(ejbSessionDescriptor.hasPrePassivateMethod())
76                 callbackDescs.addAll(ejbSessionDescriptor.getPrePassivateDescriptors());
77         }
78
79         for (LifecycleCallbackDescriptor callbackDesc : callbackDescs) {
80             try {
81                 Method JavaDoc method = callbackDesc.getLifecycleCallbackMethodObject(cl);
82                 Class JavaDoc[] excepClasses = method.getExceptionTypes();
83                 for (Class JavaDoc exception : excepClasses) {
84                     if(!(RuntimeException JavaDoc.class.isAssignableFrom(exception) ||
85                             java.rmi.RemoteException JavaDoc.class.isAssignableFrom(exception))) {
86                         addErrorDetails(result, compName);
87                         result.failed(smh.getLocalString
88                                         (getClass().getName() + ".failed",
89                                         "Method [ {0} ] throws an application exception.",
90                                         new Object JavaDoc[] {method}));
91                     }
92                 }
93             } catch (Exception JavaDoc e) {}// will be caught in other tests
94
}
95         
96         if(result.getStatus()!=Result.FAILED) {
97             addGoodDetails(result, compName);
98             result.passed(smh.getLocalString
99                             (getClass().getName() + ".passed",
100                             "Valid Callback methods."));
101         }
102         
103         return result;
104     }
105 }
106
Popular Tags