KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > verifier > tests > ejb > intf > localintf > LocalInterfaceRemoteException


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.intf.localintf;
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.tools.verifier.tests.ejb.EjbTest;
29 import com.sun.enterprise.deployment.EjbDescriptor;
30
31 import java.lang.reflect.Method JavaDoc;
32
33 /**
34  * The throws clause of a home method on the local home interface may include
35  * additional application-level exceptions. It must not include the
36  * java.rmi.RemoteException.
37  *
38  * @author Vikas Awasthi
39  */

40 public class LocalInterfaceRemoteException extends EjbTest {
41
42     public Result check(EjbDescriptor descriptor) {
43         Result result = getInitializedResult();
44         ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
45         ClassLoader JavaDoc cl = getVerifierContext().getClassLoader();
46         String JavaDoc localClassName = descriptor.getLocalHomeClassName();
47         if (localClassName!=null) {
48             try {
49                 Class JavaDoc localHome = Class.forName(localClassName, false, cl);
50                 Method JavaDoc[] methods = localHome.getMethods();
51                 for (int i = 0; i < methods.length; i++) {
52                     if(containsRemote(methods[i].getExceptionTypes())) {
53                         addErrorDetails(result, compName);
54                         result.failed(smh.getLocalString
55                                 (getClass().getName()+".failed",
56                                 "Method [ {0} ] throws a RemoteException.",
57                                 new Object JavaDoc[]{methods[i]}));
58                     }
59                 
60                 }
61             } catch (ClassNotFoundException JavaDoc e) {
62                 Verifier.debug(e);
63                 addErrorDetails(result, compName);
64                 result.failed(smh.getLocalString
65                                 (getClass().getName()+".failed1",
66                                 "LocalHome class [ {0} ] not found.",
67                                 new Object JavaDoc[]{localClassName}));
68             }
69         }
70
71         if(result.getStatus() != Result.FAILED) {
72             addGoodDetails(result, compName);
73             result.passed(smh.getLocalString
74                     (getClass().getName() + ".passed",
75                             "Valid LocalInterface."));
76         }
77         return result;
78     }
79     
80     /** returns true if one of the exceptions is RemoteException*/
81     private boolean containsRemote(Class JavaDoc[] exceptions) {
82         for (int i = 0; i < exceptions.length; i++)
83             if(exceptions[i].getName().equals("java.rmi.RemoteException"))
84                 return true;
85         
86         return false;
87     }
88 }
Popular Tags