KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.util.Arrays JavaDoc;
26 import java.util.logging.Level JavaDoc;
27 import java.lang.reflect.Method JavaDoc;
28 import com.sun.enterprise.deployment.EjbDescriptor;
29 import com.sun.enterprise.tools.verifier.Result;
30 import com.sun.enterprise.tools.verifier.Verifier;
31 import com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor;
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 number and types of arguments
40  */

41 abstract public class InterfaceMatchMethodArgs extends InterfaceMethodTest {
42     /**
43      * <p>
44      * run an individual verifier test against a declared method of the
45      * local 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,
53                                               Method JavaDoc method,
54                                               Result result) {
55         
56         boolean businessMethodFound, signaturesMatch;
57         ComponentNameConstructor compName = null;
58         
59         try {
60             compName = getVerifierContext().getComponentNameConstructor();
61             // retrieve the EJB Class Methods
62
ClassLoader JavaDoc jcl = getVerifierContext().getClassLoader();
63             Class JavaDoc EJBClass = Class.forName(descriptor.getEjbClassName(), false, jcl);
64             Class JavaDoc[] methodParameterTypes = method.getParameterTypes();
65             
66             // start do while loop here....
67
do {
68                 // try and find the business method in the EJB Class Methods
69
businessMethodFound = false;
70                 signaturesMatch = false;
71                 for (Method JavaDoc businessMethod : EJBClass.getDeclaredMethods()) {
72                     if (method.getName().equals(businessMethod.getName())) {
73                         businessMethodFound = true;
74                         // check the rest of the signature
75
Class JavaDoc[] businessMethodParameterTypes = businessMethod.getParameterTypes();
76                         if (Arrays.equals(methodParameterTypes,businessMethodParameterTypes)) {
77                             signaturesMatch = true;
78                             break;
79                         } // if the bean & local/remote interface method param values match
80
} else {
81                         continue;
82                         
83                     } // if the bean & local/remote interface method match
84
} // for all the bean class business methods
85

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