KickJava   Java API By Example, From Geeks To Geeks.

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


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.homeintf;
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.ClassLoader JavaDoc;
31 import java.lang.reflect.Method JavaDoc;
32
33 /**
34  * For each method defined in the home interface, there must be a matching
35  * method in the enterprise Bean's class prefixed with ejbHome.
36  *
37  * @author Jerome Dochez
38  * @version
39  */

40 abstract public class HomeMethodNameMatch extends HomeMethodTest {
41     
42     /**
43      * <p>
44      * run an individual home method test
45      * </p>
46      *
47      * @param method the home method to test
48      * @param descriptor the deployment descriptor for the entity bean
49      * @param result the result object
50      */

51
52     protected void runIndividualHomeMethodTest(Method JavaDoc method, EjbDescriptor descriptor, Result result) {
53         
54         Method JavaDoc m;
55     ComponentNameConstructor compName = null;
56     try {
57         compName = getVerifierContext().getComponentNameConstructor();
58         // retrieve the remote interface methods
59
ClassLoader JavaDoc jcl = getVerifierContext().getClassLoader();
60         Class JavaDoc ejbClass = Class.forName(descriptor.getEjbClassName(), false, jcl);
61             // Bug: 4952890. first character of this name should be converted to UpperCase.
62
String JavaDoc methodName = method.getName().replaceFirst(method.getName().substring(0,1),
63                                                               method.getName().substring(0,1).toUpperCase());
64             String JavaDoc expectedMethodName = "ejbHome" + methodName;
65             do {
66                 // retrieve the EJB Class Methods
67
m = getMethod(ejbClass, expectedMethodName, method.getParameterTypes());
68             } while (((ejbClass = ejbClass.getSuperclass()) != null) && (m==null));
69
70             if (m != null) {
71                 // now display the appropriate results for this particular business
72
// method
73
addGoodDetails(result, compName);
74                 result.passed(smh.getLocalString
75                     (getClass().getName() + ".passed",
76                     "For method [ {1} ] in Home Interface [ {0} ], a ejbHome<METHOD> name matching method was found",
77                     new Object JavaDoc[] {method.getDeclaringClass().getName(), method.getName()}));
78             } else {
79                 addErrorDetails(result, compName);
80                 result.failed(smh.getLocalString
81                     (getClass().getName() + ".failed",
82                     "Error : For method [ {1} ] defined in Home Interface [ {0} ], no ejbHome<METHOD> name matching method was found" ,
83                     new Object JavaDoc[] {method.getDeclaringClass().getName(), method.getName()}));
84         }
85     } catch (ClassNotFoundException JavaDoc e) {
86         Verifier.debug(e);
87         addErrorDetails(result, compName);
88         result.failed(smh.getLocalString(
89                getClass().getName() + ".failedException",
90                "Error: Home interface [ {0} ] does not exist or is not loadable within bean [ {1} ]",
91                new Object JavaDoc[] {getClassName(descriptor),descriptor.getName()}));
92     }
93     }
94
95     private String JavaDoc getClassName(EjbDescriptor descriptor) {
96     return getHomeInterfaceName(descriptor);
97     }
98 }
99
Popular Tags