KickJava   Java API By Example, From Geeks To Geeks.

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


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 final 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 final.
43  *
44  */

45 public class EjbCreateMethodFinal extends EjbTest implements EjbCheck {
46
47
48     /**
49      * Entity Bean's ejbCreate(...) methods final 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 isFinal = 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             isFinal = 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 final.
91
int modifiers = methods[i].getModifiers();
92                 if (Modifier.isFinal(modifiers)){
93                 isFinal = true;
94                 }
95                 // now display the appropriate results for this particular ejbCreate
96
// method
97
if (ejbCreateFound && isFinal) {
98                 oneFailed = true;
99                 result.addErrorDetails(smh.getLocalString
100                           ("tests.componentNameConstructor",
101                            "For [ {0} ]",
102                            new Object JavaDoc[] {compName.toString()}));
103                 result.addErrorDetails(smh.getLocalString
104                                (getClass().getName() + ".debug1",
105                             "For EJB Class [ {0} ] method [ {1} ]",
106                             new Object JavaDoc[] {descriptor.getEjbClassName(),methods[i].getName()}));
107                 result.addErrorDetails(smh.getLocalString
108                                (getClass().getName() + ".failed",
109                             "Error: A final [ {0} ] method was found, but [ {1} ] cannot be declared as final.",
110                             new Object JavaDoc[] {methods[i].getName(),methods[i].getName()}));
111                 break;
112                 }
113             }
114             }
115             if (oneFailed == true)
116             break;
117                 } while (((c = c.getSuperclass()) != null) && (foundAtLeastOne == 0));
118         
119         if (foundAtLeastOne == 0){
120             result.addNaDetails(smh.getLocalString
121                           ("tests.componentNameConstructor",
122                            "For [ {0} ]",
123                            new Object JavaDoc[] {compName.toString()}));
124             result.notApplicable(smh.getLocalString
125                      (getClass().getName() + ".notApplicable1",
126                       "[ {0} ] does not declare any ejbCreate(...) methods.",
127                       new Object JavaDoc[] {descriptor.getEjbClassName()}));
128         }
129         if (oneFailed == false && foundAtLeastOne > 0) {
130             result.addGoodDetails(smh.getLocalString
131                           ("tests.componentNameConstructor",
132                            "For [ {0} ]",
133                            new Object JavaDoc[] {compName.toString()}));
134             result.addGoodDetails(smh.getLocalString
135                       (getClass().getName() + ".debug1",
136                        "For EJB Class [ {0} ] ",
137                        new Object JavaDoc[] {descriptor.getEjbClassName()}));
138             result.addGoodDetails(smh.getLocalString
139                       (getClass().getName() + ".passed",
140                        "[ {0} ] properly declares non-final ejbCreate<method> method.",
141                        new Object JavaDoc[] {descriptor.getEjbClassName()}));
142         }
143         } catch (ClassNotFoundException JavaDoc e) {
144         Verifier.debug(e);
145         result.addErrorDetails(smh.getLocalString
146                        ("tests.componentNameConstructor",
147                     "For [ {0} ]",
148                     new Object JavaDoc[] {compName.toString()}));
149         result.failed(smh.getLocalString
150                   (getClass().getName() + ".failedException",
151                    "Error: [ {0} ] class not found.",
152                    new Object JavaDoc[] {descriptor.getEjbClassName()}));
153         oneFailed = true;
154         }
155
156             if (oneFailed) {
157                 result.setStatus(result.FAILED);
158             } else if (foundAtLeastOne == 0) {
159                 result.setStatus(result.NOT_APPLICABLE);
160             } else {
161                 result.setStatus(result.PASSED);
162             }
163
164         return result;
165  
166     } else {
167         result.addNaDetails(smh.getLocalString
168                           ("tests.componentNameConstructor",
169                            "For [ {0} ]",
170                            new Object JavaDoc[] {compName.toString()}));
171         result.notApplicable(smh.getLocalString
172                  (getClass().getName() + ".notApplicable",
173                   "[ {0} ] expected {1} bean, but called with {2} bean.",
174                   new Object JavaDoc[] {getClass(),"Entity","Session"}));
175         return result;
176     }
177     }
178 }
179
Popular Tags