KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > verifier > tests > ejb > session > stateless > StatelessEjbCreateHome


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.stateless;
24
25 import com.sun.enterprise.tools.verifier.tests.ejb.EjbTest;
26 import com.sun.enterprise.deployment.EjbDescriptor;
27 import com.sun.enterprise.deployment.EjbSessionDescriptor;
28 import java.lang.ClassLoader JavaDoc;
29 import com.sun.enterprise.tools.verifier.tests.*;
30 import java.lang.reflect.*;
31 import com.sun.enterprise.tools.verifier.*;
32 import com.sun.enterprise.tools.verifier.tests.ejb.EjbCheck;
33
34 /**
35  * Stateless session enterprise beans class single create method test.
36  * The session enterprise Bean class must define a single ejbCreate method
37  * that takes no arguments.
38  */

39 public class StatelessEjbCreateHome extends EjbTest implements EjbCheck {
40
41
42     /**
43      * Stateless session enterprise beans class single create method test.
44      * The session enterprise Bean class must define a single ejbCreate method
45      * that takes no arguments.
46      *
47      * @param descriptor the Enterprise Java Bean deployment descriptor
48      *
49      * @return <code>Result</code> the results for this assertion
50      */

51     public Result check(EjbDescriptor descriptor) {
52
53     Result result = getInitializedResult();
54     ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
55
56     if (descriptor instanceof EjbSessionDescriptor) {
57         String JavaDoc stateType = ((EjbSessionDescriptor)descriptor).getSessionType();
58         if (EjbSessionDescriptor.STATELESS.equals(stateType)) {
59         // RULE: The stateless session enterprise Bean class must define a
60
// single ejbCreate method that takes no arguments.
61
try {
62             Context context = getVerifierContext();
63         ClassLoader JavaDoc jcl = context.getClassLoader();
64             Class JavaDoc c = Class.forName(descriptor.getEjbClassName(), false, getVerifierContext().getClassLoader());
65             Method m= null;
66             int foundThisManyTimes = 0;
67                     // start do while loop here....
68
do {
69                 Method methods[] = c.getDeclaredMethods();
70                 for (int i=0; i< methods.length; i++) {
71                 if (!methods[i].getName().equals("ejbCreate")){
72                     continue;
73                 }
74                 if (foundThisManyTimes == 0) {
75                     m = methods[i];
76                     foundThisManyTimes++;
77                 } else {
78                     foundThisManyTimes++;
79                 }
80                 }
81                     } while (((c = c.getSuperclass()) != null) && (m == null));
82
83             //if we know that m got set to create in the above loop, check params
84
// otherwise skip test, set status to FAILED below,
85
if ((m != null) && (foundThisManyTimes == 1)) {
86             Class JavaDoc cc[] = m.getParameterTypes();
87             if (cc.length > 0) {
88                 result.addErrorDetails(smh.getLocalString
89                            ("tests.componentNameConstructor",
90                             "For [ {0} ]",
91                             new Object JavaDoc[] {compName.toString()}));
92                 result.failed(smh.getLocalString
93                       (getClass().getName() + ".failed",
94                        "Error: The ejbCreate method has one or more parameters \n" +
95                        "within bean [ {0} ]. Stateless session are only allowed \n" +
96                        "to have ejbCreate methods with no arguments.",
97                        new Object JavaDoc[] {descriptor.getEjbClassName()}));
98             } else {
99                 result.addGoodDetails(smh.getLocalString
100                           ("tests.componentNameConstructor",
101                            "For [ {0} ]",
102                            new Object JavaDoc[] {compName.toString()}));
103                 result.passed(smh.getLocalString
104                       (getClass().getName() + ".passed",
105                        "Valid: This bean's [ {0} ] ejbCreate method has no parameters."
106                        + "\n Stateless session beans can only have a ejbCreate method"
107                        + "\n with no parameters.",
108                        new Object JavaDoc[] {descriptor.getEjbClassName()}));
109             }
110             } else if ((m != null) && (foundThisManyTimes > 1)) {
111             // set status to FAILED, 'cause there is more than one
112
// create methods to begin with, regardless of its parameters
113
result.addErrorDetails(smh.getLocalString
114                            ("tests.componentNameConstructor",
115                         "For [ {0} ]",
116                         new Object JavaDoc[] {compName.toString()}));
117             result.failed(smh.getLocalString
118                       (getClass().getName() + ".failed2",
119                        "Error: [ {0} ] ejbCreate methods exists within bean [ {1} ]. The EJB class must have only one ejbCreate method for stateless session bean. ",
120                        new Object JavaDoc[] {new Integer JavaDoc(foundThisManyTimes),descriptor.getEjbClassName()}));
121             } else {
122             // set status to FAILED, 'cause there is not even
123
// a create method to begin with, regardless of its parameters
124
result.addErrorDetails(smh.getLocalString
125                            ("tests.componentNameConstructor",
126                         "For [ {0} ]",
127                         new Object JavaDoc[] {compName.toString()}));
128             result.failed(smh.getLocalString
129                       (getClass().getName() + ".failed3",
130                        "Error: No ejbCreate method exists within bean [ {0} ]",
131                        new Object JavaDoc[] {descriptor.getEjbClassName()}));
132             }
133         } catch (ClassNotFoundException JavaDoc e) {
134             Verifier.debug(e);
135             result.addErrorDetails(smh.getLocalString
136                        ("tests.componentNameConstructor",
137                         "For [ {0} ]",
138                         new Object JavaDoc[] {compName.toString()}));
139             result.failed(smh.getLocalString
140                   (getClass().getName() + ".failedException",
141                    "Error: Class [ {0} ] not found within bean [ {1} ]",
142                    new Object JavaDoc[] {descriptor.getEjbClassName(), descriptor.getName()}));
143         }
144         return result;
145           
146         } else if (EjbSessionDescriptor.STATEFUL.equals(stateType)) {
147         result.addNaDetails(smh.getLocalString
148                        ("tests.componentNameConstructor",
149                     "For [ {0} ]",
150                     new Object JavaDoc[] {compName.toString()}));
151         result.notApplicable(smh.getLocalString
152                      (getClass().getName() + ".notApplicable1",
153                       "{0} expected {1} Session bean, but called with {2} Session bean.",
154                       new Object JavaDoc[] {getClass(),EjbSessionDescriptor.STATELESS,stateType}));
155         return result;
156         } else {
157         result.addErrorDetails(smh.getLocalString
158                        ("tests.componentNameConstructor",
159                     "For [ {0} ]",
160                     new Object JavaDoc[] {compName.toString()}));
161         result.failed(smh.getLocalString
162                   (getClass().getName() + ".failed4",
163                    "Error: [ {0} ] is not valid stateType within bean [ {1} ].",
164                    new Object JavaDoc[] {stateType, descriptor.getName()}));
165         return result;
166         }
167     } else {
168         result.addNaDetails(smh.getLocalString
169                 ("tests.componentNameConstructor",
170                  "For [ {0} ]",
171                  new Object JavaDoc[] {compName.toString()}));
172         result.notApplicable(smh.getLocalString
173                  (getClass().getName() + ".notApplicable",
174                   "[ {0} ] expected {1} bean, but called with {2} bean.",
175                   new Object JavaDoc[] {getClass(),"Session","Entity"}));
176         return result;
177     }
178     }
179 }
180
Popular Tags