KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > verifier > tests > ejb > homeintf > HomeInterfaceExtendsRightInterface


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.homeintf;
24
25 import com.sun.enterprise.tools.verifier.tests.ejb.EjbTest;
26 import java.lang.ClassLoader JavaDoc;
27 import com.sun.enterprise.tools.verifier.tests.ejb.EjbCheck;
28 import com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor;
29 import com.sun.enterprise.tools.verifier.Result;
30 import com.sun.enterprise.tools.verifier.Context;
31 import com.sun.enterprise.tools.verifier.Verifier;
32 import com.sun.enterprise.deployment.EjbDescriptor;
33 import com.sun.enterprise.deployment.EjbSessionDescriptor;
34 import com.sun.enterprise.deployment.EjbEntityDescriptor;
35
36 /**
37  * Extends the EJBHome Interface test.
38  * All enterprise beans home interface's must extend the EJBHome interface.
39  */

40 abstract public class HomeInterfaceExtendsRightInterface extends EjbTest implements EjbCheck {
41  
42     /** Method tells the name of the home interface class that called this test
43      */

44     abstract protected String JavaDoc getHomeInterfaceName(EjbDescriptor descriptor);
45     abstract protected String JavaDoc getSuperInterface();
46     
47     /**
48      * Extends the EJBHome Interface test.
49      * All enterprise beans home interface's must extend the EJBHome interface.
50      *
51      * @param descriptor the Enterprise Java Bean deployment descriptor
52      *
53      * @return <code>Result</code> the results for this assertion
54      */

55
56   
57     public Result check(EjbDescriptor descriptor) {
58
59     Result result = getInitializedResult();
60     ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
61     String JavaDoc str = null;
62
63     if(getHomeInterfaceName(descriptor) == null || "".equals(getHomeInterfaceName(descriptor))){
64             result.addNaDetails(smh.getLocalString
65                         ("tests.componentNameConstructor", "For [ {0} ]",
66                          new Object JavaDoc[] {compName.toString()}));
67             result.notApplicable(smh.getLocalString
68                        ("com.sun.enterprise.tools.verifier.tests.ejb.localinterfaceonly.notapp",
69                         "Not Applicable because, EJB [ {0} ] has Local Interfaces only.",
70                                           new Object JavaDoc[] {descriptor.getEjbClassName()}));
71
72         return result;
73     }
74
75     if ((descriptor instanceof EjbSessionDescriptor) ||
76         (descriptor instanceof EjbEntityDescriptor)) {
77  
78         try {
79         Context context = getVerifierContext();
80         ClassLoader JavaDoc jcl = context.getClassLoader();
81         Class JavaDoc c = Class.forName(getClassName(descriptor), false, jcl);
82         str = getSuperInterface();
83                 if (isImplementorOf(c, str)) {
84             // it extends the proper EJBHome
85
result.addGoodDetails(smh.getLocalString
86                       ("tests.componentNameConstructor",
87                        "For [ {0} ]",
88                        new Object JavaDoc[] {compName.toString()}));
89             result.passed(smh.getLocalString
90                   (getClass().getName() + ".passed",
91                    "[ {0} ] properly extends the " + str + "interface.",
92                    new Object JavaDoc[] {getClassName(descriptor)}));
93                 } else {
94             result.addErrorDetails(smh.getLocalString
95                        ("tests.componentNameConstructor",
96                         "For [ {0} ]",
97                         new Object JavaDoc[] {compName.toString()}));
98             result.failed(smh.getLocalString
99                   (getClass().getName() + ".failed",
100                    "Error: [ {0} ] does not properly extend the " + str +
101                    " interface. All enterprise beans home interfaces must extend the " + str +
102                    " interface. [ {1} ] is not a valid home interface.",
103                    new Object JavaDoc[] {getClassName(descriptor),getClassName(descriptor)}));
104         }
105         } catch (ClassNotFoundException JavaDoc e) {
106         Verifier.debug(e);
107         result.addErrorDetails(smh.getLocalString
108                        ("tests.componentNameConstructor",
109                     "For [ {0} ]",
110                     new Object JavaDoc[] {compName.toString()}));
111         result.failed(smh.getLocalString
112                   (getClass().getName() + ".failedException",
113                    "Error: [ {0} ] class not found.",
114                    new Object JavaDoc[] {getClassName(descriptor)}));
115         }
116         return result;
117  
118     } else {
119         result.addNaDetails(smh.getLocalString
120                 ("tests.componentNameConstructor",
121                  "For [ {0} ]",
122                  new Object JavaDoc[] {compName.toString()}));
123         result.notApplicable(smh.getLocalString
124                  (getClass().getName() + ".notApplicable",
125                   "[ {0} ] expected {1} bean or {2} bean, but called with {3}.",
126                   new Object JavaDoc[] {getClass(),"Session","Entity",descriptor.getName()}));
127         return result;
128     }
129     }
130
131     private String JavaDoc getClassName(EjbDescriptor descriptor) {
132     return getHomeInterfaceName(descriptor);
133     }
134 }
135
Popular Tags