KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > verifier > tests > ejb > beanclass > EjbClassExposed


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.beanclass;
24
25
26 import com.sun.enterprise.deployment.*;
27 import com.sun.enterprise.tools.verifier.*;
28 import com.sun.enterprise.tools.verifier.tests.ejb.EjbTest;
29 import java.lang.reflect.Method JavaDoc;
30 import com.sun.enterprise.tools.verifier.tests.*;
31
32 /**
33  * Enterprise Java Bean class exposed test.
34  * The class must not be exposed through remote or local interfaces.
35  * @author Sheetal Vartak
36  */

37 public class EjbClassExposed extends EjbTest {
38
39     Result result = null;
40     ComponentNameConstructor compName = null;
41     /**
42      * Enterprise Java Bean class exposed test.
43      *
44      * @param descriptor the Enterprise Java Bean deployment descriptor
45      * @return <code>Result</code> the results for this assertion
46      */

47     public Result check(EjbDescriptor descriptor) {
48
49     result = getInitializedResult();
50     compName = getVerifierContext().getComponentNameConstructor();
51
52     if (descriptor instanceof EjbSessionDescriptor ||
53             descriptor instanceof EjbEntityDescriptor) {
54         if (descriptor.getRemoteClassName() != null &&
55                 !((descriptor.getRemoteClassName()).equals("")))
56             commonToBothInterfaces(descriptor.getRemoteClassName(),descriptor);
57         if (descriptor.getLocalClassName() != null &&
58                 !((descriptor.getLocalClassName()).equals("")))
59             commonToBothInterfaces(descriptor.getLocalClassName(),descriptor);
60     }
61
62     if(result.getStatus() != Result.FAILED) {
63         addGoodDetails(result, compName);
64         result.passed(smh.getLocalString(
65                 getClass().getName() + ".passed",
66                 "Ejb Bean Class [{0}] is valid.",
67                 new Object JavaDoc[] {descriptor.getEjbClassName()}));
68     }
69     return result;
70
71     }
72
73     /**
74      * This method is responsible for the logic of the test. It is called for
75      * both local and remote interfaces.
76      * @param descriptor the Enterprise Java Bean deployment descriptor
77      * @param remote for the Remote/Local interface of the Ejb.
78      */

79
80     private void commonToBothInterfaces(String JavaDoc remote, EjbDescriptor descriptor) {
81     try {
82         Class JavaDoc c = Class.forName(remote,
83                                 false,
84                                 getVerifierContext().getClassLoader());
85
86         for (Method JavaDoc method : c.getDeclaredMethods()) {
87             String JavaDoc ejbClassName = descriptor.getEjbClassName();
88             if(((method.getReturnType()).getName()).equals(ejbClassName)) {
89                 addErrorDetails(result, compName);
90                 result.failed(smh.getLocalString(
91                         getClass().getName() + ".failed",
92                         "Error: Ejb Bean Class [{0}] is exposed through interface [{1}]",
93                         new Object JavaDoc[] {ejbClassName, remote}));
94             }
95         }
96     }catch (ClassNotFoundException JavaDoc e) {
97         addErrorDetails(result, compName);
98         result.failed(smh.getLocalString(
99                          getClass().getName() + ".failedException",
100                          "Error: interface class [{0}] not found",
101                          new Object JavaDoc[] {remote}));
102     }
103     }
104 }
105
Popular Tags