KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > verifier > tests > ejb > EjbBeanType


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;
24
25 import java.util.logging.Level JavaDoc;
26
27 import com.sun.enterprise.deployment.EjbDescriptor;
28 import com.sun.enterprise.deployment.EjbEntityDescriptor;
29 import com.sun.enterprise.deployment.EjbSessionDescriptor;
30 import com.sun.enterprise.tools.verifier.Result;
31 import com.sun.enterprise.tools.verifier.Verifier;
32 import com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor;
33
34 /**
35  * Bean type test.
36  * The bean provider must use the appropriate session or entity element
37  * to declare the bean type.
38  */

39 public class EjbBeanType extends EjbTest implements EjbCheck {
40
41
42     /**
43      * Bean Type Test.
44      * The bean provider must use the appropriate session or entity element
45      * to declare the bean type.
46      *
47      * @param descriptor the Enterprise Java Bean deployment descriptor
48      *
49      * @return <code>Result</code> the results for this assertion
50      */

51     public Result check(EjbDescriptor descriptor) {
52
53         Result result = getInitializedResult();
54         ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
55
56         if ((descriptor instanceof EjbSessionDescriptor) ||
57                 (descriptor instanceof EjbEntityDescriptor)) {
58
59             try {
60                 Class JavaDoc c = Class.forName(descriptor.getEjbClassName(), false, getVerifierContext().getClassLoader());
61                 boolean validBean = false;
62                 // walk up the class tree (bug #4243606)
63
do {
64                     Class JavaDoc[] interfaces = c.getInterfaces();
65                     for (int i = 0; i < interfaces.length; i++) {
66                         logger.log(Level.FINE, getClass().getName() + ".debug1",
67                                 new Object JavaDoc[] {interfaces[i].getName()});
68
69                         if (interfaces[i].getName().equals("javax.ejb.EntityBean") &&
70                                 (descriptor instanceof EjbEntityDescriptor)) {
71                             validBean = true;
72                             result.addGoodDetails(smh.getLocalString
73                                     ("tests.componentNameConstructor",
74                                             "For [ {0} ]",
75                                             new Object JavaDoc[] {compName.toString()}));
76                             result.passed(smh.getLocalString
77                                     (getClass().getName() + ".passed",
78                                             "[ {0} ] properly implements the {1}Bean interface.",
79                                             new Object JavaDoc[] {descriptor.getEjbClassName(),"Entity"}));
80                             break;
81                         } else if (interfaces[i].getName().equals("javax.ejb.SessionBean") &&
82                                 descriptor instanceof EjbSessionDescriptor) {
83                             validBean = true;
84                             result.addGoodDetails(smh.getLocalString
85                                     ("tests.componentNameConstructor",
86                                             "For [ {0} ]",
87                                             new Object JavaDoc[] {compName.toString()}));
88                             result.passed(smh.getLocalString
89                                     (getClass().getName() + ".passed",
90                                             "[ {0} ] properly implements the {1}Bean interface.",
91                                             new Object JavaDoc[] {descriptor.getEjbClassName(),"Session"}));
92                             break;
93                         }
94                     }
95                 } while ((((c=c.getSuperclass()) != null) && (!validBean)));
96
97
98                 if (!validBean){
99                     result.addErrorDetails(smh.getLocalString
100                             ("tests.componentNameConstructor",
101                                     "For [ {0} ]",
102                                     new Object JavaDoc[] {compName.toString()}));
103                     result.failed(smh.getLocalString
104                             (getClass().getName() + ".failed",
105                                     "Error: [ {0} ] is not a valid bean. The bean provider must use the appropriate {1} or {2} element to declare the bean type.",
106                                     new Object JavaDoc[] {descriptor.getEjbClassName(),"session","entity"}));
107                 }
108             } catch (ClassNotFoundException JavaDoc e) {
109                 Verifier.debug(e);
110                 result.addErrorDetails(smh.getLocalString
111                         ("tests.componentNameConstructor",
112                                 "For [ {0} ]",
113                                 new Object JavaDoc[] {compName.toString()}));
114                 result.failed(smh.getLocalString
115                         (getClass().getName() + ".failedException",
116                                 "Error: [ {0} ] class not found.",
117                                 new Object JavaDoc[] {descriptor.getEjbClassName()}));
118             }
119             return result;
120
121         } else {
122             result.addNaDetails(smh.getLocalString
123                     ("tests.componentNameConstructor",
124                             "For [ {0} ]",
125                             new Object JavaDoc[] {compName.toString()}));
126             result.notApplicable(smh.getLocalString
127                     (getClass().getName() + ".notApplicable",
128                             "[ {0} ] not called with a Session or Entity Bean.",
129                             new Object JavaDoc[] {getClass()}));
130             return result;
131         }
132     }
133 }
134
Popular Tags