KickJava   Java API By Example, From Geeks To Geeks.

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


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

36 //</addition>
37

38 public class ASResourceEnvRef extends WebTest implements WebCheck {
39
40     public Result check(WebBundleDescriptor descriptor) {
41
42         String JavaDoc resName;
43         Result result = getInitializedResult();
44         ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
45         boolean oneFailed = false;
46         boolean notApp = false;
47         try{
48             ResourceEnvRef[] envRefs= (descriptor.getSunDescriptor()).getResourceEnvRef();
49         
50             if (envRefs != null && envRefs.length > 0) {
51
52                 for (int rep=0; rep<envRefs.length; rep++ ) {
53                 resName = envRefs[rep].getResourceEnvRefName();
54
55                 if (validResEnvRefName(resName,descriptor)) {
56                     addGoodDetails(result, compName);
57                     result.passed(smh.getLocalString
58                       (getClass().getName() + ".passed",
59                        "PASSED [AS-WEB sun-web-app] resource-env-ref [ {0} ] properly defined in the war file.",
60                        new Object JavaDoc[] {resName}));
61                 } else {
62                     oneFailed = true;
63                     addErrorDetails(result, compName);
64                     result.failed(smh.getLocalString
65                                         (getClass().getName() + ".failed",
66                                         "FAILED [AS-WEB sun-web-app] resource-env-ref name [ {0} ] is not valid, either empty or not defined in web.xml.",
67                                         new Object JavaDoc[] {resName}));
68                 }
69
70             }
71
72         } else {
73             notApp = true;
74             addNaDetails(result, compName);
75             result.notApplicable(smh.getLocalString
76                  (getClass().getName() + ".notApplicable",
77                   "NOT APPLICABLE [AS-WEB sun-web-app] resource-env-ref element not defined in the web archive [ {0} ].",
78                   new Object JavaDoc[] {descriptor.getName()}));
79         }
80         if (oneFailed) {
81             result.setStatus(Result.FAILED);
82         } else if(notApp) {
83             result.setStatus(Result.NOT_APPLICABLE);
84         }else {
85             result.setStatus(Result.PASSED);
86             addGoodDetails(result, compName);
87             result.passed
88             (smh.getLocalString
89              (getClass().getName() + ".passed2",
90               "PASSED [AS-WEB sun-web-app] resource-env-ref element(s) are valid within the web archive [ {0} ].",
91                       new Object JavaDoc[] {descriptor.getName()} ));
92         }
93         }catch(Exception JavaDoc ex){
94             oneFailed=true;
95             addErrorDetails(result, compName);
96             result.failed(smh.getLocalString
97                (getClass().getName() + ".failed2", "FAILED [AS-WEB resource-env-ref] Could not create the resource-env-ref"));
98             
99             
100         }
101     
102             return result;
103         }
104     
105
106      boolean validResEnvRefName(String JavaDoc name,WebBundleDescriptor descriptor){
107         boolean valid =true;
108         if(name !=null && name.length()!=0) {
109             try{
110               descriptor.getJmsDestinationReferenceByName(name);
111             }
112             catch(IllegalArgumentException JavaDoc e){
113             valid=false;
114             }
115         } else{
116          valid=false;
117
118         }
119         return valid;
120     }
121
122 }
123
Popular Tags