KickJava   Java API By Example, From Geeks To Geeks.

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


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.*;
30 import com.sun.enterprise.tools.verifier.*;
31 import com.sun.enterprise.tools.verifier.tests.ejb.EjbCheck;
32
33 /**
34  * Optionally implements the enterprise Bean's remote interface test.
35  * The class may, but is not required to, implement the enterprise Bean's
36  * remote interface. It is recommended that the enterprise bean class
37  * not implement the remote interface to prevent inadvertent passing of
38  * this as a method argument or result.
39  * Note: Display warning to user in this instance.
40  */

41 public class EjbClassImplementsComponentInterface extends EjbTest implements EjbCheck {
42     Result result = null;
43     ComponentNameConstructor compName = null;
44     /**
45      * Optionally implements the enterprise Bean's remote interface test.
46      * The class may, but is not required to, implement the enterprise Bean's
47      * remote interface. It is recommended that the enterprise bean class
48      * not implement the remote interface to prevent inadvertent passing of
49      * this as a method argument or result.
50      * Note: Display warning to user in this instance.
51      *
52      * @param descriptor the Enterprise Java Bean deployment descriptor
53      *
54      * @return <code>Result</code> the results for this assertion
55      */

56     public Result check(EjbDescriptor descriptor) {
57
58     result = getInitializedResult();
59     compName = getVerifierContext().getComponentNameConstructor();
60
61     if (descriptor instanceof EjbEntityDescriptor) {
62         if(descriptor.getRemoteClassName() != null && !"".equals(descriptor.getRemoteClassName()))
63         commonToBothInterfaces(descriptor.getRemoteClassName(),(EjbEntityDescriptor)descriptor);
64         if(descriptor.getLocalClassName() != null && !"".equals(descriptor.getLocalClassName()))
65         commonToBothInterfaces(descriptor.getLocalClassName(),(EjbEntityDescriptor)descriptor);
66         
67         return result;
68  
69     } else {
70         result.addNaDetails(smh.getLocalString
71                 ("tests.componentNameConstructor",
72                  "For [ {0} ]",
73                  new Object JavaDoc[] {compName.toString()}));
74         result.notApplicable(smh.getLocalString
75                  (getClass().getName() + ".notApplicable",
76                   "[ {0} ] expected {1} bean, but called with {2} bean.",
77                   new Object JavaDoc[] {getClass(),"Entity","Session"}));
78         return result;
79     }
80     }
81
82     private void commonToBothInterfaces(String JavaDoc component, EjbDescriptor descriptor) {
83     try {
84         Class JavaDoc c = Class.forName(descriptor.getEjbClassName(), false, getVerifierContext().getClassLoader());
85         Class JavaDoc rc = Class.forName(component, false, getVerifierContext().getClassLoader());
86         boolean foundOne = false;
87         // walk up the class tree
88
do {
89         Class JavaDoc[] interfaces = c.getInterfaces();
90         
91         for (int i = 0; i < interfaces.length; i++) {
92             logger.log(Level.FINE, getClass().getName() + ".debug1",
93                     new Object JavaDoc[] {interfaces[i].getName()});
94
95             if (interfaces[i].getName().equals(rc.getName()) &&
96             descriptor instanceof EjbEntityDescriptor) {
97             // display warning to user
98
result.addWarningDetails(smh.getLocalString
99                          ("tests.componentNameConstructor",
100                           "For [ {0} ]",
101                           new Object JavaDoc[] {compName.toString()}));
102             result.warning(smh.getLocalString
103                        (getClass().getName() + ".warning",
104                     "Warning: [ {0} ] class implments the enterprise Bean's remote interface [ {1} ]. It is recommended that the enterprise bean class not implement the remote interface to prevent inadvertent passing of this as a method argument or result. The class must provide no-op implementations of the methods defined in the javax.ejb.EJBObject interface.",
105                     new Object JavaDoc[] {descriptor.getEjbClassName(),rc.getName()}));
106             foundOne = true;
107             break;
108             }
109         }
110         } while ((c=c.getSuperclass()) != null);
111         
112         if (!foundOne) {
113         // does not implement Bean's remote interface, test n/a
114
result.addNaDetails(smh.getLocalString
115                     ("tests.componentNameConstructor",
116                      "For [ {0} ]",
117                      new Object JavaDoc[] {compName.toString()}));
118         result.notApplicable(smh.getLocalString
119                      (getClass().getName() + ".notApplicable2",
120                       "[ {0} ] does not optionally implement bean class remote interface [ {1} ]",
121                       new Object JavaDoc[] {descriptor.getEjbClassName(),rc.getName()}));
122         } else {
123         // if the class implements the enterprise Bean's remote interface,
124
// the class must provide no-op implementations of the methods
125
// defined in the javax.ejb.EJBObject interface.
126

127         // i can check all methods defined within javax.ejb.EJBObject
128
// interface, but i can't tell whether they are no-ops
129
// do nothing
130
}
131     } catch (ClassNotFoundException JavaDoc e) {
132         Verifier.debug(e);
133         result.addErrorDetails(smh.getLocalString
134                    ("tests.componentNameConstructor",
135                     "For [ {0} ]",
136                     new Object JavaDoc[] {compName.toString()}));
137         result.failed(smh.getLocalString
138               (getClass().getName() + ".failedException",
139                "Error: [ {0} ] class not found.",
140                new Object JavaDoc[] {descriptor.getEjbClassName()}));
141     }
142     }
143 }
144
Popular Tags