KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > verifier > tests > web > runtime > ASWebEjbRef


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
24 package com.sun.enterprise.tools.verifier.tests.web.runtime;
25
26
27 import com.sun.enterprise.tools.verifier.tests.web.WebTest;
28 import com.sun.enterprise.tools.verifier.tests.web.WebCheck;
29 import com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor;
30 import com.sun.enterprise.tools.verifier.Result;
31 import com.sun.enterprise.deployment.runtime.common.EjbRef;
32 import com.sun.enterprise.deployment.WebBundleDescriptor;
33
34 //<addition author="irfan@sun.com" [bug/rfe]-id="4711198" >
35
/* Changed the result messages to reflect consistency between the result messages generated
36  * for the EJB test cases for SunONE specific deployment descriptors*/

37 //</addition>
38

39 public class ASWebEjbRef extends WebTest implements WebCheck {
40
41     public Result check(WebBundleDescriptor descriptor) {
42         Result result = getInitializedResult();
43         ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
44         boolean oneFailed = false;
45         String JavaDoc refName;
46         EjbRef[] ejbRefs = (descriptor.getSunDescriptor()).getEjbRef();
47         if (ejbRefs!=null && ejbRefs.length > 0) {
48             for (int rep=0; rep<ejbRefs.length; rep++ ) {
49                 refName = ejbRefs[rep].getEjbRefName();
50                 if (validEjbRefName(refName,descriptor)) {
51                     addGoodDetails(result, compName);
52                     result.passed(smh.getLocalString
53                             (getClass().getName() + ".passed",
54                                     "PASSED [AS-WEB ejb-ref] ejb-ref-name [ {0} ] properly defined in the war file.",
55                                     new Object JavaDoc[] {refName}));
56                 } else {
57                     oneFailed = true;
58                     addErrorDetails(result, compName);
59                     result.failed(smh.getLocalString
60                             (getClass().getName() + ".failed",
61                                     "FAILED [AS-WEB ejb-ref] ejb-ref-name [ {0} ] is not valid, either empty or not defined in web.xml.",
62                                     new Object JavaDoc[] {refName}));
63                 }
64             }
65         } else {
66             addNaDetails(result, compName);
67             result.notApplicable(smh.getLocalString
68                     (getClass().getName() + ".notApplicable",
69                             "NOT APPLICABLE [AS-WEB sun-web-app] ejb-ref element(s) not defined in the web archive [ {0} ].",
70                             new Object JavaDoc[] {descriptor.getName()}));
71             return result;
72         }
73         if (oneFailed)
74         {
75             result.setStatus(Result.FAILED);
76         } else {
77             addGoodDetails(result, compName);
78             result.passed
79                     (smh.getLocalString
80                     (getClass().getName() + ".passed2",
81                             "PASSED [AS-WEB sun-web-app] ejb-ref element(s) defined are valid within the web archive [ {0} ].",
82                             new Object JavaDoc[] {descriptor.getName()} ));
83         }
84         return result;
85     }
86
87     boolean validEjbRefName(String JavaDoc name,WebBundleDescriptor descriptor){
88         boolean valid =true;
89         if(name !=null && name.length()!=0) {
90             try{
91                 descriptor.getEjbReferenceByName(name);
92             }
93             catch(IllegalArgumentException JavaDoc e){
94                 valid=false;
95             }
96         }else{
97             valid=false;
98         }
99         return valid;
100     }
101 }
102
Popular Tags