KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > verifier > tests > ejb > entity > ejbpostcreatemethod > EjbPostCreateMethodFinal


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.ejbpostcreatemethod;
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 java.util.*;
32 import com.sun.enterprise.tools.verifier.*;
33 import com.sun.enterprise.tools.verifier.tests.ejb.EjbCheck;
34
35 /**
36  * Entity Bean's ejbPostCreate(...) methods test.
37  * Each entity Bean class may define zero or more ejbPostCreate(...) 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 ejbPostCreate.
42  *
43  * The method must not be declared as final.
44  *
45  */

46 public class EjbPostCreateMethodFinal extends EjbTest implements EjbCheck {
47
48
49     /**
50      * Entity Bean's ejbPostCreate(...) methods test.
51      * Each entity Bean class may define zero or more ejbPostCreate(...) 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 ejbPostCreate.
56      *
57      * The method must not be declared as final.
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
68     if (descriptor instanceof EjbEntityDescriptor) {
69         boolean oneFailed = false;
70         int foundAtLeastOne = 0;
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         boolean ejbPostCreateFound = false;
77         boolean isFinal = false;
78                 // start do while loop here....
79
do {
80             Method [] methods = c.getDeclaredMethods();
81             for (int i = 0; i < methods.length; i++) {
82             // reset flags from last time thru loop
83
ejbPostCreateFound = false;
84             isFinal = false;
85
86             // The method name must be ejbPostCreate.
87
if (methods[i].getName().startsWith("ejbPostCreate")) {
88                 foundAtLeastOne++;
89                 ejbPostCreateFound = true;
90
91                 // The method must not be declared as final.
92
int modifiers = methods[i].getModifiers();
93                 if (Modifier.isFinal(modifiers)){
94                 isFinal = true;
95                 }
96
97                 // now display the appropriate results for this particular
98
// ejbPostCreate method
99
if (ejbPostCreateFound && (!isFinal)) {
100                 result.addGoodDetails(smh.getLocalString
101                        ("tests.componentNameConstructor",
102                     "For [ {0} ]",
103                     new Object JavaDoc[] {compName.toString()}));
104                 result.addGoodDetails(smh.getLocalString
105                               (getClass().getName() + ".debug1",
106                                "For EJB Class [ {0} ] method [ {1} ]",
107                                new Object JavaDoc[] {descriptor.getEjbClassName(),methods[i].getName()}));
108                 result.addGoodDetails(smh.getLocalString
109                               (getClass().getName() + ".passed",
110                                "[ {0} ] declares non-final [ {1} ] method.",
111                                new Object JavaDoc[] {descriptor.getEjbClassName(),methods[i].getName()}));
112                 } else if (ejbPostCreateFound && isFinal) {
113                 oneFailed = true;
114                 result.addErrorDetails(smh.getLocalString
115                        ("tests.componentNameConstructor",
116                     "For [ {0} ]",
117                     new Object JavaDoc[] {compName.toString()}));
118                 result.addErrorDetails(smh.getLocalString
119                                (getClass().getName() + ".debug1",
120                             "For EJB Class [ {0} ] ejbPostCreate(...) Method [ {1} ]",
121                             new Object JavaDoc[] {descriptor.getEjbClassName(),methods[i].getName()}));
122                 result.addErrorDetails(smh.getLocalString
123                                (getClass().getName() + ".failed",
124                             "Error: A final [ {0} ] method was found, but [ {1} ] cannot be declared as final.",
125                             new Object JavaDoc[] {methods[i].getName(),methods[i].getName()}));
126                 }
127             }
128             }
129                 } while (((c = c.getSuperclass()) != null) && (foundAtLeastOne == 0));
130         
131         if (foundAtLeastOne == 0) {
132             result.addNaDetails(smh.getLocalString
133                        ("tests.componentNameConstructor",
134                     "For [ {0} ]",
135                     new Object JavaDoc[] {compName.toString()}));
136             result.notApplicable(smh.getLocalString
137                      (getClass().getName() + ".notApplicable1",
138                       "[ {0} ] does not declare any ejbPostCreate(...) methods.",
139                       new Object JavaDoc[] {descriptor.getEjbClassName()}));
140         }
141         } catch (ClassNotFoundException JavaDoc e) {
142         Verifier.debug(e);
143         result.addErrorDetails(smh.getLocalString
144                        ("tests.componentNameConstructor",
145                     "For [ {0} ]",
146                     new Object JavaDoc[] {compName.toString()}));
147         result.failed(smh.getLocalString
148                   (getClass().getName() + ".failedException",
149                    "Error: [ {0} ] class not found.",
150                    new Object JavaDoc[] {descriptor.getEjbClassName()}));
151         oneFailed = true;
152         }
153
154         if (oneFailed) {
155         result.setStatus(result.FAILED);
156             } else if (foundAtLeastOne == 0) {
157                 result.setStatus(result.NOT_APPLICABLE);
158         } else {
159         result.setStatus(result.PASSED);
160         }
161
162         return result;
163  
164     } else {
165         result.addNaDetails(smh.getLocalString
166                        ("tests.componentNameConstructor",
167                     "For [ {0} ]",
168                     new Object JavaDoc[] {compName.toString()}));
169         result.notApplicable(smh.getLocalString
170                  (getClass().getName() + ".notApplicable",
171                   "[ {0} ] expected {1} bean, but called with {2} bean.",
172                   new Object JavaDoc[] {getClass(),"Entity","Session"}));
173         return result;
174     }
175     }
176 }
177
Popular Tags