KickJava   Java API By Example, From Geeks To Geeks.

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


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 be declared as public.
44  *
45  */

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