KickJava   Java API By Example, From Geeks To Geeks.

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


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.util.logging.Level JavaDoc;
27
28 import com.sun.enterprise.tools.verifier.tests.*;
29 import com.sun.enterprise.deployment.EjbDescriptor;
30 import com.sun.enterprise.deployment.EjbEntityDescriptor;
31 import com.sun.enterprise.tools.verifier.*;
32 import com.sun.enterprise.tools.verifier.tests.ejb.*;
33
34 /**
35  * The interfaces/classes that the entity bean implements must be serializable
36  * directly or indirectly.
37  * @author Sheetal Vartak
38  */

39 public class EntityBeanExtendsSerializableClass extends EjbTest implements EjbCheck {
40
41     /**
42      * The interfaces/classes that the entity bean implements must be
43      * serializable directly or indirectly.
44      * Ejb 2.1 says that "The bean class that uses the timer service must
45      * implement the javax.ejb.TimedObject interface."
46      * @param descriptor the Enterprise Java Bean deployment descriptor
47      * @return <code>Result</code> the results for this assertion
48      */

49     public Result check(EjbDescriptor descriptor) {
50     Result result = getInitializedResult();
51     ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
52
53     if (descriptor instanceof EjbEntityDescriptor) {
54         try {
55         Class JavaDoc c = Class.forName(descriptor.getEjbClassName(), false, getVerifierContext().getClassLoader());
56
57         boolean validBean = true;
58         Class JavaDoc superClass = c.getSuperclass();
59         if (validBean == true) {
60             // walk up the class tree
61
if(!(superClass.getName()).equals("java.lang.Object")) {
62             if (!isValidSerializableType(superClass) &&
63                     !isTimedObject(superClass)) {
64                 validBean = false;
65                 result.addWarningDetails(smh.getLocalString
66                              ("tests.componentNameConstructor",
67                               "For [ {0} ]",
68                               new Object JavaDoc[] {compName.toString()}));
69                 result.addWarningDetails(smh.getLocalString
70                              (getClass().getName() + ".failed1",
71                               "[ {0} ] extends class [ {1} ] which is not serializable. ",
72                               new Object JavaDoc[] {descriptor.getEjbClassName(),superClass.getName()}));
73                 result.setStatus(Result.WARNING);
74                 return result;
75             } else {
76                 result.addGoodDetails(smh.getLocalString
77                        ("tests.componentNameConstructor",
78                     "For [ {0} ]",
79                     new Object JavaDoc[] {compName.toString()}));
80                 result.addGoodDetails(smh.getLocalString
81                           (getClass().getName() + ".passed1",
82                            "Bean [ {0} ] extends class [ {1} ] which is serializable. ",
83                            new Object JavaDoc[] {descriptor.getEjbClassName(), superClass.getName()}));
84                 do {
85                 Class JavaDoc[] interfaces = c.getInterfaces();
86                 
87                 for (int i = 0; i < interfaces.length; i++) {
88                     
89                     logger.log(Level.FINE, getClass().getName() + ".debug1",
90                             new Object JavaDoc[] {interfaces[i].getName()});
91
92                     if (!isValidSerializableType(interfaces[i])
93                      && !isTimedObject(interfaces[i])) {
94                     validBean = false;
95                     result.addWarningDetails(smh.getLocalString
96                                  ("tests.componentNameConstructor",
97                                   "For [ {0} ]",
98                                   new Object JavaDoc[] {compName.toString()}));
99                     result.addWarningDetails(smh.getLocalString
100                            (getClass().getName() + ".failed",
101                            "[ {0} ] implements interface [ {1} ] which is not serializable. ",
102                            new Object JavaDoc[] {descriptor.getEjbClassName(),interfaces[i].getName()}));
103                     result.setStatus(Result.WARNING);
104                     break;
105                     }
106                 }
107                 } while ((((c=c.getSuperclass()) != null) && (validBean != false)));
108             }
109             }
110             if (validBean == true){
111             result.addGoodDetails(smh.getLocalString
112                           ("tests.componentNameConstructor",
113                            "For [ {0} ]",
114                            new Object JavaDoc[] {compName.toString()}));
115             result.passed(smh.getLocalString
116                       (getClass().getName() + ".passed",
117                        "Bean [ {0} ] implements interfaces which are all serializable. ",
118                        new Object JavaDoc[] {descriptor.getEjbClassName()}));
119             result.setStatus(Result.PASSED);
120             }
121         }
122
123
124         } catch (ClassNotFoundException JavaDoc e) {
125         Verifier.debug(e);
126         result.addErrorDetails(smh.getLocalString
127                        ("tests.componentNameConstructor",
128                     "For [ {0} ]",
129                     new Object JavaDoc[] {compName.toString()}));
130         result.failed(smh.getLocalString
131                   (getClass().getName() + ".failedException",
132                    "Error: [ {0} ] class not found.",
133                    new Object JavaDoc[] {descriptor.getEjbClassName()}));
134         }
135
136         return result;
137         
138     } else {
139         result.addNaDetails(smh.getLocalString
140                 ("tests.componentNameConstructor",
141                  "For [ {0} ]",
142                  new Object JavaDoc[] {compName.toString()}));
143         result.notApplicable(smh.getLocalString
144                  (getClass().getName() + ".notApplicable",
145                   "[ {0} ] expected {1} bean, but called with {2} bean.",
146                   new Object JavaDoc[] {getClass(),"Entity","Session"}));
147         return result;
148     }
149     }
150
151     /** Class checked for implementing java.io.Serializable interface test.
152      * Verify the following:
153      *
154      * The class must implement the java.io.Serializable interface, either
155      * directly or indirectly.
156      *
157      * @param serClass the class to be checked for Rmi-IIOP value type
158      * compliance
159      *
160      * @return <code>boolean</code> true if class implements java.io.Serializable, false otherwise
161      */

162     public static boolean isValidSerializableType(Class JavaDoc serClass) {
163
164         if (java.io.Serializable JavaDoc.class.isAssignableFrom(serClass))
165             return true;
166         else
167             return false;
168     }
169
170     public static boolean isTimedObject(Class JavaDoc serClass) {
171         if (javax.ejb.TimedObject JavaDoc.class.isAssignableFrom(serClass))
172             return true;
173         else
174             return false;
175     }
176 }
177
Popular Tags