KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > verifier > tests > web > elements > WebReferencesInWEBINF


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.web.elements;
24
25 import com.sun.enterprise.tools.verifier.tests.web.WebTest;
26 import com.sun.enterprise.tools.verifier.tests.web.WebCheck;
27 import java.util.*;
28 import com.sun.enterprise.deployment.*;
29 import com.sun.enterprise.tools.verifier.*;
30 import com.sun.enterprise.tools.verifier.tests.*;
31 import com.sun.enterprise.tools.verifier.tests.web.*;
32
33 /**
34  * The Bean Provider must declare all enterprise bean's references to the
35  * homes of other enterprise beans as specified in section 14.3.2 of the
36  * Moscone spec. Check for one within the same jar file, can't check
37  * outside of jar file. Load/locate & check other bean's home/remote/bean,
38  * ensure they match with what the linking bean says they should be; check
39  * for pair of referencing and referenced beans exist.
40  */

41 public class WebReferencesInWEBINF extends WebTest implements WebCheck {
42     Result result = null;
43     ComponentNameConstructor compName = null;
44     EjbReferenceDescriptor ejbReference;
45     Iterator iterator;
46   
47     /**
48      * The referenced Ejb bean/home/component interfaces should exist inside the WEB-INF/classes dir
49      * or the WEB-INF/lib/*.jar. These classes should be loadable by the war file's class loader.
50      *
51      * @param descriptor the Web deployment descriptor
52      *
53      * @return <code>Result</code> the results for this assertion
54      */

55     public Result check(WebBundleDescriptor descriptor) {
56
57         result = getInitializedResult();
58     boolean oneFailed = false;
59     compName = getVerifierContext().getComponentNameConstructor();
60
61     if (descriptor instanceof WebBundleDescriptor) {
62
63         /*
64         The referenced Ejb home/component interfaces should exist inside the WEB-INF/classes dir
65         or the WEB-INF/lib/*.jar. These classes should be loadable by the war file's class loader.
66         */

67        
68         String JavaDoc f = descriptor.getModuleDescriptor().getArchiveUri();
69         Set references = descriptor.getEjbReferenceDescriptors();
70         iterator = references.iterator();
71         result = loadWarFile(descriptor);
72
73         try {
74         if (iterator.hasNext()) {
75             while (iterator.hasNext()) {
76             ejbReference = (EjbReferenceDescriptor) iterator.next();
77             if (ejbReference.isLinked()) { // instanceof EjbDescriptor) {
78
oneFailed = findEjbRef(f);
79             } else {
80                 // (e.g. external references)
81
result.addGoodDetails(smh.getLocalString
82                        ("tests.componentNameConstructor",
83                     "For [ {0} ]",
84                     new Object JavaDoc[] {compName.toString()}));
85                 result.addGoodDetails(smh.getLocalString
86                           (getClass().getName() + ".notApplicable2",
87                            "Not Applicable: [ {0} ] must be external reference to bean outside of [ {1} ].",
88                            new Object JavaDoc[] {ejbReference.getName(),f}));
89             }
90             }
91         }
92         else {
93             result.addNaDetails(smh.getLocalString
94                        ("tests.componentNameConstructor",
95                     "For [ {0} ]",
96                     new Object JavaDoc[] {compName.toString()}));
97             result.notApplicable(smh.getLocalString
98                      (getClass().getName() + ".notApplicable",
99                       "Not Applicable: No EJB references found in [ {0} ]",
100                       new Object JavaDoc[] {f}));
101             return result;
102         }
103         } catch (Exception JavaDoc e) {
104         result.addErrorDetails(smh.getLocalString
105                        ("tests.componentNameConstructor",
106                     "For [ {0} ]",
107                     new Object JavaDoc[] {compName.toString()}));
108         result.failed(smh.getLocalString
109                   (getClass().getName() + ".IOException",
110                    "I/O error trying to open {0}", new Object JavaDoc[] {f}));
111         } finally {
112         try {
113         } catch (Exception JavaDoc x) {}
114         }
115         if (oneFailed) {
116         result.setStatus(Result.FAILED);
117         } else {
118         result.setStatus(Result.PASSED);
119         }
120     } else {
121         result.addNaDetails(smh.getLocalString
122                        ("tests.componentNameConstructor",
123                     "For [ {0} ]",
124                     new Object JavaDoc[] {compName.toString()}));
125         result.notApplicable(smh.getLocalString
126                  (getClass().getName() + ".notApplicable1",
127                   "There are no ejb references to other beans within this web archive [ {0} ]",
128                   new Object JavaDoc[] {descriptor.getName()}));
129     }
130     
131     return result;
132     }
133     
134     private boolean findEjbRef(String JavaDoc f) {
135     
136     boolean oneFailed = false;
137     
138     try {
139       if(ejbReference.getEjbHomeInterface() != null &&
140            !"".equals(ejbReference.getEjbHomeInterface()) &&
141            ejbReference.getEjbInterface() != null &&
142            !"".equals(ejbReference.getEjbInterface())) {
143         oneFailed = common(ejbReference.getEjbHomeInterface(),f);
144             if (oneFailed == true) {
145             result.addErrorDetails(smh.getLocalString
146                        ("tests.componentNameConstructor",
147                     "For [ {0} ]",
148                     new Object JavaDoc[] {compName.toString()}));
149             result.failed(smh.getLocalString
150                       (getClass().getName() + ".failed",
151                        "Error: The [ {0} ] interface of the referenced EJB [ {1} ] is not packaged inside the WEB-INF directory of the war file.",
152                        new Object JavaDoc[] {ejbReference.getEjbHomeInterface(),ejbReference.getName()}));
153             return true;
154             }
155             
156             oneFailed = common(ejbReference.getEjbInterface(),f);
157             if (oneFailed == true) {
158             result.addErrorDetails(smh.getLocalString
159                        ("tests.componentNameConstructor",
160                     "For [ {0} ]",
161                     new Object JavaDoc[] {compName.toString()}));
162             result.failed(smh.getLocalString
163                       (getClass().getName() + ".failed",
164                        "Error: The [ {0} ] interface of the referenced EJB [ {1} ] is not packaged inside the WEB-INF directory of the war file",
165                        new Object JavaDoc[] {ejbReference.getEjbInterface(),ejbReference.getName()}));
166             return true;
167             }
168         }
169         return oneFailed;
170     } catch (NoClassDefFoundError JavaDoc e) {
171         result.addErrorDetails(smh.getLocalString
172                        ("tests.componentNameConstructor",
173                     "For [ {0} ]",
174                     new Object JavaDoc[] {compName.toString()}));
175         result.failed(smh.getLocalString
176               (getClass().getName() + ".failed1",
177                "Error: Bean class [ {0} ] does not exist or is not loadable:NoClassDefFoundError.",
178                new Object JavaDoc[] {ejbReference.getName()}));
179         oneFailed = true;
180         return oneFailed;
181     } catch (Exception JavaDoc e) {
182         Verifier.debug(e);
183         result.addErrorDetails(smh.getLocalString
184                        ("tests.componentNameConstructor",
185                     "For [ {0} ]",
186                     new Object JavaDoc[] {compName.toString()}));
187         result.failed(smh.getLocalString
188               (getClass().getName() + ".failed1",
189                "Error: Bean class [ {0} ] does not exist or is not loadable:ClassNotFoundException",
190                new Object JavaDoc[] {ejbReference.getName()}));
191         oneFailed = true;
192         return oneFailed;
193     }
194     }
195     
196     private boolean common(String JavaDoc intf, String JavaDoc f) {
197     Class JavaDoc cl = loadClass(result, intf);
198     if (cl != null) {
199         result.addGoodDetails(smh.getLocalString
200                        ("tests.componentNameConstructor",
201                     "For [ {0} ]",
202                     new Object JavaDoc[] {compName.toString()}));
203         result.passed(smh.getLocalString
204               (getClass().getName() + ".passed",
205                "The referenced beans home/component [ {0} ] interface exists and is loadable within [ {1} ].",
206                new Object JavaDoc[] {intf,f}));
207         return false;
208     }
209     else return true;
210     }
211 }
212
213
214
Popular Tags