KickJava   Java API By Example, From Geeks To Geeks.

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

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

57     public Result check(EjbDescriptor descriptor) {
58         result = getInitializedResult();
59         compName = getVerifierContext().getComponentNameConstructor();
60         if (descriptor instanceof EjbSessionDescriptor) {
61             if(descriptor.getRemoteClassName() != null && !"".equals(descriptor.getRemoteClassName()))
62                 commonToBothInterfaces(descriptor.getRemoteClassName(),(EjbSessionDescriptor)descriptor);
63             if(descriptor.getLocalClassName() != null && !"".equals(descriptor.getLocalClassName()))
64                 commonToBothInterfaces(descriptor.getLocalClassName(),(EjbSessionDescriptor)descriptor);
65         }
66         if(result.getStatus()!=Result.FAILED && result.getStatus()!=Result.WARNING) {
67             addGoodDetails(result, compName);
68             result.addGoodDetails(smh.getLocalString
69                             (getClass().getName() + ".passed",
70                             "Bean class does not implement the enterprise Bean's remote interface"));
71         }
72         return result;
73     }
74
75     private void commonToBothInterfaces(String JavaDoc component, EjbSessionDescriptor descriptor) {
76         try {
77             Class JavaDoc c = Class.forName(descriptor.getEjbClassName(), false, getVerifierContext().getClassLoader());
78             Class JavaDoc rc = Class.forName(component, false, getVerifierContext().getClassLoader());
79             // walk up the class tree
80
do {
81                 for (Class JavaDoc interfaces : c.getInterfaces()) {
82                     logger.log(Level.FINE, getClass().getName() + ".debug1",
83                             new Object JavaDoc[] {interfaces.getName()});
84                     if (interfaces.getName().equals(rc.getName())) {
85                         // display warning to user
86
addWarningDetails(result, compName);
87                         result.warning(smh.getLocalString
88                                 (getClass().getName() + ".warning",
89                                  "Warning: [ {0} ] class implments the " +
90                                 "enterprise Bean's remote interface [ {1} ]. " +
91                                 "It is recommended that the enterprise bean class not" +
92                                 " implement the remote interface to prevent " +
93                                 "inadvertent passing of this as a method argument or result. ",
94                                  new Object JavaDoc[] {descriptor.getEjbClassName(),rc.getName()}));
95                         break;
96                     }
97                 }
98             } while ((c=c.getSuperclass()) != null);
99         } catch (ClassNotFoundException JavaDoc e) {
100             Verifier.debug(e);
101             addErrorDetails(result, compName);
102             result.failed(smh.getLocalString
103                         (getClass().getName() + ".failedException",
104                                 "Error: [ {0} ] class not found.",
105                                 new Object JavaDoc[] {descriptor.getEjbClassName()}));
106         }
107     }
108 }
109
Popular Tags