KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > verifier > tests > ejb > entity > ejbfindermethod > EjbFinderMethodArgs


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.ejbfindermethod;
24
25 import com.sun.enterprise.tools.verifier.tests.ejb.EjbTest;
26 import java.lang.reflect.*;
27 import java.util.*;
28 import com.sun.enterprise.deployment.EjbEntityDescriptor;
29 import com.sun.enterprise.deployment.EjbDescriptor;
30 import com.sun.enterprise.deployment.MethodDescriptor;
31 import com.sun.enterprise.tools.verifier.tests.ejb.EjbCheck;
32 import com.sun.enterprise.tools.verifier.tests.ejb.RmiIIOPUtils;
33 import com.sun.enterprise.tools.verifier.*;
34 import java.lang.ClassLoader JavaDoc;
35 import com.sun.enterprise.tools.verifier.tests.*;
36
37 /**
38  * ejbFind<METHOD>(...) methods test.
39  *
40  * EJB class contains all ejbFind<METHOD>(...) methods declared in the bean
41  * class.
42  *
43  * The signatures of the finder methods must follow the following rules:
44  *
45  * A finder method name must start with the prefix ``ejbFind''
46  * (e.g. ejbFindByPrimaryKey, ejbFindLargeAccounts, ejbFindLateShipments).
47  *
48  * The methods arguments types must be legal types for RMI-IIOP.
49  *
50  */

51 public class EjbFinderMethodArgs extends EjbTest implements EjbCheck {
52
53
54     /**
55      * ejbFind<METHOD>(...) methods test.
56      *
57      * EJB class contains all ejbFind<METHOD>(...) methods declared in the bean
58      * class.
59      *
60      * The signatures of the finder methods must follow the following rules:
61      *
62      * A finder method name must start with the prefix ``ejbFind''
63      * (e.g. ejbFindByPrimaryKey, ejbFindLargeAccounts, ejbFindLateShipments).
64      *
65      * The methods arguments types must be legal types for RMI-IIOP.
66      *
67      * @param descriptor the Enterprise Java Bean deployment descriptor
68      *
69      * @return <code>Result</code> the results for this assertion
70      */

71     public Result check(EjbDescriptor descriptor) {
72
73     Result result = getInitializedResult();
74     ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
75
76     if (descriptor instanceof EjbEntityDescriptor) {
77         String JavaDoc persistence =
78         ((EjbEntityDescriptor)descriptor).getPersistenceType();
79         if (EjbEntityDescriptor.BEAN_PERSISTENCE.equals(persistence)) {
80
81         Class JavaDoc [] methodParameterTypes;
82         Class JavaDoc [] ejbFinderMethodParameterTypes;
83         boolean ejbFindMethodFound = false;
84         boolean isLegalRMIIIOP = false;
85         boolean oneFailed = false;
86         int foundAtLeastOne = 0;
87         try {
88             // retrieve the EJB Class Methods
89
Context context = getVerifierContext();
90             ClassLoader JavaDoc jcl = context.getClassLoader();
91             Class JavaDoc EJBClass = Class.forName(descriptor.getEjbClassName(), false, getVerifierContext().getClassLoader());
92                     // start do while loop here....
93
// test not applicable if the bean has only local home
94
if (descriptor.getHomeClassName() == null ||
95                         descriptor.getHomeClassName().equals("")) {
96                        result.addNaDetails(smh.getLocalString
97                         ("tests.componentNameConstructor", "For [ {0} ]",
98                          new Object JavaDoc[] {compName.toString()}));
99                        result.notApplicable(smh.getLocalString
100                        ("com.sun.enterprise.tools.verifier.tests.ejb.localinterfaceonly.notapp",
101                         "Not Applicable because, EJB [ {0} ] has Local Interfaces only.",
102                                           new Object JavaDoc[] {descriptor.getEjbClassName()}));
103
104                        return result;
105                     }
106                     do {
107             Method [] ejbFinderMethods = EJBClass.getDeclaredMethods();
108           
109             for (int j = 0; j < ejbFinderMethods.length; ++j) {
110                 if (ejbFinderMethods[j].getName().startsWith("ejbFind")) {
111                 ejbFindMethodFound = true;
112                 foundAtLeastOne++;
113     
114                 // The methods arguments types must be legal types for RMI-IIOP.
115
ejbFinderMethodParameterTypes = ejbFinderMethods[j].getParameterTypes();
116                 if (RmiIIOPUtils.isValidRmiIIOPParameters(ejbFinderMethodParameterTypes)) {
117                 // these method parameters are valid, continue
118
isLegalRMIIIOP = true;
119                 }
120   
121                 if (ejbFindMethodFound && isLegalRMIIIOP) {
122                     result.addGoodDetails(smh.getLocalString
123                        ("tests.componentNameConstructor",
124                     "For [ {0} ]",
125                     new Object JavaDoc[] {compName.toString()}));
126                     result.addGoodDetails(smh.getLocalString
127                               (getClass().getName() + ".debug1",
128                                "For EJB Class [ {0} ] Finder Method [ {1} ]",
129                                new Object JavaDoc[] {EJBClass.getName(),ejbFinderMethods[j].getName()}));
130                     result.addGoodDetails(smh.getLocalString
131                               (getClass().getName() + ".passed",
132                                "An [ {0} ] method was found, with valid method arguments types for RMI-IIOP.",
133                                new Object JavaDoc[] {ejbFinderMethods[j].getName()}));
134                 } else if (ejbFindMethodFound && (!isLegalRMIIIOP)) {
135                     oneFailed = true;
136                     result.addErrorDetails(smh.getLocalString
137                        ("tests.componentNameConstructor",
138                     "For [ {0} ]",
139                     new Object JavaDoc[] {compName.toString()}));
140                     result.addErrorDetails(smh.getLocalString
141                                (getClass().getName() + ".debug1",
142                                 "For EJB Class [ {0} ] Finder Method [ {1} ]",
143                                 new Object JavaDoc[] {EJBClass.getName(),ejbFinderMethods[j].getName()}));
144                     result.addErrorDetails(smh.getLocalString
145                                (getClass().getName() + ".failed",
146                                 "Error: An [ {0} ] method was found, but [ {1} ] method has illegal parameter values. [ {2} ] methods arguments types must be legal types for RMI-IIOP.",
147                                 new Object JavaDoc[] {ejbFinderMethods[j].getName(),ejbFinderMethods[j].getName(),ejbFinderMethods[j].getName()}));
148                 }
149                 }
150             }
151                     } while (((EJBClass = EJBClass.getSuperclass()) != null) && (foundAtLeastOne == 0));
152   
153             if (foundAtLeastOne == 0) {
154             result.addNaDetails(smh.getLocalString
155                        ("tests.componentNameConstructor",
156                     "For [ {0} ]",
157                     new Object JavaDoc[] {compName.toString()}));
158             result.notApplicable(smh.getLocalString
159                          (getClass().getName() + ".notApplicable1",
160                           "[ {0} ] does not declare any ejbFind<METHOD>(...) methods.",
161                           new Object JavaDoc[] {descriptor.getEjbClassName()}));
162             }
163   
164         } catch (ClassNotFoundException JavaDoc e) {
165             Verifier.debug(e);
166             result.addErrorDetails(smh.getLocalString
167                        ("tests.componentNameConstructor",
168                     "For [ {0} ]",
169                     new Object JavaDoc[] {compName.toString()}));
170             result.failed(smh.getLocalString
171                   (getClass().getName() + ".failedException",
172                    "Error: EJB Class [ {1} ] does not exist or is not loadable.",
173                    new Object JavaDoc[] {descriptor.getEjbClassName()}));
174             oneFailed = true;
175         }
176     
177         if (oneFailed) {
178             result.setStatus(result.FAILED);
179                 } else if (foundAtLeastOne == 0) {
180                     result.setStatus(result.NOT_APPLICABLE);
181         } else {
182             result.setStatus(result.PASSED);
183         }
184     
185         return result;
186
187         } else { //if (CONTAINER_PERSISTENCE.equals(persistence))
188
result.addNaDetails(smh.getLocalString
189                        ("tests.componentNameConstructor",
190                     "For [ {0} ]",
191                     new Object JavaDoc[] {compName.toString()}));
192         result.notApplicable(smh.getLocalString
193                      (getClass().getName() + ".notApplicable2",
194                       "Expected [ {0} ] managed persistence, but [ {1} ] bean has [ {2} ] managed persistence.",
195                       new Object JavaDoc[] {EjbEntityDescriptor.BEAN_PERSISTENCE,descriptor.getName(),persistence}));
196         return result;
197         }
198
199     } else {
200         result.addNaDetails(smh.getLocalString
201                        ("tests.componentNameConstructor",
202                     "For [ {0} ]",
203                     new Object JavaDoc[] {compName.toString()}));
204         result.notApplicable(smh.getLocalString
205                  (getClass().getName() + ".notApplicable",
206                   "[ {0} ] expected {1} bean, but called with {2} bean.",
207                   new Object JavaDoc[] {getClass(),"Entity","Session"}));
208         return result;
209     }
210     }
211 }
212
Popular Tags