KickJava   Java API By Example, From Geeks To Geeks.

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


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 import java.lang.reflect.Modifier JavaDoc;
33
34 /**
35  * Home methods must be public and not static
36  *
37  * @author Jerome Dochez
38  * @version
39  */

40 abstract public class HomeMethodModifiers 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 = getVerifierContext().getComponentNameConstructor();
56
57     try {
58         // retrieve the remote interface methods
59
ClassLoader JavaDoc jcl = getVerifierContext().getClassLoader();
60         Class JavaDoc ejbClass = Class.forName(descriptor.getEjbClassName(), false, jcl);
61                                     
62             // Bug: 4952890. first character of this name should be converted to UpperCase.
63
String JavaDoc methodName = method.getName().replaceFirst(method.getName().substring(0,1),
64                                                               method.getName().substring(0,1).toUpperCase());
65             String JavaDoc expectedMethodName = "ejbHome" + methodName;
66             do {
67                 // retrieve the EJB Class Methods
68
m = getMethod(ejbClass, expectedMethodName, method.getParameterTypes());
69         } while (((ejbClass = ejbClass.getSuperclass()) != null) && (m==null));
70
71             if (m != null) {
72                 int modifiers = m.getModifiers();
73                 if (Modifier.isPublic(modifiers) && !Modifier.isStatic(modifiers)) {
74                     addGoodDetails(result, compName);
75                     result.addGoodDetails(smh.getLocalString
76                         (getClass().getName() + ".passed",
77                         "For method [ {1} ] in Home Interface [ {0} ], ejbHome method is public and not static",
78                         new Object JavaDoc[] {method.getDeclaringClass().getName(), method.getName()}));
79             result.setStatus(Result.PASSED);
80                     //return true;
81
} else {
82                     addErrorDetails(result, compName);
83                     result.addErrorDetails(smh.getLocalString
84                         (getClass().getName() + ".notApplicable",
85                         "Error : For method [ {1} ] defined in Home Interface [ {0} ], the ejbHome method is either static or not public",
86                         new Object JavaDoc[] {method.getDeclaringClass().getName(), method.getName()}));
87             result.setStatus(Result.FAILED);
88             // return false;
89
}
90             } else {
91                 addErrorDetails(result, compName);
92                 result.addErrorDetails(smh.getLocalString
93                     (getClass().getName() + ".failed",
94                     "Error : For method [ {1} ] defined in Home Interface [ {0} ], no ejbHome name matching method was found" ,
95                     new Object JavaDoc[] {method.getDeclaringClass().getName(), method.getName()}));
96             result.setStatus(Result.FAILED);
97                 //return true;
98
}
99     } catch (ClassNotFoundException JavaDoc e) {
100         Verifier.debug(e);
101         addErrorDetails(result, compName);
102         result.failed(smh.getLocalString(
103                          getClass().getName() + ".failedException",
104                          "Error: Home interface [ {0} ] does not exist or is not loadable within bean [ {1} ]",
105                          new Object JavaDoc[] {getClassName(descriptor),descriptor.getName()}));
106         //return false;
107
result.setStatus(Result.FAILED);
108     }
109     }
110
111   private String JavaDoc getClassName(EjbDescriptor descriptor) {
112     return getHomeInterfaceName(descriptor);
113     }
114 }
115
Popular Tags