KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > verifier > tests > ejb > intf > ExtendsRightInterface


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.intf;
24
25 import com.sun.enterprise.tools.verifier.tests.ejb.EjbTest;
26 import com.sun.enterprise.tools.verifier.tests.ejb.EjbCheck;
27 import com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor;
28 import com.sun.enterprise.tools.verifier.Result;
29 import com.sun.enterprise.tools.verifier.Verifier;
30 import com.sun.enterprise.deployment.EjbDescriptor;
31 import com.sun.enterprise.deployment.EjbSessionDescriptor;
32 import com.sun.enterprise.deployment.EjbEntityDescriptor;
33
34 /**
35  * Remote interfaces extend the EJBObject interface test. Local interfaces extend
36  * the EJBLocalObject interface test.
37  * All enterprise beans remote interfaces must extend the EJBObject interface
38  * and/or local interfaces must extend the EJBLocalObject interface.
39  *
40  * @author Sheetal Vartak
41  */

42 abstract public class ExtendsRightInterface extends EjbTest implements EjbCheck {
43     /**
44      * Following 3 methods are used to determine whether this method is being called by
45      * local/remote interface.
46      */

47     abstract protected String JavaDoc getInterfaceName(EjbDescriptor descriptor);
48     abstract protected String JavaDoc getSuperInterface();
49     abstract protected String JavaDoc getInterfaceType();
50     
51     /**
52      * local interfaces extend the EJBLocalObject interface and remote interfaces
53      * extend the EJBObject interface test.
54      * All enterprise beans remote interfaces must extend the EJBObject interface
55      * and/or local interfaces must extend the EJBLocalObject interface.
56      *
57      * @param descriptor the Enterprise Java Bean deployment descriptor
58      * @return <code>Result</code> the results for this assertion
59      */

60     public Result check(EjbDescriptor descriptor) {
61         
62         Result result = getInitializedResult();
63         ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
64         String JavaDoc str = null;
65         
66         if (!(descriptor instanceof EjbSessionDescriptor) &&
67                 !(descriptor instanceof EjbEntityDescriptor)) {
68             addNaDetails(result, compName);
69             result.notApplicable(smh.getLocalString
70                     ("com.sun.enterprise.tools.verifier.tests.ejb.homeintf.HomeMethodTest.notApplicable1",
71                     "Test apply only to session or entity beans."));
72             return result;
73         }
74         
75         if(getInterfaceName(descriptor) == null || "".equals(getInterfaceName(descriptor))) {
76             addNaDetails(result, compName);
77             result.notApplicable(smh.getLocalString
78                     ("com.sun.enterprise.tools.verifier.tests.ejb.intf.InterfaceTest.notApplicable",
79                     "Not Applicable because, EJB [ {0} ] does not have {1} Interface.",
80                     new Object JavaDoc[] {descriptor.getEjbClassName(), getInterfaceType()}));
81             return result;
82         }
83         
84         try {
85             ClassLoader JavaDoc jcl = getVerifierContext().getClassLoader();
86             Class JavaDoc c = Class.forName(getClassName(descriptor), false, jcl);
87             str = getSuperInterface();
88             
89             if (isImplementorOf(c, str)) {
90                 addGoodDetails(result, compName);
91                 result.passed(smh.getLocalString
92                         (getClass().getName() + ".passed",
93                         "[ {0} ] " + getInterfaceType() +" interface properly extends the" + str + " interface.",
94                         new Object JavaDoc[] {getClassName(descriptor)}));
95             } else {
96                 addErrorDetails(result, compName);
97                 result.failed(smh.getLocalString
98                         (getClass().getName() + ".failed",
99                         "Error: [ {0} ] does not properly extend the EJBObject interface. "+
100                         " All enterprise bean" + getInterfaceType() + " interfaces must extend the" + str + " interface."+
101                         " [ {1} ] is not a valid "+ getInterfaceType() + "interface within bean [ {2} ]",
102                         new Object JavaDoc[] {getClassName(descriptor),getClassName(descriptor),descriptor.getName()}));
103             }
104         } catch (ClassNotFoundException JavaDoc e) {
105             Verifier.debug(e);
106             addErrorDetails(result, compName);
107             result.failed(smh.getLocalString
108                     (getClass().getName() + ".failedException",
109                     "Error: [ {0} ] class not found.",
110                     new Object JavaDoc[] {getClassName(descriptor)}));
111         }
112         return result;
113     }
114     //get the interface class name
115
private String JavaDoc getClassName(EjbDescriptor descriptor) {
116         return getInterfaceName(descriptor);
117     }
118 }
119
Popular Tags