KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > verifier > tests > ejb > entity > ejbfindbyprimarykey > EjbFindByPrimaryKeyFinal


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.ejbfindbyprimarykey;
24
25 import com.sun.enterprise.tools.verifier.tests.ejb.EjbTest;
26 import java.lang.reflect.*;
27 import java.util.*;
28 import com.sun.enterprise.deployment.EjbEntityDescriptor;
29 import com.sun.enterprise.deployment.EjbDescriptor;
30 import com.sun.enterprise.deployment.MethodDescriptor;
31 import com.sun.enterprise.tools.verifier.tests.ejb.EjbCheck;
32 import com.sun.enterprise.tools.verifier.*;
33 import java.lang.ClassLoader JavaDoc;
34 import com.sun.enterprise.tools.verifier.tests.*;
35
36 /**
37  * Define ejbFindByPrimaryKey method final test.
38  *
39  * Every entity enterprise Bean class must define the ejbFindByPrimaryKey
40  * method.
41  *
42  * The method must not be declared as final.
43  *
44  */

45 public class EjbFindByPrimaryKeyFinal extends EjbTest implements EjbCheck {
46
47
48     /**
49      * Define ejbFindByPrimaryKey method final test.
50      *
51      * Every entity enterprise Bean class must define the ejbFindByPrimaryKey
52      * method.
53      *
54      * The method must not be declared as final.
55      *
56      * @param descriptor the Enterprise Java Bean deployment descriptor
57      *
58      * @return <code>Result</code> the results for this assertion
59      */

60     public Result check(EjbDescriptor descriptor) {
61
62     Result result = getInitializedResult();
63     ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
64
65     if (descriptor instanceof EjbEntityDescriptor) {
66         String JavaDoc persistentType =
67         ((EjbEntityDescriptor)descriptor).getPersistenceType();
68         if (EjbEntityDescriptor.BEAN_PERSISTENCE.equals(persistentType)) {
69         boolean ejbFindByPrimaryKeyMethodFound = false;
70         boolean isFinal = false;
71         boolean oneFailed = false;
72         int findMethodModifiers = 0;
73         try {
74             // retrieve the EJB Class Methods
75
Context context = getVerifierContext();
76         ClassLoader JavaDoc jcl = context.getClassLoader();
77             Class JavaDoc EJBClass = Class.forName(descriptor.getEjbClassName(), false, getVerifierContext().getClassLoader());
78                     // start do while loop here....
79
do {
80             Method [] ejbFinderMethods = EJBClass.getDeclaredMethods();
81           
82             for (int j = 0; j < ejbFinderMethods.length; ++j) {
83                 if (ejbFinderMethods[j].getName().equals("ejbFindByPrimaryKey")) {
84                 // Every entity enterprise Bean class must define the
85
// ejbFindByPrimaryKey method.
86
ejbFindByPrimaryKeyMethodFound = true;
87   
88                 // The method must not be declared as final.
89
findMethodModifiers = ejbFinderMethods[j].getModifiers();
90                 if (Modifier.isFinal(findMethodModifiers)) {
91                     isFinal = true;
92                 }
93     
94                 if (ejbFindByPrimaryKeyMethodFound && !isFinal) {
95                     result.addGoodDetails(smh.getLocalString
96                               ("tests.componentNameConstructor",
97                                "For [ {0} ]",
98                                new Object JavaDoc[] {compName.toString()}));
99                     result.addGoodDetails(smh.getLocalString
100                               (getClass().getName() + ".debug1",
101                                "For EJB Class [ {0} ] Finder method [ {1} ]",
102                                new Object JavaDoc[] {EJBClass.getName(),ejbFinderMethods[j].getName()}));
103                     result.addGoodDetails(smh.getLocalString
104                               (getClass().getName() + ".passed",
105                                "A non-final [ {0} ] method was found.",
106                                new Object JavaDoc[] {ejbFinderMethods[j].getName()}));
107                 } else if (ejbFindByPrimaryKeyMethodFound && isFinal) {
108                     oneFailed = true;
109                     result.addErrorDetails(smh.getLocalString
110                                ("tests.componentNameConstructor",
111                                 "For [ {0} ]",
112                                 new Object JavaDoc[] {compName.toString()}));
113                     result.addErrorDetails(smh.getLocalString
114                                (getClass().getName() + ".debug1",
115                                 "For EJB Class [ {0} ] Finder method [ {1} ]",
116                                 new Object JavaDoc[] {EJBClass.getName(),ejbFinderMethods[j].getName()}));
117                     result.addErrorDetails(smh.getLocalString
118                                (getClass().getName() + ".failed",
119                                 "Error: A final [ {0} ] method was found, but [ {1} ] cannot be declared as final.",
120                                 new Object JavaDoc[] {ejbFinderMethods[j].getName(),ejbFinderMethods[j].getName()}));
121                 }
122                 // found one, and there should only be one, break out
123
break;
124                 }
125             }
126                     } while (((EJBClass = EJBClass.getSuperclass()) != null) && (!ejbFindByPrimaryKeyMethodFound));
127   
128             if (!ejbFindByPrimaryKeyMethodFound) {
129             oneFailed = true;
130             result.addErrorDetails(smh.getLocalString
131                        ("tests.componentNameConstructor",
132                     "For [ {0} ]",
133                     new Object JavaDoc[] {compName.toString()}));
134             result.addErrorDetails(smh.getLocalString
135                            (getClass().getName() + ".debug3",
136                         "For EJB Class [ {0} ]",
137                         new Object JavaDoc[] {descriptor.getEjbClassName()}));
138             result.addErrorDetails(smh.getLocalString
139                            (getClass().getName() + ".failed1",
140                         "Error: No ejbFindByPrimaryKey method was found in bean class."));
141             }
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: EJB Class [ {0} ] does not exist or is not loadable.",
152                    new Object JavaDoc[] {descriptor.getEjbClassName()}));
153             oneFailed = true;
154         }
155     
156         if (oneFailed) {
157             result.setStatus(result.FAILED);
158         } else {
159             result.setStatus(result.PASSED);
160         }
161   
162         } else { //(CONTAINER_PERSISTENCE.equals(persistentType))
163
result.addNaDetails(smh.getLocalString
164                        ("tests.componentNameConstructor",
165                     "For [ {0} ]",
166                     new Object JavaDoc[] {compName.toString()}));
167         result.notApplicable(smh.getLocalString
168                      (getClass().getName() + ".notApplicable2",
169                       "Expected persistence type [ {0} ], but bean [ {1} ] has persistence type [ {2} ]",
170                       new Object JavaDoc[] {EjbEntityDescriptor.BEAN_PERSISTENCE,descriptor.getName(),persistentType}));
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