KickJava   Java API By Example, From Geeks To Geeks.

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


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;
24
25 import com.sun.enterprise.tools.verifier.tests.ejb.EjbTest;
26 import com.sun.enterprise.deployment.*;
27 import com.sun.enterprise.tools.verifier.*;
28 import java.lang.ClassLoader JavaDoc;
29 import com.sun.enterprise.tools.verifier.tests.*;
30
31 /**
32  * ejb-jar file must contain the java class file of the enterprise bean
33  * implementation class, and any of the classes that it depends on.
34  */

35 public class JarFileContainsProperEJBClasses extends EjbTest implements EjbCheck {
36
37
38
39     /**
40      * ejb-jar file must contain the java class file of the enterprise bean
41      * implementation class, and any of the classes that it depends on.
42      *
43      * @param descriptor the Enterprise Java Bean deployment descriptor
44      *
45      * @return <code>Result</code> the results for this assertion
46      */

47     public Result check(EjbDescriptor descriptor) {
48
49     Result result = getInitializedResult();
50     ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
51
52     try {
53         Context context = getVerifierContext();
54         Class JavaDoc c = Class.forName(descriptor.getEjbClassName(), false,
55                              getVerifierContext().getClassLoader());
56             // if we are dealing with a CMP2 entity bean, the class is abstract..
57
if (descriptor instanceof EjbEntityDescriptor) {
58             String JavaDoc persistentType =
59             ((EjbEntityDescriptor)descriptor).getPersistenceType();
60             if (EjbEntityDescriptor.CONTAINER_PERSISTENCE.equals(persistentType)) {
61                     if (EjbCMPEntityDescriptor.CMP_1_1!=((EjbCMPEntityDescriptor) descriptor).getCMPVersion()) {
62             result.addGoodDetails(smh.getLocalString
63                           ("tests.componentNameConstructor",
64                            "For [ {0} ]",
65                            new Object JavaDoc[] {compName.toString()}));
66
67                 result.passed(smh.getLocalString
68                       (getClass().getName() + ".passed",
69                        "Bean class [ {0} ] exists and it's supporting classes exist.",
70                        new Object JavaDoc[] {descriptor.getEjbClassName()}));
71                     return result;
72                     }
73                 }
74             }
75
76             try {
77         c.newInstance();
78         result.addGoodDetails(smh.getLocalString
79                       ("tests.componentNameConstructor",
80                        "For [ {0} ]",
81                        new Object JavaDoc[] {compName.toString()}));
82
83         result.passed(smh.getLocalString
84                   (getClass().getName() + ".passed",
85                    "Bean class [ {0} ] exists and it's supporting classes exist.",
86                    new Object JavaDoc[] {descriptor.getEjbClassName()}));
87         } catch (InstantiationException JavaDoc e) {
88         Verifier.debug(e);
89         result.addErrorDetails(smh.getLocalString
90                        ("tests.componentNameConstructor",
91                     "For [ {0} ]",
92                     new Object JavaDoc[] {compName.toString()}));
93
94         result.failed(smh.getLocalString
95                   (getClass().getName() + ".failedException",
96                    "Error: Could not instantiate [ {0} ] within bean [ {1} ]",
97                    new Object JavaDoc[] {descriptor.getEjbClassName(),descriptor.getName()}));
98         } catch (IllegalAccessException JavaDoc e) {
99         Verifier.debug(e);
100         result.addErrorDetails(smh.getLocalString
101                        ("tests.componentNameConstructor",
102                     "For [ {0} ]",
103                     new Object JavaDoc[] {compName.toString()}));
104
105         result.failed(smh.getLocalString
106                   (getClass().getName() + ".failedException1",
107                    "Error: Illegal Access while trying to instantiate [ {0} ] within bean [ {1} ]",
108                    new Object JavaDoc[] {descriptor.getEjbClassName(),descriptor.getName()}));
109         }
110     } catch (ClassNotFoundException JavaDoc e) {
111         Verifier.debug(e);
112         result.addErrorDetails(smh.getLocalString
113                    ("tests.componentNameConstructor",
114                     "For [ {0} ]",
115                     new Object JavaDoc[] {compName.toString()}));
116         
117         result.failed(smh.getLocalString
118               (getClass().getName() + ".failedException2",
119                "Error: Can't find class [ {0} ] within bean [ {1} ]",
120                new Object JavaDoc[] {descriptor.getEjbClassName(),descriptor.getName()}));
121         } catch (Throwable JavaDoc t) {
122         Verifier.debug(t);
123         result.addNaDetails(smh.getLocalString
124                 ("tests.componentNameConstructor",
125                  "For [ {0} ]",
126                  new Object JavaDoc[] {compName.toString()}));
127         
128             result.notApplicable(smh.getLocalString
129                  (getClass().getName() + ".notApplicable",
130                   "Not Applicable: [ {0} ] class encountered [ {1} ]. Cannot create instance of class [ {2} ] becuase [ {3} ] is not accessible within [ {4} ].",
131                   new Object JavaDoc[] {(descriptor).getEjbClassName(),t.toString(), descriptor.getEjbClassName(), t.getMessage(), descriptor.getEjbBundleDescriptor().getModuleDescriptor().getArchiveUri()}));
132     }
133     return result;
134     }
135 }
136
Popular Tags