KickJava   Java API By Example, From Geeks To Geeks.

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


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 import com.sun.enterprise.tools.verifier.tests.ejb.RmiIIOPUtils;
35
36 /**
37  * Session Bean's ejbCreate(...) methods arguments test.
38  * Each session Bean class must define one or more ejbCreate(...) methods.
39  * The number and signatures of a session Bean's create methods are specific
40  * to each EJB class. The method signatures must follow these rules:
41  *
42  * The method name must be ejbCreate.
43  *
44  * The methods arguments must be legal types for RMI-IIOP.
45  *
46  */

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

64     public Result check(EjbDescriptor descriptor) {
65
66     Result result = getInitializedResult();
67     ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
68     boolean remote_exists = false;
69
70     if (descriptor instanceof EjbSessionDescriptor) {
71         boolean oneFailed = false;
72         try {
73         Context context = getVerifierContext();
74         ClassLoader JavaDoc jcl = context.getClassLoader();
75         Class JavaDoc c = Class.forName(descriptor.getEjbClassName(), false, getVerifierContext().getClassLoader());
76
77         Class JavaDoc [] ejbCreateMethodParameterTypes;
78         boolean ejbCreateFound = false;
79         boolean isLegalRMIIIOP = false;
80             int foundAtLeastOne = 0;
81
82         //bug fix for 4699227
83
if (descriptor.getHomeClassName() == null ||
84                         descriptor.getHomeClassName().equals("")) {
85                        result.addNaDetails(smh.getLocalString
86                         ("tests.componentNameConstructor", "For [ {0} ]",
87                          new Object JavaDoc[] {compName.toString()}));
88                        result.notApplicable(smh.getLocalString
89                        ("com.sun.enterprise.tools.verifier.tests.ejb.localinterfaceonly.notapp",
90                         "Not Applicable because, EJB [ {0} ] has Local Interfaces only.",
91                                           new Object JavaDoc[] {descriptor.getEjbClassName()}));
92
93                        return result;
94                 }
95
96         if (descriptor.getRemoteClassName() != null &&
97             !descriptor.getRemoteClassName().equals(""))
98             remote_exists = true;
99
100                 // start do while loop here....
101
do {
102             Method [] methods = c.getDeclaredMethods();
103             for (int i = 0; i < methods.length; i++) {
104             // reset flags from last time thru loop
105
ejbCreateFound = false;
106             isLegalRMIIIOP = false;
107             
108             // The method name must be ejbCreate.
109
if (methods[i].getName().startsWith("ejbCreate")) {
110                 foundAtLeastOne++;
111                 ejbCreateFound = true;
112                                 
113                 if (remote_exists == true) {
114                 // The methods arguments types must be legal types for RMI-IIOP.
115
ejbCreateMethodParameterTypes = methods[i].getParameterTypes();
116                 if (RmiIIOPUtils.isValidRmiIIOPParameters(ejbCreateMethodParameterTypes)) {
117                     // these method parameters are valid, continue
118
isLegalRMIIIOP = true;
119                 }
120                 } else isLegalRMIIIOP = true; //if the ejb has only a local interface
121
//we donot need to check for legal rmi-iiop parameters
122
// now display the appropriate results for this particular ejbCreate
123

124                 // now display the appropriate results for this particular ejbCreate
125
// method
126
if (ejbCreateFound && isLegalRMIIIOP) {
127                 result.addGoodDetails(smh.getLocalString
128                               ("tests.componentNameConstructor",
129                                "For [ {0} ]",
130                                new Object JavaDoc[] {compName.toString()}));
131                 result.addGoodDetails(smh.getLocalString
132                               (getClass().getName() + ".debug1",
133                                "For EJB Class [ {0} ] method [ {1} ]",
134                                new Object JavaDoc[] {descriptor.getEjbClassName(),methods[i].getName()}));
135                 result.addGoodDetails(smh.getLocalString
136                               (getClass().getName() + ".passed",
137                                "[ {0} ] properly declares [ {1} ] method with valid RMI-IIOP argument types.",
138                                new Object JavaDoc[] {descriptor.getEjbClassName(),methods[i].getName()}));
139                 } else if (ejbCreateFound && (!isLegalRMIIIOP)) {
140                 oneFailed = true;
141                 result.addErrorDetails(smh.getLocalString
142                                ("tests.componentNameConstructor",
143                             "For [ {0} ]",
144                             new Object JavaDoc[] {compName.toString()}));
145                 result.addErrorDetails(smh.getLocalString
146                                (getClass().getName() + ".debug1",
147                             "For EJB Class [ {0} ] method [ {1} ]",
148                             new Object JavaDoc[] {descriptor.getEjbClassName(),methods[i].getName()}));
149                 result.addErrorDetails(smh.getLocalString
150                                (getClass().getName() + ".failed",
151                             "Error: An [ {0} ] method was found, but [ {1} ] method has illegal parameter values. [ {2} ] methods arguments types must be legal types for RMI-IIOP.",
152                             new Object JavaDoc[] {methods[i].getName(),methods[i].getName(),methods[i].getName()}));
153                 }
154             }
155             }
156                 } while (((c = c.getSuperclass()) != null) && (foundAtLeastOne == 0));
157         
158         if (foundAtLeastOne == 0){
159             result.addErrorDetails(smh.getLocalString
160                        ("tests.componentNameConstructor",
161                         "For [ {0} ]",
162                         new Object JavaDoc[] {compName.toString()}));
163             result.failed(smh.getLocalString
164                   (getClass().getName() + ".failed1",
165                    "Error: [ {0} ] does not properly declare at least one ejbCreate(...) method. [ {1} ] is not a valid bean.",
166                    new Object JavaDoc[] {descriptor.getEjbClassName(),descriptor.getEjbClassName()}));
167             oneFailed = true;
168         }
169         } catch (ClassNotFoundException JavaDoc e) {
170         Verifier.debug(e);
171         result.addErrorDetails(smh.getLocalString
172                        ("tests.componentNameConstructor",
173                     "For [ {0} ]",
174                     new Object JavaDoc[] {compName.toString()}));
175         result.failed(smh.getLocalString
176                   (getClass().getName() + ".failedException",
177                    "Error: [ {0} ] class not found.",
178                    new Object JavaDoc[] {descriptor.getEjbClassName()}));
179         oneFailed = true;
180         }
181
182         if (oneFailed) {
183         result.setStatus(result.FAILED);
184         } else {
185         result.setStatus(result.PASSED);
186         }
187
188         return result;
189  
190     } else {
191         result.addNaDetails(smh.getLocalString
192                 ("tests.componentNameConstructor",
193                  "For [ {0} ]",
194                  new Object JavaDoc[] {compName.toString()}));
195         result.notApplicable(smh.getLocalString
196                  (getClass().getName() + ".notApplicable",
197                   "[ {0} ] expected {1} bean, but called with {2} bean.",
198                   new Object JavaDoc[] {getClass(),"Session","Entity"}));
199         return result;
200     }
201     }
202 }
203
Popular Tags