KickJava   Java API By Example, From Geeks To Geeks.

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


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 com.sun.enterprise.deployment.*;
27 import com.sun.enterprise.tools.verifier.Result;
28 import com.sun.enterprise.tools.verifier.*;
29 import java.lang.ClassLoader JavaDoc;
30 import com.sun.enterprise.tools.verifier.tests.*;
31
32 /**
33  * Home Interface test.
34  * Verify that the bean home interface class exist and is loadable.
35  * @author Sheetal Vartak
36  */

37 abstract public class HomeInterfaceClassExist extends EjbTest {
38
39     /** Method tells the name of the home interface class that called this test
40      */

41     abstract protected String JavaDoc getHomeInterfaceName(EjbDescriptor descriptor);
42
43     /**
44      * Home Interface test.
45      * Verify that the bean home interface class exist and is loadable.
46      *
47      * @param descriptor the Enterprise Java Bean deployment descriptor
48      *
49      * @return <code>Result</code> the results for this assertion
50      */

51   
52     public Result check(EjbDescriptor descriptor) {
53
54     Result result = getInitializedResult();
55     ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
56         
57     if (!(descriptor instanceof EjbSessionDescriptor) &&
58         !(descriptor instanceof EjbEntityDescriptor)) {
59         result.addNaDetails(smh.getLocalString
60                 ("tests.componentNameConstructor",
61                  "For [ {0} ]",
62                  new Object JavaDoc[] {compName.toString()}));
63         result.notApplicable(smh.getLocalString
64                  ("com.sun.enterprise.tools.verifier.tests.ejb.homeintf.HomeMethodTest.notApplicable1",
65                   "Test apply only to session or entity beans."));
66         return result;
67         }
68
69     if(getHomeInterfaceName(descriptor) == null || "".equals(getHomeInterfaceName(descriptor))){
70             result.addNaDetails(smh.getLocalString
71                         ("tests.componentNameConstructor", "For [ {0} ]",
72                          new Object JavaDoc[] {compName.toString()}));
73             result.notApplicable(smh.getLocalString
74                        ("com.sun.enterprise.tools.verifier.tests.ejb.localinterfaceonly.notapp",
75                         "Not Applicable because, EJB [ {0} ] has Local Interfaces only.",
76                                           new Object JavaDoc[] {descriptor.getEjbClassName()}));
77
78         return result;
79     }
80
81     // verify that the home interface class exist and is loadable
82
try {
83         Context context = getVerifierContext();
84         ClassLoader JavaDoc jcl = context.getClassLoader();
85         Class JavaDoc c = Class.forName(getClassName(descriptor), false, jcl);
86         if (c != null) {
87             result.addGoodDetails(smh.getLocalString
88                       ("tests.componentNameConstructor",
89                        "For [ {0} ]",
90                        new Object JavaDoc[] {compName.toString()}));
91         result.passed(smh.getLocalString
92                   (getClass().getName() + ".passed",
93                    "Home interface [ {0} ] exist and is loadable.",
94                    new Object JavaDoc[] {getClassName(descriptor)}));
95         } else {
96             result.addErrorDetails(smh.getLocalString
97                        ("tests.componentNameConstructor",
98                     "For [ {0} ]",
99                     new Object JavaDoc[] {compName.toString()}));
100         result.failed(smh.getLocalString
101                   (getClass().getName() + ".failed",
102                    "Error: Home interface [ {0} ] does not exist or is not loadable.",
103                    new Object JavaDoc[] {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() + ".failed",
113                "Error: Home interface [ {0} ] does not exist or is not loadable.",
114                new Object JavaDoc[] {getClassName(descriptor)}));
115     }
116     return result;
117     }
118
119     private String JavaDoc getClassName(EjbDescriptor descriptor) {
120     return getHomeInterfaceName(descriptor);
121     }
122 }
123
Popular Tags