KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > verifier > tests > ejb > entity > 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.entity.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.EntityBean JavaDoc;
29 import java.lang.reflect.*;
30 import com.sun.enterprise.deployment.*;
31 import com.sun.enterprise.tools.verifier.*;
32 import com.sun.enterprise.tools.verifier.tests.ejb.EjbCheck;
33 import com.sun.enterprise.tools.verifier.tests.ejb.RmiIIOPUtils;
34
35 /**
36  * Entity Bean's ejbCreate(...) methods arguments test.
37  * Each entity Bean class may define zero or more ejbCreate(...) methods.
38  * The number and signatures of a entity 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  * The methods arguments must be legal types for RMI-IIOP.
44  *
45  */

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

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

122                 if (ejbCreateFound && !isLegalRMIIIOP) {
123                 oneFailed = true;
124                 result.addErrorDetails(smh.getLocalString
125                                ("tests.componentNameConstructor",
126                             "For [ {0} ]",
127                             new Object JavaDoc[] {compName.toString()}));
128                 result.addErrorDetails(smh.getLocalString
129                                (getClass().getName() + ".debug1",
130                             "For EJB Class [ {0} ] method [ {1} ]",
131                             new Object JavaDoc[] {descriptor.getEjbClassName(),methods[i].getName()}));
132                 result.addErrorDetails(smh.getLocalString
133                                (getClass().getName() + ".failed",
134                             "Error: An [ {0} ] method was found, but [ {1} ] method has illegal parameter values. [ {2} ] methods arguments types must be legal types for RMI-IIOP.",
135                             new Object JavaDoc[] {methods[i].getName(),methods[i].getName(),methods[i].getName()}));
136                 break;
137                 }
138             }
139             }
140             if (oneFailed == true)
141             break;
142                 } while (((c = c.getSuperclass()) != null) && (foundAtLeastOne == 0));
143         
144         if (foundAtLeastOne == 0) {
145             result.addNaDetails(smh.getLocalString
146                     ("tests.componentNameConstructor",
147                      "For [ {0} ]",
148                      new Object JavaDoc[] {compName.toString()}));
149             result.notApplicable(smh.getLocalString
150                      (getClass().getName() + ".notApplicable1",
151                       "[ {0} ] does not declare any ejbCreate(...) methods.",
152                       new Object JavaDoc[] {descriptor.getEjbClassName()}));
153         }
154     
155         if (oneFailed == false && foundAtLeastOne > 0) {
156             result.addGoodDetails(smh.getLocalString
157                       ("tests.componentNameConstructor",
158                        "For [ {0} ]",
159                        new Object JavaDoc[] {compName.toString()}));
160             result.addGoodDetails(smh.getLocalString
161                       (getClass().getName() + ".debug1",
162                        "For EJB Class [ {0} ]",
163                        new Object JavaDoc[] {descriptor.getEjbClassName()}));
164             result.addGoodDetails(smh.getLocalString
165                       (getClass().getName() + ".passed",
166                        "[ {0} ] properly declares ejbCreate<method> method with arguments that are legal types for RMI-IIOP.",
167                        new Object JavaDoc[] {descriptor.getEjbClassName()}));
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 if (foundAtLeastOne == 0) {
185         result.setStatus(result.NOT_APPLICABLE);
186         } else {
187         result.setStatus(result.PASSED);
188         }
189
190         return result;
191  
192     } else {
193         result.addNaDetails(smh.getLocalString
194                 ("tests.componentNameConstructor",
195                  "For [ {0} ]",
196                  new Object JavaDoc[] {compName.toString()}));
197         result.notApplicable(smh.getLocalString
198                  (getClass().getName() + ".notApplicable",
199                   "[ {0} ] expected {1} bean, but called with {2} bean.",
200                   new Object JavaDoc[] {getClass(),"Entity","Session"}));
201         return result;
202     }
203     }
204 }
205
Popular Tags