KickJava   Java API By Example, From Geeks To Geeks.

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


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;
24
25 import com.sun.enterprise.deployment.EjbDescriptor;
26 import com.sun.enterprise.tools.verifier.Result;
27 import com.sun.enterprise.tools.verifier.Verifier;
28 import com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor;
29 import com.sun.enterprise.tools.verifier.tests.ejb.RmiIIOPUtils;
30
31 import java.lang.reflect.Method JavaDoc;
32 import java.util.logging.Level JavaDoc;
33
34 /**
35  * Local/remote interface/business matching methods exceptions test.
36  * Verify the following:
37  *
38  * For each method defined in the local/remote interface, there must be a matching
39  * method in the enterprise Bean's class. The matching method must have:
40  * . All the exceptions defined in the throws clause of the matching method
41  * of the enterprise Bean class must be defined in the throws clause of
42  * the method of the local/remote interface.
43  */

44 abstract public class InterfaceMatchMethodException extends InterfaceMethodTest {
45     /**
46      * <p>
47      * run an individual verifier test against a declared method of the
48      * local/remote interface.
49      * </p>
50      *
51      * @param descriptor the deployment descriptor for the bean
52      * @param method the method to run the test on
53      * @return true if the test passes
54      */

55     
56     protected boolean runIndividualMethodTest(EjbDescriptor descriptor, Method JavaDoc method, Result result) {
57         
58         boolean businessMethodFound, exceptionsMatch;
59         ComponentNameConstructor compName = null;
60         
61         try {
62             compName = getVerifierContext().getComponentNameConstructor();
63             // retrieve the EJB Class Methods
64
ClassLoader JavaDoc jcl = getVerifierContext().getClassLoader();
65             Class JavaDoc EJBClass = Class.forName(descriptor.getEjbClassName(), false, jcl);
66             Class JavaDoc[] methodExceptionTypes = method.getExceptionTypes();
67             
68             // start do while loop here....
69
do {
70                 Method JavaDoc [] businessMethods = EJBClass.getDeclaredMethods();
71                 
72                 // try and find the business method in the EJB Class Methods
73
businessMethodFound = false;
74                 exceptionsMatch = false;
75                 for (Method JavaDoc businessMethod : businessMethods) {
76                     if (method.getName().equals(businessMethod.getName())) {
77                         businessMethodFound = true;
78                         // check the rest of the exceptions
79
Class JavaDoc[] businessMethodExceptionTypes = businessMethod.getExceptionTypes();
80                         if (RmiIIOPUtils.isEjbFindMethodExceptionsSubsetOfFindMethodExceptions(businessMethodExceptionTypes,methodExceptionTypes)) {
81                             exceptionsMatch = true;
82                             break;
83                         } // if the bean & local interface method exceptions match
84
} else {
85                         continue;
86                     }
87                 } // for all the bean class business methods
88

89                 // now display the appropriate results for this particular business
90
// method
91
if (businessMethodFound && exceptionsMatch) {
92                     addGoodDetails(result, compName);
93                     result.addGoodDetails(smh.getLocalString
94                             (getClass().getName() + ".passed",
95                             "The corresponding business method with matching " +
96                             "exceptions was found."));
97                     return true;
98                 } else if (businessMethodFound && !exceptionsMatch) {
99                     logger.log(Level.FINE, getClass().getName() + ".debug1",
100                             new Object JavaDoc[] {method.getDeclaringClass().getName(),method.getName()});
101                     logger.log(Level.FINE, getClass().getName() + ".debug3",
102                             new Object JavaDoc[] {method.getName()});
103                     logger.log(Level.FINE, getClass().getName() + ".debug2");
104                 }
105                 
106             } while (((EJBClass = EJBClass.getSuperclass()) != null) && (!(businessMethodFound && exceptionsMatch)));
107             
108             
109             if (!exceptionsMatch) {
110                 addErrorDetails(result, compName);
111                 result.addErrorDetails(smh.getLocalString
112                         (getClass().getName() + ".failed",
113                                 "Error: No corresponding business method with matching exceptions was found for method [ {0} ].",
114                                 new Object JavaDoc[] {method.getName()}));
115             }
116         } catch (ClassNotFoundException JavaDoc e) {
117             Verifier.debug(e);
118             addErrorDetails(result, compName);
119             result.failed(smh.getLocalString
120                     (getClass().getName() + ".failedException",
121                     "Error: "+ getInterfaceType() +"interface [ {0} ] does not " +
122                     "exist or is not loadable within bean [ {1} ]",
123                     new Object JavaDoc[] {getClassName(descriptor),descriptor.getName()}));
124         }
125         return false;
126     }
127     
128     private String JavaDoc getClassName(EjbDescriptor descriptor) {
129         return getInterfaceName(descriptor);
130     }
131 }
132
Popular Tags