KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > verifier > tests > web > ias > ASCacheMappingFieldConstraint


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

41 //</addition>
42

43 public class ASCacheMappingFieldConstraint extends ASCache implements WebCheck {
44
45
46
47     public Result check(WebBundleDescriptor descriptor) {
48
49
50     Result result = getInitializedResult();
51     WebComponentNameConstructor compName = new WebComponentNameConstructor(descriptor);
52
53         boolean oneFailed = false;
54         boolean notApp = false;
55         boolean doneAtleastOnce=false;
56          
57         Cache cache = getCache(descriptor);
58
59         CacheMapping[] cacheMapp=null;
60         String JavaDoc servletName;
61         String JavaDoc urlPattern;
62         ConstraintField[] fieldConstraints=null;
63
64         String JavaDoc mappingFor=null;
65
66         if (cache != null ){
67           cacheMapp=cache.getCacheMapping();
68         }
69
70
71          if (cache != null && cacheMapp !=null && cacheMapp.length !=0 ) {
72             for(int rep=0;rep < cacheMapp.length;rep++){
73
74         servletName = cacheMapp[rep].getServletName();
75                 urlPattern = cacheMapp[rep].getUrlPattern();
76
77                 if(servletName !=null)
78                     mappingFor=servletName;
79                 else
80                     mappingFor=urlPattern;
81
82                 fieldConstraints = cacheMapp[rep].getConstraintField();
83
84                 if(fieldConstraints !=null && fieldConstraints.length != 0)
85                 {
86                     for(int rep1=0;rep1 < fieldConstraints.length;rep1++){
87                         if(fieldConstraints[rep1] !=null){
88                             doneAtleastOnce=true;
89                             if(checkFieldConstraint(fieldConstraints[rep1],result,mappingFor,descriptor,compName)){
90                                 //nothing more required
91
}
92                             else{
93                                 oneFailed = true;
94                                 result.failed(smh.getLocalString
95                                     (getClass().getName() + ".failed",
96                                     "FAILED [AS-WEB cache-mapping] List of field-constraint in cache-mapping for [ {0} ] is not proper, within the web archive/sun-web.xml of [ {1} ].",
97                                     new Object JavaDoc[] {mappingFor,descriptor.getName()}));
98
99                             }
100                         }
101                     }//end of for(int rep1=0;rep1 < fieldConstraints.length;rep1++)
102
}
103                 
104             }//end of for(int rep=0;rep < cacheMapp.length;rep++)
105

106           }else {
107               notApp=true;
108           }
109
110         if (oneFailed) {
111             result.setStatus(Result.FAILED);
112         } else if(notApp || !doneAtleastOnce) {
113             result.setStatus(Result.NOT_APPLICABLE);
114         result.notApplicable(smh.getLocalString
115                                  (getClass().getName() + ".notApplicable",
116                                   "NOT APPLICABLE [AS-WEB cache-mapping ] constraint-field not defined in [ {0} ].",
117                                   new Object JavaDoc[] {descriptor.getName()}));
118
119
120
121         }else {
122             result.setStatus(Result.PASSED);
123         }
124     return result;
125     }
126
127     
128
129     boolean checkFieldConstraint(ConstraintField fieldCons, Result result,String JavaDoc mappingFor,
130                         WebBundleDescriptor descriptor,WebComponentNameConstructor compName) {
131
132           boolean valid=true;
133           String JavaDoc fieldName;
134           String JavaDoc[] values;
135           if (fieldCons != null) {
136              fieldName= fieldCons.getAttributeValue("name");
137              values=fieldCons.getValue();
138              if(fieldName!=null && ! fieldName.equals("")){
139                 result.passed(smh.getLocalString
140                        ("tests.componentNameConstructor",
141                     "For [ {0} ]",
142                     new Object JavaDoc[] {compName.toString()}));
143                 result.passed(smh.getLocalString
144                       (getClass().getName() + ".passed1",
145                        "PASSED [AS-WEB cache-mapping] Proper field-constraint/fieldName [ {0} ] defined for [ {1} ].",
146                        new Object JavaDoc[] {fieldName,mappingFor}));
147
148              }else{
149                 valid=false;
150                 result.failed(smh.getLocalString
151                        ("tests.componentNameConstructor",
152                     "For [ {0} ]",
153                     new Object JavaDoc[] {compName.toString()}));
154                 result.failed(smh.getLocalString
155                                       (getClass().getName() + ".failed1",
156                                       "FAILED [AS-WEB cache-mapping] field-constraint/fieldName [ {0} ] defined for [ {1} ], attribute can not be empty.",
157                                       new Object JavaDoc[] {fieldName,mappingFor}));
158
159              }
160
161              for(int rep=0;values !=null && rep < values.length;rep++){
162                 if(values[rep]!=null && ! values[rep].equals("")) {
163                     result.passed(smh.getLocalString
164                        ("tests.componentNameConstructor",
165                     "For [ {0} ]",
166                     new Object JavaDoc[] {compName.toString()}));
167                     result.passed(smh.getLocalString
168                       (getClass().getName() + ".passed2",
169                        "PASSED [AS-WEB cache-mapping]Proper field-constraint/value [ {0} ] defined for [ {1} ], within the web archive/sun-web.xml of [ {2} ].",
170                        new Object JavaDoc[] {values[rep],mappingFor,descriptor.getName()}));
171
172                 }else {
173                     valid=false;
174                     result.failed(smh.getLocalString
175                        ("tests.componentNameConstructor",
176                     "For [ {0} ]",
177                     new Object JavaDoc[] {compName.toString()}));
178                     result.failed(smh.getLocalString
179                                       (getClass().getName() + ".failed2",
180                                       "FAILED [AS-WEB cache-mapping] field-constraint/value [ {0} ] defined for [ {1} ], can not be empty, within the web archive/sun-web.xml of [ {2} ].",
181                                       new Object JavaDoc[] {values[rep],mappingFor,descriptor.getName()}));
182
183                 }
184
185              }
186           }
187
188           return valid;
189     }
190      
191
192 }
193
194
Popular Tags