KickJava   Java API By Example, From Geeks To Geeks.

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


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.session;
24
25 import com.sun.enterprise.tools.verifier.tests.ejb.EjbTest;
26 import java.lang.ClassLoader JavaDoc;
27 import java.util.logging.Level JavaDoc;
28
29 import com.sun.enterprise.tools.verifier.tests.*;
30 import javax.ejb.SessionBean JavaDoc;
31 import com.sun.enterprise.deployment.EjbDescriptor;
32 import com.sun.enterprise.deployment.EjbSessionDescriptor;
33 import com.sun.enterprise.tools.verifier.*;
34 import com.sun.enterprise.tools.verifier.tests.ejb.EjbCheck;
35
36 /**
37  * Implements the SessionBean Interface test.
38  * All session Beans must implement, directly or indirectly, the SessionBean
39  * interface.
40  */

41 public class SessionBeanInterface extends EjbTest implements EjbCheck {
42
43     /**
44      * Implements the SessionBean Interface test.
45      * All session Beans must implement, directly or indirectly, the SessionBean
46      * interface.
47      *
48      * @param descriptor the Enterprise Java Bean deployment descriptor
49      *
50      * @return <code>Result</code> the results for this assertion
51      */

52     public Result check(EjbDescriptor descriptor) {
53
54     Result result = getInitializedResult();
55     ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
56
57     if (descriptor instanceof EjbSessionDescriptor) {
58         try {
59         Context context = getVerifierContext();
60         ClassLoader JavaDoc jcl = context.getClassLoader();
61         Class JavaDoc c = Class.forName(descriptor.getEjbClassName(), false, getVerifierContext().getClassLoader());
62
63         boolean validBean = false;
64         // walk up the class tree
65
do {
66             Class JavaDoc[] interfaces = c.getInterfaces();
67     
68             for (int i = 0; i < interfaces.length; i++) {
69             logger.log(Level.FINE, getClass().getName() + ".debug1",
70                     new Object JavaDoc[] {interfaces[i].getName()});
71             if (interfaces[i].getName().equals("javax.ejb.SessionBean") &&
72                 descriptor instanceof EjbSessionDescriptor) {
73                 validBean = true;
74                 result.addGoodDetails(smh.getLocalString
75                                 ("tests.componentNameConstructor",
76                                  "For [ {0} ]",
77                                  new Object JavaDoc[] {compName.toString()}));
78                 result.passed(smh.getLocalString
79                       (getClass().getName() + ".passed",
80                        "[ {0} ] properly implements the SessionBean interface.",
81                        new Object JavaDoc[] {descriptor.getEjbClassName()}));
82                 break;
83             }
84             }
85         } while ((((c=c.getSuperclass()) != null) && (!validBean)));
86           
87         if (!validBean) {
88             result.addErrorDetails(smh.getLocalString
89                        ("tests.componentNameConstructor",
90                         "For [ {0} ]",
91                         new Object JavaDoc[] {compName.toString()}));
92             result.failed(smh.getLocalString
93                   (getClass().getName() + ".failed",
94                    "Error: [ {0} ] does not properly implement the SessionBean interface. All session Beans must implement the SessionBean interface. [ {1} ] is not a valid bean.",
95                    new Object JavaDoc[] {descriptor.getEjbClassName(),descriptor.getEjbClassName()}));
96         }
97         } catch (ClassNotFoundException JavaDoc e) {
98         Verifier.debug(e);
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() + ".failedException",
105                    "Error: [ {0} ] class not found.",
106                    new Object JavaDoc[] {descriptor.getEjbClassName()}));
107         }
108         return result;
109  
110     } else {
111         result.addNaDetails(smh.getLocalString
112                 ("tests.componentNameConstructor",
113                  "For [ {0} ]",
114                  new Object JavaDoc[] {compName.toString()}));
115         result.notApplicable(smh.getLocalString
116                  (getClass().getName() + ".notApplicable",
117                   "[ {0} ] expected {1} bean, but called with {2} bean.",
118                   new Object JavaDoc[] {getClass(),"Session","Entity"}));
119         return result;
120     }
121     }
122 }
123
Popular Tags