KickJava   Java API By Example, From Geeks To Geeks.

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


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.tools.verifier.Verifier;
30 import com.sun.enterprise.deployment.EjbDescriptor;
31
32 import java.lang.reflect.Method JavaDoc;
33 import java.util.Set JavaDoc;
34
35 /**
36  * The methods of the business interface may declare arbitrary application
37  * exceptions. However, the methods of the business interface should not throw
38  * the java.rmi.RemoteException, even if the interface is a remote business
39  * interface or the bean class is annotated WebService or the method as
40  * WebMethod.
41  * The methods of the business interface may only throw the
42  * java.rmi.RemoteException if the interface extends java.rmi.Remote.
43  *
44  * @author Vikas Awasthi
45  */

46 public class BusinessInterfaceException extends EjbTest {
47
48     public Result check(EjbDescriptor descriptor) {
49         Result result = getInitializedResult();
50         ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
51         
52         Set JavaDoc<String JavaDoc> localAndRemoteClassNames = descriptor.getLocalBusinessClassNames();
53         localAndRemoteClassNames.addAll(descriptor.getRemoteBusinessClassNames());
54         
55         for (String JavaDoc localOrRemoteClass : localAndRemoteClassNames)
56             checkForRemoteException(localOrRemoteClass,result,compName);
57
58         if(result.getStatus() != Result.WARNING) {
59             addGoodDetails(result, compName);
60             result.passed(smh.getLocalString
61                             (getClass().getName() + ".passed",
62                             "Business interface(s) if any are valid."));
63         }
64         return result;
65     }
66     
67     private void checkForRemoteException(String JavaDoc className,
68                                         Result result,
69                                         ComponentNameConstructor compName) {
70         try {
71             Class JavaDoc c = Class.forName(className,
72                                     false,
73                                     getVerifierContext().getClassLoader());
74             // do not check further if the business interface extends java.rmi.Remote
75
if(java.rmi.Remote JavaDoc.class.isAssignableFrom(c))
76                 return;
77             Method JavaDoc[] methods = c.getMethods();
78             for (Method JavaDoc method : methods) {
79                 Class JavaDoc[] exceptions = method.getExceptionTypes();
80                 for (Class JavaDoc exception : exceptions) {
81                     if(java.rmi.RemoteException JavaDoc.class.isAssignableFrom(exception)) {
82                         addWarningDetails(result, compName);
83                         result.warning(smh.getLocalString
84                                         (getClass().getName() + ".warning",
85                                         "java.rmi.RemoteException is thrown " +
86                                         "in method [ {0} ] of business interface [ {1} ]",
87                                         new Object JavaDoc[] {method.getName(), className}));
88                     }
89                 }
90             }
91         } catch (ClassNotFoundException JavaDoc e) {
92             Verifier.debug(e);
93             addErrorDetails(result, compName);
94             result.failed(smh.getLocalString
95                             (getClass().getName() + ".failed1",
96                             "[ {0} ] not found.",
97                             new Object JavaDoc[] {className}));
98         }
99     }
100 }
101
Popular Tags