KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > verifier > tests > ejb > messagebean > RemoteExceptionNotThrown


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.tools.verifier.tests.ejb.messagebean;
24
25 import com.sun.enterprise.tools.verifier.Result;
26 import com.sun.enterprise.tools.verifier.Verifier;
27 import com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor;
28 import com.sun.enterprise.deployment.EjbMessageBeanDescriptor;
29
30 import java.lang.reflect.Method JavaDoc;
31
32 /**
33  * Message listener methods should not throw java.rmi.RemoteException.
34  * @author Vikas Awasthi
35  */

36 public class RemoteExceptionNotThrown extends MessageBeanTest {
37
38     public Result check(EjbMessageBeanDescriptor descriptor) {
39         Result result = getInitializedResult();
40         ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
41         ClassLoader JavaDoc cl = getVerifierContext().getClassLoader();
42         try {
43             Method JavaDoc[] methods = descriptor.getMessageListenerInterfaceMethods(cl);
44             for (int i = 0; i < methods.length; i++) {
45                 if(containsRemote(methods[i].getExceptionTypes())) {
46                     addErrorDetails(result, compName);
47                     result.failed(smh.getLocalString
48                                     (getClass().getName()+".failed",
49                                     "Method [ {0} ] throws RemoteException",
50                                     new Object JavaDoc[] {methods[i]}));
51                 }
52             }
53         } catch (NoSuchMethodException JavaDoc e) {
54             Verifier.debug(e);
55             addErrorDetails(result, compName);
56             result.failed(smh.getLocalString
57                             (getClass().getName()+".failed1",
58                             "[ {0} ]", new Object JavaDoc[]{e.getMessage()}));
59         }
60         
61         if(result.getStatus() != Result.FAILED) {
62             addGoodDetails(result, compName);
63             result.passed(smh.getLocalString
64                             (getClass().getName() + ".passed",
65                             "Valid message listener method(s)."));
66         }
67         return result;
68     }
69     
70     /** returns true if one of the exceptions is RemoteException*/
71     private boolean containsRemote(Class JavaDoc[] exceptions) {
72         for (int i = 0; i < exceptions.length; i++)
73             if(exceptions[i].getName().equals("java.rmi.RemoteException"))
74                 return true;
75         
76         return false;
77     }
78 }
79
Popular Tags