KickJava   Java API By Example, From Geeks To Geeks.

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


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;
24
25 import java.lang.reflect.Method JavaDoc;
26
27 import com.sun.enterprise.deployment.EjbDescriptor;
28 import com.sun.enterprise.deployment.EjbEntityDescriptor;
29 import com.sun.enterprise.deployment.EjbSessionDescriptor;
30 import com.sun.enterprise.tools.verifier.Result;
31 import com.sun.enterprise.tools.verifier.Verifier;
32 import com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor;
33
34 /**
35  * The Bean Provider defines the application exceptions in the throws clauses
36  * of the methods of the home interface. An application exception
37  * is an exception defined in the throws clause of a method in the Bean's home
38  * interface, other than java.rmi.RemoteException. An application
39  * exception must not be defined as a subclass of the
40  * java.lang.RuntimeException, or of the java.rmi.RemoteException. These are
41  * reserved for system exceptions.
42  * The javax.ejb.CreateException, javax.ejb.RemoveException,
43  * javax.ejb.FinderException, and subclasses thereof, are considered to be
44  * application exceptions.
45  */

46 public class ApplicationExceptionHomeInterfaceMethods extends EjbTest implements EjbCheck {
47
48     Result result = null;
49     ComponentNameConstructor compName = null;
50
51     /**
52      * The Bean Provider defines the application exceptions in the throws clauses
53      * of the methods of the home interface. An application exception
54      * is an exception defined in the throws clause of a method in the Bean's home
55      * interface, other than java.rmi.RemoteException. An application
56      * exception must not be defined as a subclass of the
57      * java.lang.RuntimeException, or of the java.rmi.RemoteException. These are
58      * reserved for system exceptions.
59      * The javax.ejb.CreateException, javax.ejb.RemoveException,
60      * javax.ejb.FinderException, and subclasses thereof, are considered to be
61      * application exceptions.
62      *
63      * @param descriptor the Enterprise Java Bean deployment descriptor
64      *
65      * @return <code>Result</code> the results for this assertion
66      */

67     public Result check(EjbDescriptor descriptor) {
68
69         result = getInitializedResult();
70         compName = getVerifierContext().getComponentNameConstructor();
71         if ((descriptor instanceof EjbSessionDescriptor) ||
72                 (descriptor instanceof EjbEntityDescriptor)) {
73             if(descriptor.getHomeClassName() != null)
74                 commonToBothInterfaces(descriptor.getHomeClassName(),descriptor);
75             if(descriptor.getLocalHomeClassName() != null)
76                 commonToBothInterfaces(descriptor.getLocalHomeClassName(), descriptor);
77         }
78
79         if(result.getStatus() != Result.FAILED) {
80             addGoodDetails(result, compName);
81             result.passed(smh.getLocalString
82                     (getClass().getName() + ".passed",
83                     "All the methods of Home interface are defined properly"));
84         }
85         return result;
86     }
87
88
89     /**
90      * This method is responsible for the logic of the test. It is called for both local and remote interfaces.
91      * @param descriptor the Enterprise Java Bean deployment descriptor
92      * @param home for the Home Interface of the Ejb
93      * This parameter may be optional depending on the test
94      */

95
96     private void commonToBothInterfaces (String JavaDoc home, EjbDescriptor descriptor) {
97
98         try {
99             Class JavaDoc c = Class.forName(home, false, getVerifierContext().getClassLoader());
100             Class JavaDoc [] methodExceptionTypes;
101
102             for(Method JavaDoc methods : c.getDeclaredMethods()) {
103                 methodExceptionTypes = methods.getExceptionTypes();
104                 // methods must also throw java.rmi.RemoteException
105
if (!(EjbUtils.isValidApplicationException(methodExceptionTypes))) {
106                     addErrorDetails(result, compName);
107                     result.failed(smh.getLocalString
108                             (getClass().getName() + ".failed",
109                             "For the Interface [ {0} ] Method [ {1} ] does" +
110                             " not throw valid application exceptions",
111                             new Object JavaDoc[] {home, methods.getName()}));
112                 }
113             } // for all the methods within the home interface class, loop
114

115         } catch (Exception JavaDoc e) {
116             Verifier.debug(e);
117             addErrorDetails(result, compName);
118             result.failed(smh.getLocalString
119                     (getClass().getName() + ".failedException",
120                     "Error: Home interface [ {0} ] does not exist or is" +
121                     " not loadable within bean [ {1} ]",
122                     new Object JavaDoc[] {home, descriptor.getName()}));
123         }
124     }
125 }
126
Popular Tags