KickJava   Java API By Example, From Geeks To Geeks.

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


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;
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.EntityBean JavaDoc;
31 import com.sun.enterprise.deployment.EjbDescriptor;
32 import com.sun.enterprise.deployment.EjbEntityDescriptor;
33 import com.sun.enterprise.tools.verifier.*;
34 import com.sun.enterprise.tools.verifier.tests.ejb.EjbCheck;
35
36 /**
37  * Implements the EntityBean Interface test.
38  * All entity Beans must implement, directly or indirectly, the EntityBean
39  * interface.
40  */

41 public class EntityBeanInterface extends EjbTest implements EjbCheck {
42
43     /**
44      * Implements the EntityBeaan Interface test.
45      * All entity Beans must implement, directly or indirectly, the EntityBean
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 EjbEntityDescriptor) {
58         try {
59         Class JavaDoc c = Class.forName(descriptor.getEjbClassName(), false, getVerifierContext().getClassLoader());
60
61         boolean validBean = false;
62         // walk up the class tree
63
do {
64             Class JavaDoc[] interfaces = c.getInterfaces();
65     
66             for (int i = 0; i < interfaces.length; i++) {
67                 logger.log(Level.FINE, getClass().getName() + ".debug1",
68                         new Object JavaDoc[] {interfaces[i].getName()});
69
70             if (interfaces[i].getName().equals("javax.ejb.EntityBean") &&
71                 descriptor instanceof EjbEntityDescriptor) {
72                 validBean = true;
73                 result.addGoodDetails(smh.getLocalString
74                           ("tests.componentNameConstructor",
75                            "For [ {0} ]",
76                            new Object JavaDoc[] {compName.toString()}));
77                 result.passed(smh.getLocalString
78                       (getClass().getName() + ".passed",
79                        "[ {0} ] properly implements the EntityBean interface.",
80                        new Object JavaDoc[] {descriptor.getEjbClassName()}));
81                 break;
82             }
83             }
84         } while ((((c=c.getSuperclass()) != null) && (!validBean)));
85           
86         if (!validBean){
87             result.addErrorDetails(smh.getLocalString
88                        ("tests.componentNameConstructor",
89                         "For [ {0} ]",
90                         new Object JavaDoc[] {compName.toString()}));
91             result.failed(smh.getLocalString
92                   (getClass().getName() + ".failed",
93                    "Error: [ {0} ] does not properly implement the EntityBean interface. All entity beans must implement the EntityBean interface. [ {1} ] is not a valid bean.",
94                    new Object JavaDoc[] {descriptor.getEjbClassName(),descriptor.getEjbClassName()}));
95         }
96         } catch (ClassNotFoundException JavaDoc e) {
97         Verifier.debug(e);
98         result.addErrorDetails(smh.getLocalString
99                        ("tests.componentNameConstructor",
100                     "For [ {0} ]",
101                     new Object JavaDoc[] {compName.toString()}));
102         result.failed(smh.getLocalString
103                   (getClass().getName() + ".failedException",
104                    "Error: [ {0} ] class not found.",
105                    new Object JavaDoc[] {descriptor.getEjbClassName()}));
106         }
107         return result;
108  
109     } else {
110         result.addNaDetails(smh.getLocalString
111                 ("tests.componentNameConstructor",
112                  "For [ {0} ]",
113                  new Object JavaDoc[] {compName.toString()}));
114         result.notApplicable(smh.getLocalString
115                  (getClass().getName() + ".notApplicable",
116                   "[ {0} ] expected {1} bean, but called with {2} bean.",
117                   new Object JavaDoc[] {getClass(),"Entity","Session"}));
118         return result;
119     }
120     }
121 }
122
Popular Tags