KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > verifier > tests > ejb > session > ejbcreatemethod > EjbCreateMethodName


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.session.ejbcreatemethod;
24
25 import com.sun.enterprise.tools.verifier.tests.ejb.EjbTest;
26 import java.lang.ClassLoader JavaDoc;
27 import com.sun.enterprise.tools.verifier.tests.*;
28 import javax.ejb.SessionBean JavaDoc;
29 import java.lang.reflect.*;
30 import com.sun.enterprise.deployment.EjbDescriptor;
31 import com.sun.enterprise.deployment.EjbSessionDescriptor;
32 import com.sun.enterprise.tools.verifier.*;
33 import com.sun.enterprise.tools.verifier.tests.ejb.EjbCheck;
34
35 /**
36  * Session Bean's ejbCreate(...) methods name test.
37  * Each session Bean class must define one or more ejbCreate(...) methods.
38  * The number and signatures of a session Bean's create methods are specific
39  * to each EJB class. The method signatures must follow these rules:
40  *
41  * The method name must be ejbCreate.
42  *
43  */

44 public class EjbCreateMethodName extends EjbTest implements EjbCheck {
45
46
47     /**
48      * Session Bean's ejbCreate(...) methods name test.
49      * Each session Bean class must define one or more ejbCreate(...) methods.
50      * The number and signatures of a session Bean's create methods are specific
51      * to each EJB class. The method signatures must follow these rules:
52      *
53      * The method name must be ejbCreate.
54      *
55      * @param descriptor the Enterprise Java Bean deployment descriptor
56      *
57      * @return <code>Result</code> the results for this assertion
58      */

59     public Result check(EjbDescriptor descriptor) {
60
61     Result result = getInitializedResult();
62     ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
63
64     if (descriptor instanceof EjbSessionDescriptor) {
65         boolean oneFailed = false;
66         try {
67         Context context = getVerifierContext();
68         ClassLoader JavaDoc jcl = context.getClassLoader();
69         Class JavaDoc c = Class.forName(descriptor.getEjbClassName(), false, getVerifierContext().getClassLoader());
70
71         int foundAtLeastOne = 0;
72                 // start do while loop here....
73
do {
74             Method [] methods = c.getDeclaredMethods();
75             for (int i = 0; i < methods.length; i++) {
76             // The method name must be ejbCreate.
77
if (methods[i].getName().startsWith("ejbCreate")) {
78                 foundAtLeastOne++;
79
80                 // now display the appropriate results for this particular ejbCreate
81
// method
82
result.addGoodDetails(smh.getLocalString
83                           ("tests.componentNameConstructor",
84                            "For [ {0} ]",
85                            new Object JavaDoc[] {compName.toString()}));
86                 result.addGoodDetails(smh.getLocalString
87                           (getClass().getName() + ".debug1",
88                            "For EJB Class [ {0} ] method [ {1} ]",
89                            new Object JavaDoc[] {descriptor.getEjbClassName(),methods[i].getName()}));
90                 result.addGoodDetails(smh.getLocalString
91                           (getClass().getName() + ".passed",
92                            "[ {0} ] declares [ {1} ] method.",
93                            new Object JavaDoc[] {descriptor.getEjbClassName(),methods[i].getName()}));
94             }
95             }
96                 } while (((c = c.getSuperclass()) != null) && (foundAtLeastOne == 0));
97         
98         if (foundAtLeastOne == 0){
99             result.addErrorDetails(smh.getLocalString
100                        ("tests.componentNameConstructor",
101                         "For [ {0} ]",
102                         new Object JavaDoc[] {compName.toString()}));
103             result.failed(smh.getLocalString
104                   (getClass().getName() + ".failed",
105                    "Error: [ {0} ] does not properly declare at least one ejbCreate(...) method. [ {1} ] is not a valid bean.",
106                    new Object JavaDoc[] {descriptor.getEjbClassName(),descriptor.getEjbClassName()}));
107             oneFailed = true;
108         }
109         } catch (ClassNotFoundException JavaDoc e) {
110         Verifier.debug(e);
111         result.addErrorDetails(smh.getLocalString
112                        ("tests.componentNameConstructor",
113                     "For [ {0} ]",
114                     new Object JavaDoc[] {compName.toString()}));
115         result.failed(smh.getLocalString
116                   (getClass().getName() + ".failedException",
117                    "Error: [ {0} ] class not found.",
118                    new Object JavaDoc[] {descriptor.getEjbClassName()}));
119         oneFailed = true;
120         }
121
122         if (oneFailed) {
123         result.setStatus(result.FAILED);
124         } else {
125         result.setStatus(result.PASSED);
126         }
127
128         return result;
129  
130     } else {
131         result.addNaDetails(smh.getLocalString
132                 ("tests.componentNameConstructor",
133                  "For [ {0} ]",
134                  new Object JavaDoc[] {compName.toString()}));
135         result.notApplicable(smh.getLocalString
136                  (getClass().getName() + ".notApplicable",
137                   "[ {0} ] expected {1} bean, but called with {2} bean.",
138                   new Object JavaDoc[] {getClass(),"Session","Entity"}));
139         return result;
140     }
141     }
142 }
143
Popular Tags