KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > verifier > tests > web > ias > 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.ias;
25
26 import java.util.*;
27 import com.sun.enterprise.deployment.*;
28 import com.sun.enterprise.tools.verifier.*;
29 import com.sun.enterprise.tools.verifier.tests.*;
30 import com.sun.enterprise.deployment.ResourceReferenceDescriptor;
31 import com.sun.enterprise.deployment.WebBundleDescriptor;
32 import com.sun.enterprise.tools.verifier.tests.web.*;
33
34 import com.sun.enterprise.tools.common.dd.ResourceEnvRef;
35 import com.sun.enterprise.tools.common.dd.webapp.*;
36
37 //<addition author="irfan@sun.com" [bug/rfe]-id="4711198" >
38
/* Changed the result messages to reflect consistency between the result messages generated
39  * for the EJB test cases for SunONE specific deployment descriptors*/

40 //</addition>
41

42 public class ASResourceEnvRef extends WebTest implements WebCheck {
43
44     public Result check(WebBundleDescriptor descriptor) {
45
46         String JavaDoc resName;
47         String JavaDoc resType;
48     Result result = getInitializedResult();
49     WebComponentNameConstructor compName = new WebComponentNameConstructor(descriptor);
50         String JavaDoc jndiName;
51         boolean oneFailed = false;
52         boolean notApp = false;
53         boolean chkOk=true;
54         ResourceEnvRef[] envRefs= descriptor.getIasWebApp().getResourceEnvRef();
55
56     if (envRefs.length > 0) {
57
58              boolean isValidResRefName;
59          for (int rep=0; rep<envRefs.length; rep++ ) {
60                 isValidResRefName=false;
61         resName = envRefs[rep].getResourceEnvRefName();
62                 jndiName = envRefs[rep].getJndiName();
63
64                 if (validResEnvRefName(resName,descriptor)) {
65
66                     isValidResRefName=true;
67                     result.passed(smh.getLocalString
68                       (getClass().getName() + ".passed",
69                        "PASSED [AS-WEB sun-web-app] resource-env-ref [ {0} ] properly defined in the war file.",
70                        new Object JavaDoc[] {resName}));
71                 } else {
72                     if (!oneFailed)
73                         oneFailed = true;
74                     result.failed(smh.getLocalString
75                                         (getClass().getName() + ".failed",
76                                         "FAILED [AS-WEB sun-web-app] resource-env-ref name [ {0} ] is not valid, either empty or not defined in web.xml.",
77                                         new Object JavaDoc[] {resName}));
78                 }
79
80                 if (isValidResRefName && validJndiName(jndiName, resName,descriptor)){
81                     result.passed(smh.getLocalString
82                       (getClass().getName() + ".passed1",
83                        "PASSED [AS-WEB resource-env-ref] jndi-name [ {0} ] properly defined in the war file.",
84                        new Object JavaDoc[] {jndiName}));
85                 } else {
86                     if (!oneFailed)
87                         oneFailed = true;
88                     result.failed(smh.getLocalString
89                                         (getClass().getName() + ".failed1",
90                                         "FAILED [AS-WEB resource-env-ref] jndi-name [ {0} ] is not valid, either empty or not starts with \"jms/\".",
91                                         new Object JavaDoc[] {resName}));
92                 }
93
94             }
95
96         } else {
97             //System.out.println("There are no resource env references defined within the ias-web archive");
98
notApp = true;
99             result.notApplicable(smh.getLocalString
100                  (getClass().getName() + ".notApplicable",
101                   "NOT APPLICABLE [AS-WEB sun-web-app] resource-env-ref element not defined in the web archive [ {0} ].",
102                   new Object JavaDoc[] {descriptor.getName()}));
103         }
104         if (oneFailed) {
105             result.setStatus(Result.FAILED);
106         } else if(notApp) {
107             result.setStatus(Result.NOT_APPLICABLE);
108         }else {
109             result.setStatus(Result.PASSED);
110             result.passed
111             (smh.getLocalString
112              (getClass().getName() + ".passed2",
113               "PASSED [AS-WEB sun-web-app] resource-env-ref element(s) are valid within the web archive [ {0} ].",
114                       new Object JavaDoc[] {descriptor.getName()} ));
115         }
116     return result;
117     }
118
119      boolean validResEnvRefName(String JavaDoc name,WebBundleDescriptor descriptor){
120         boolean valid =true;
121         if(name !=null && name.length()!=0) {
122             try{
123               descriptor.getJmsDestinationReferenceByName(name);
124             }
125             catch(IllegalArgumentException JavaDoc e){
126             valid=false;
127             }
128         } else{
129          valid=false;
130
131         }
132         return valid;
133     }
134
135     boolean validJndiName(String JavaDoc refJndiName, String JavaDoc refName,WebBundleDescriptor descriptor){
136         boolean valid =true;
137         JmsDestinationReferenceDescriptor resDesc;
138
139         if(refJndiName !=null && refJndiName.length()!=0) {
140           //descriptor.getResourceReferenceByName(name);
141
resDesc = descriptor.getJmsDestinationReferenceByName(refName);
142                         String JavaDoc type = resDesc.getRefType();
143                         if(type.indexOf("javax.jms")>-1) //jms resource
144
{
145                             if(!refJndiName.startsWith("jms/"))
146                               valid=false;
147
148                         }
149
150                         else
151                             valid=false;
152          }
153         else{
154         valid=false;
155         }
156
157         return valid;
158     }
159
160
161
162 }
163
Popular Tags