KickJava   Java API By Example, From Geeks To Geeks.

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


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  */

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

59     public Result check(EjbDescriptor descriptor) {
60
61     Result result = getInitializedResult();
62     ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
63     boolean ejbCreateExists = false;
64
65     if (descriptor instanceof EjbEntityDescriptor) {
66         boolean oneFailed = false;
67         boolean found = false;
68         int foundAtLeastOne = 0;
69         try {
70         Context context = getVerifierContext();
71         ClassLoader JavaDoc jcl = context.getClassLoader();
72         Class JavaDoc c = Class.forName(descriptor.getEjbClassName(), false, getVerifierContext().getClassLoader());
73         Method [] methods = c.getDeclaredMethods();
74         Vector<Method> createMethodSuffix = new Vector<Method>();
75         for (int i = 0; i < methods.length; i++) {
76             // The method name must start with create.
77
if (methods[i].getName().startsWith("ejbCreate")) {
78             createMethodSuffix.addElement((Method)methods[i]);
79             ejbCreateExists = true;
80             }
81         }
82
83                 // start do while loop here....
84
do {
85             for (int i = 0; i < methods.length; i++) {
86             found = false;
87             
88             // The method name must be ejbPostCreate.
89
if (methods[i].getName().startsWith("ejbPostCreate")) {
90                 found = true;
91                 String JavaDoc matchSuffix = methods[i].getName().substring(13);
92                 for (int k = 0; k < createMethodSuffix.size(); k++) {
93                 if (matchSuffix.equals(((Method)createMethodSuffix.elementAt(k)).getName().substring(9))) {
94                     foundAtLeastOne++;
95
96                     // now display the appropriate results for this particular
97
// ejbPostCreate method
98
result.addGoodDetails(smh.getLocalString
99                                ("tests.componentNameConstructor",
100                                 "For [ {0} ]",
101                                 new Object JavaDoc[] {compName.toString()}));
102                     result.addGoodDetails(smh.getLocalString
103                               (getClass().getName() + ".debug1",
104                                "For EJB Class [ {0} ] method [ {1} ]",
105                                new Object JavaDoc[] {descriptor.getEjbClassName(),methods[i].getName()}));
106                     result.addGoodDetails(smh.getLocalString
107                               (getClass().getName() + ".passed",
108                                "[ {0} ] declares [ {1} ] method.",
109                                new Object JavaDoc[] {descriptor.getEjbClassName(),methods[i].getName()}));
110                 }
111                 }
112                 if (found == true && foundAtLeastOne == 0) {
113                 oneFailed = true;
114                 result.addErrorDetails(smh.getLocalString
115                                ("tests.componentNameConstructor",
116                             "For [ {0} ]",
117                             new Object JavaDoc[] {compName.toString()}));
118                 result.failed(smh.getLocalString
119                           (getClass().getName() + ".failedException",
120                            "Error: [ {0} ] class not found.",
121                            new Object JavaDoc[] {descriptor.getEjbClassName()}));
122                 break;
123                 }
124             }
125             }
126             if (oneFailed == false)
127             break;
128         } while (((c = c.getSuperclass()) != null) && (foundAtLeastOne == 0));
129         
130         if (ejbCreateExists == false){
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         if (foundAtLeastOne == 0 && ejbCreateExists == true){
141             result.addErrorDetails(smh.getLocalString
142                        ("tests.componentNameConstructor",
143                     "For [ {0} ]",
144                     new Object JavaDoc[] {compName.toString()}));
145             result.failed(smh.getLocalString
146                   (getClass().getName() + ".failedException1",
147                    "Error: ejbPostCreate<Method> method corresponding to the ejbCreate<Method> method does not exist!",
148                    new Object JavaDoc[] {}));
149             
150         }
151         } catch (ClassNotFoundException JavaDoc e) {
152         Verifier.debug(e);
153         result.addErrorDetails(smh.getLocalString
154                        ("tests.componentNameConstructor",
155                     "For [ {0} ]",
156                     new Object JavaDoc[] {compName.toString()}));
157         result.failed(smh.getLocalString
158                   (getClass().getName() + ".failedException",
159                    "Error: [ {0} ] class not found.",
160                    new Object JavaDoc[] {descriptor.getEjbClassName()}));
161         oneFailed = true;
162         }
163
164         if (oneFailed) {
165         result.setStatus(result.FAILED);
166             } else if (foundAtLeastOne == 0) {
167                 result.setStatus(result.NOT_APPLICABLE);
168         } else {
169         result.setStatus(result.PASSED);
170         }
171
172         return result;
173  
174     } else {
175         result.addNaDetails(smh.getLocalString
176                        ("tests.componentNameConstructor",
177                     "For [ {0} ]",
178                     new Object JavaDoc[] {compName.toString()}));
179         result.notApplicable(smh.getLocalString
180                  (getClass().getName() + ".notApplicable",
181                   "[ {0} ] expected {1} bean, but called with {2} bean.",
182                   new Object JavaDoc[] {getClass(),"Entity","Session"}));
183         return result;
184     }
185     }
186 }
187
Popular Tags