KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > verifier > tests > ejb > entity > ejbfindbyprimarykey > EjbFindByPrimaryKeyArgs


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.ejbfindbyprimarykey;
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  * Define ejbFindByPrimaryKey method arguments test.
39  *
40  * Every entity enterprise Bean class must define the ejbFindByPrimaryKey
41  * method.
42  *
43  * The methods arguments types must be legal types for RMI-IIOP.
44  */

45 public class EjbFindByPrimaryKeyArgs extends EjbTest implements EjbCheck {
46
47
48     /**
49      * Define ejbFindByPrimaryKey method arguments test.
50      *
51      * Every entity enterprise Bean class must define the ejbFindByPrimaryKey
52      * method.
53      *
54      * The methods arguments types must be legal types for RMI-IIOP.
55      *
56      * @param descriptor the Enterprise Java Bean deployment descriptor
57      *
58      * @return <code>Result</code> the results for this assertion
59      */

60     public Result check(EjbDescriptor descriptor) {
61
62     Result result = getInitializedResult();
63     ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
64
65     if (descriptor instanceof EjbEntityDescriptor) {
66         String JavaDoc persistentType =
67         ((EjbEntityDescriptor)descriptor).getPersistenceType();
68         if (EjbEntityDescriptor.BEAN_PERSISTENCE.equals(persistentType)) {
69         Class JavaDoc [] ejbFinderMethodParameterTypes;
70         boolean ejbFindByPrimaryKeyMethodFound = false;
71         boolean oneFailed = false;
72         boolean isLegalRMIIIOP = false;
73         try {
74             // retrieve the EJB Class Methods
75
Context context = getVerifierContext();
76         ClassLoader JavaDoc jcl = context.getClassLoader();
77             Class JavaDoc EJBClass = Class.forName(descriptor.getEjbClassName(), false, getVerifierContext().getClassLoader());
78                     // start do while loop here....
79
do {
80             Method [] ejbFinderMethods = EJBClass.getDeclaredMethods();
81           
82             for (int j = 0; j < ejbFinderMethods.length; ++j) {
83                 if (ejbFinderMethods[j].getName().equals("ejbFindByPrimaryKey")) {
84                 // Every entity enterprise Bean class must define the
85
// ejbFindByPrimaryKey method.
86
ejbFindByPrimaryKeyMethodFound = true;
87     
88                 // The methods arguments types must be legal types for RMI-IIOP.
89
ejbFinderMethodParameterTypes = ejbFinderMethods[j].getParameterTypes();
90                 if (RmiIIOPUtils.isValidRmiIIOPParameters(ejbFinderMethodParameterTypes)) {
91                 // these method parameters are valid, continue
92
isLegalRMIIIOP = true;
93                 }
94   
95                 if (ejbFindByPrimaryKeyMethodFound && isLegalRMIIIOP) {
96                     result.addGoodDetails(smh.getLocalString
97                        ("tests.componentNameConstructor",
98                     "For [ {0} ]",
99                     new Object JavaDoc[] {compName.toString()}));
100                     result.addGoodDetails(smh.getLocalString
101                               (getClass().getName() + ".debug1",
102                                "For EJB Class [ {0} ] Finder Method [ {1} ]",
103                                new Object JavaDoc[] {EJBClass.getName(),ejbFinderMethods[j].getName()}));
104                     result.addGoodDetails(smh.getLocalString
105                               (getClass().getName() + ".passed",
106                                "An [ {0} ] method with valid RMI-IIOP argument types was found.",
107                                new Object JavaDoc[] {ejbFinderMethods[j].getName()}));
108                 } else if (ejbFindByPrimaryKeyMethodFound && (!isLegalRMIIIOP)) {
109                     oneFailed = true;
110                     result.addErrorDetails(smh.getLocalString
111                        ("tests.componentNameConstructor",
112                     "For [ {0} ]",
113                     new Object JavaDoc[] {compName.toString()}));
114                     result.addErrorDetails(smh.getLocalString
115                                (getClass().getName() + ".debug1",
116                                 "For EJB Class [ {0} ] Finder Method [ {1} ]",
117                                 new Object JavaDoc[] {EJBClass.getName(),ejbFinderMethods[j].getName()}
118                                 ));
119                     result.addErrorDetails(smh.getLocalString
120                                (getClass().getName() + ".failed",
121                                 "Error: An [ {0} ] method was found, but [ {1} ] method has illegal parameter values. [ {2} ] methods arguments types must be legal types for RMI-IIOP.",
122                                 new Object JavaDoc[] {ejbFinderMethods[j].getName(),ejbFinderMethods[j].getName(),ejbFinderMethods[j].getName()}));
123                 }
124                 // found one, and there should only be one, break out
125
break;
126                 }
127             }
128                     } while (((EJBClass = EJBClass.getSuperclass()) != null) && (!ejbFindByPrimaryKeyMethodFound));
129           
130             if (!ejbFindByPrimaryKeyMethodFound) {
131             oneFailed = true;
132             result.addErrorDetails(smh.getLocalString
133                        ("tests.componentNameConstructor",
134                     "For [ {0} ]",
135                     new Object JavaDoc[] {compName.toString()}));
136             result.addErrorDetails(smh.getLocalString
137                            (getClass().getName() + ".debug3",
138                         "For EJB Class [ {0} ]",
139                         new Object JavaDoc[] {descriptor.getEjbClassName()}));
140             result.addErrorDetails(smh.getLocalString
141                            (getClass().getName() + ".failed1",
142                         "Error: No ejbFindByPrimaryKey method was found in bean class."));
143             }
144   
145         } catch (ClassNotFoundException JavaDoc e) {
146             Verifier.debug(e);
147             result.addErrorDetails(smh.getLocalString
148                        ("tests.componentNameConstructor",
149                     "For [ {0} ]",
150                     new Object JavaDoc[] {compName.toString()}));
151             result.failed(smh.getLocalString
152                   (getClass().getName() + ".failedException",
153                    "Error: EJB Class [ {0} ] does not exist or is not loadable.",
154                    new Object JavaDoc[] {descriptor.getEjbClassName()}));
155             oneFailed = true;
156         }
157     
158         if (oneFailed) {
159             result.setStatus(result.FAILED);
160         } else {
161             result.setStatus(result.PASSED);
162         }
163         } else { //(CONTAINER_PERSISTENCE.equals(persistentType))
164
result.addNaDetails(smh.getLocalString
165                        ("tests.componentNameConstructor",
166                     "For [ {0} ]",
167                     new Object JavaDoc[] {compName.toString()}));
168         result.notApplicable(smh.getLocalString
169                      (getClass().getName() + ".notApplicable2",
170                       "Expected persistence type [ {0} ], but bean [ {1} ] has persistence type [ {2} ]",
171                       new Object JavaDoc[] {EjbEntityDescriptor.BEAN_PERSISTENCE,descriptor.getName(),persistentType}));
172         }
173   
174         return result;
175
176     } else {
177         result.addNaDetails(smh.getLocalString
178                        ("tests.componentNameConstructor",
179                     "For [ {0} ]",
180                     new Object JavaDoc[] {compName.toString()}));
181         result.notApplicable(smh.getLocalString
182                  (getClass().getName() + ".notApplicable",
183                   "[ {0} ] expected {1} bean, but called with {2} bean.",
184                   new Object JavaDoc[] {getClass(),"Entity","Session"}));
185         return result;
186     }
187     }
188 }
189
Popular Tags