KickJava   Java API By Example, From Geeks To Geeks.

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


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
30 import java.lang.reflect.Method JavaDoc;
31 import java.util.logging.Level JavaDoc;
32
33 /**
34  * Local or remote interface/business matching methods return type test.
35  * Verify the following:
36  *
37  * For each method defined in the local or remote interface, there must be a matching
38  * method in the enterprise Bean's class. The matching method must have:
39  * . The same return type.
40  */

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

52     protected boolean runIndividualMethodTest(EjbDescriptor descriptor, Method JavaDoc method, Result result) {
53         
54         boolean businessMethodFound, returnMatch;
55         ComponentNameConstructor compName = null;
56         
57         try {
58             compName = getVerifierContext().getComponentNameConstructor();
59             Class JavaDoc methodReturnType = method.getReturnType();
60             // retrieve the EJB Class Methods
61
ClassLoader JavaDoc jcl = getVerifierContext().getClassLoader();
62             Class JavaDoc EJBClass = Class.forName(descriptor.getEjbClassName(), false, jcl);
63             
64             // start do while loop here....
65
do {
66                 Method JavaDoc [] businessMethods = EJBClass.getDeclaredMethods();
67                 
68                 // try and find the business method in the EJB Class Methods
69
businessMethodFound = false;
70                 returnMatch = false;
71                 for (Method JavaDoc businessMethod : businessMethods) {
72                     if (method.getName().equals(businessMethod.getName())) {
73                         businessMethodFound = true;
74                         Class JavaDoc businessMethodReturnType = businessMethod.getReturnType();
75                         if (methodReturnType.equals(businessMethodReturnType)) {
76                             returnMatch = true;
77                             break;
78                         } // if the bean & local/remote interface method return value matches
79
} else {
80                         continue;
81                         
82                     } // if the bean & local/remote interface method match
83
} // for all the bean class business methods
84

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