KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > verifier > tests > ejb > entity > ejbcreatemethod > EjbCreateMethodStatic


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
34 /**
35  * Entity Bean's ejbCreate(...) methods static test.
36  * Each entity Bean class may define zero or more ejbCreate(...) methods.
37  * The number and signatures of a entity Bean's create methods are specific
38  * to each EJB class. The method signatures must follow these rules:
39  *
40  * The method name must be ejbCreate.
41  *
42  * The method must not be declared as static.
43  *
44  */

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

62     public Result check(EjbDescriptor descriptor) {
63
64     Result result = getInitializedResult();
65     ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
66
67     if (descriptor instanceof EjbEntityDescriptor) {
68         boolean oneFailed = false;
69         int foundAtLeastOne = 0;
70         try {
71         Context context = getVerifierContext();
72         ClassLoader JavaDoc jcl = context.getClassLoader();
73         Class JavaDoc c = Class.forName(descriptor.getEjbClassName(), false, getVerifierContext().getClassLoader());
74
75         boolean ejbCreateFound = false;
76         boolean isStatic = false;
77                 // start do while loop here....
78
do {
79             Method [] methods = c.getDeclaredMethods();
80             for (int i = 0; i < methods.length; i++) {
81             // reset flags from last time thru loop
82
ejbCreateFound = false;
83             isStatic = false;
84
85             // The method name must be ejbCreate.
86
if (methods[i].getName().startsWith("ejbCreate")) {
87                 foundAtLeastOne++;
88                 ejbCreateFound = true;
89
90                 // The method must not be declared as static.
91
int modifiers = methods[i].getModifiers();
92                 if (Modifier.isStatic(modifiers)){
93                 isStatic = true;
94                 }
95
96                 // now display the appropriate results for this particular ejbCreate
97
// method
98
if (ejbCreateFound && isStatic) {
99                 oneFailed = true;
100                 result.addErrorDetails(smh.getLocalString
101                           ("tests.componentNameConstructor",
102                            "For [ {0} ]",
103                            new Object JavaDoc[] {compName.toString()}));
104                 result.addErrorDetails(smh.getLocalString
105                                (getClass().getName() + ".debug1",
106                             "For EJB Class [ {0} ] method [ {1} ]",
107                             new Object JavaDoc[] {descriptor.getEjbClassName(),methods[i].getName()}));
108                 result.addErrorDetails(smh.getLocalString
109                                (getClass().getName() + ".failed",
110                             "Error: A static [ {0} ] method was found, but [ {1} ] cannot be declared as static.",
111                             new Object JavaDoc[] {methods[i].getName(),methods[i].getName()}));
112                 break;
113                 }
114             }
115             }
116             if (oneFailed == true)
117             break;
118                 } while (((c = c.getSuperclass()) != null) && (foundAtLeastOne == 0));
119         
120         if (foundAtLeastOne == 0) {
121             result.addNaDetails(smh.getLocalString
122                           ("tests.componentNameConstructor",
123                            "For [ {0} ]",
124                            new Object JavaDoc[] {compName.toString()}));
125             result.notApplicable(smh.getLocalString
126                      (getClass().getName() + ".notApplicable1",
127                       "[ {0} ] does not declare any ejbCreate(...) methods.",
128                       new Object JavaDoc[] {descriptor.getEjbClassName()}));
129         }
130         if (oneFailed == false && foundAtLeastOne > 0) {
131             result.addGoodDetails(smh.getLocalString
132                    ("tests.componentNameConstructor",
133                     "For [ {0} ]",
134                     new Object JavaDoc[] {compName.toString()}));
135             result.addGoodDetails(smh.getLocalString
136                       (getClass().getName() + ".debug1",
137                        "For EJB Class [ {0} ]",
138                        new Object JavaDoc[] {descriptor.getEjbClassName()}));
139             result.addGoodDetails(smh.getLocalString
140                       (getClass().getName() + ".passed",
141                        "[ {0} ] properly declares non-static ejbCreate<method> method.",
142                        new Object JavaDoc[] {descriptor.getEjbClassName()}));
143         }
144         } catch (ClassNotFoundException JavaDoc e) {
145         Verifier.debug(e);
146         result.addErrorDetails(smh.getLocalString
147                        ("tests.componentNameConstructor",
148                     "For [ {0} ]",
149                     new Object JavaDoc[] {compName.toString()}));
150         result.failed(smh.getLocalString
151                   (getClass().getName() + ".failedException",
152                    "Error: [ {0} ] class not found.",
153                    new Object JavaDoc[] {descriptor.getEjbClassName()}));
154         oneFailed = true;
155         }
156
157             if (oneFailed) {
158                 result.setStatus(result.FAILED);
159             } else if (foundAtLeastOne == 0) {
160                 result.setStatus(result.NOT_APPLICABLE);
161             } else {
162         result.setStatus(result.PASSED);
163             }
164
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(),"Entity","Session"}));
176         return result;
177     }
178     }
179 }
180
Popular Tags