KickJava   Java API By Example, From Geeks To Geeks.

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


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

47 public class WebEjbReferencesElement extends WebTest implements WebCheck {
48     boolean oneFailed=false;
49     /**
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 result = getInitializedResult();
58     ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
59     String JavaDoc f=descriptor.getModuleDescriptor().getArchiveUri();
60     loadWarFile(descriptor);
61         result.notApplicable(smh.getLocalString
62            ("tests.componentNameConstructor",
63             "For [ {0} ]",
64             new Object JavaDoc[] {compName.toString()}));
65         result.addNaDetails(smh.getLocalString
66                               (getClass().getName() + ".notApplicable",
67                                "There is no ejb-ref inside [ {0} ].",
68                                new Object JavaDoc[] {compName}));
69         result.addGoodDetails(smh.getLocalString
70                            ("tests.componentNameConstructor",
71                             "For [ {0} ]",
72                             new Object JavaDoc[] {compName}));
73         result.addErrorDetails(smh.getLocalString
74                ("tests.componentNameConstructor",
75                 "For [ {0} ]",
76                 new Object JavaDoc[] {compName.toString()}));
77
78
79         Set references = descriptor.getEjbReferenceDescriptors();
80         Iterator iterator = references.iterator();
81         while (iterator.hasNext()) {
82             EjbReferenceDescriptor ejbReference = (EjbReferenceDescriptor) iterator.next();
83             checkInterface(result, ejbReference, ejbReference.getEjbHomeInterface(), f);
84             checkInterface(result, ejbReference, ejbReference.getEjbInterface(), f);
85         }
86         return result;
87     }
88
89     private void checkInterface(Result result, EjbReferenceDescriptor ejbRef, String JavaDoc intf, String JavaDoc f){
90         Class JavaDoc cl = loadClass(result, intf);
91         if(cl==null){
92             oneFailed=true;
93             result.failed(smh.getLocalString
94                           (getClass().getName() + ".failed",
95                            "Error: For ejb-ref element [ {0} ] the home/component interface class [ {1} ] is not loadable within [ {2} ].",
96                            new Object JavaDoc[] {ejbRef.getName(), intf, f}));
97         }else if(!oneFailed) {
98             result.passed(smh.getLocalString
99                           (getClass().getName() + ".passed",
100                            "For ejb-ref element [ {0} ] the home/component interface class [ {1} ] is loadable within [ {2} ].",
101                            new Object JavaDoc[] {ejbRef.getName(), intf, f}));
102         }
103     }
104 }
105
106
107
Popular Tags