KickJava   Java API By Example, From Geeks To Geeks.

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

38 //</addition>
39

40 public class ASCacheMappingFieldConstraint extends ASCache implements WebCheck {
41
42
43
44     public Result check(WebBundleDescriptor descriptor) {
45
46
47     Result result = getInitializedResult();
48     ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
49
50         boolean oneFailed = false;
51         boolean notApp = false;
52         boolean doneAtleastOnce=false;
53               
54         try{
55         Cache cache = (descriptor.getSunDescriptor()).getCache();
56         CacheMapping[] cacheMapp=null;
57         String JavaDoc servletName;
58         String JavaDoc urlPattern;
59         ConstraintField[] fieldConstraints=null;
60
61         String JavaDoc mappingFor=null;
62
63         if (cache != null ){
64           cacheMapp=cache.getCacheMapping();
65         }
66
67
68          if (cache != null && cacheMapp !=null && cacheMapp.length !=0 ) {
69             for(int rep=0;rep < cacheMapp.length;rep++){
70
71         servletName = cacheMapp[rep].getServletName();
72                 urlPattern = cacheMapp[rep].getUrlPattern();
73
74                 if(servletName !=null)
75                     mappingFor=servletName;
76                 else
77                     mappingFor=urlPattern;
78
79                 fieldConstraints = cacheMapp[rep].getConstraintField();
80                 if(fieldConstraints !=null && fieldConstraints.length != 0)
81                 {
82                     for(int rep1=0;rep1 < fieldConstraints.length;rep1++){
83                         if(fieldConstraints[rep1] !=null){
84                             doneAtleastOnce=true;
85                             if(checkFieldConstraint(fieldConstraints[rep1],result,mappingFor,descriptor,compName)){
86                                 //nothing more required
87
}
88                             else{
89                                 oneFailed = true;
90                                 addErrorDetails(result, compName);
91                                 result.failed(smh.getLocalString
92                                     (getClass().getName() + ".failed",
93                                     "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} ].",
94                                     new Object JavaDoc[] {mappingFor,descriptor.getName()}));
95
96                             }
97                         }
98                     }//end of for(int rep1=0;rep1 < fieldConstraints.length;rep1++)
99
}
100                 
101             }//end of for(int rep=0;rep < cacheMapp.length;rep++)
102

103           }else {
104               notApp=true;
105           }
106
107         if (oneFailed) {
108             result.setStatus(Result.FAILED);
109         } else if(notApp || !doneAtleastOnce) {
110             result.setStatus(Result.NOT_APPLICABLE);
111             addNaDetails(result, compName);
112             result.notApplicable(smh.getLocalString
113                                      (getClass().getName() + ".notApplicable",
114                                       "NOT APPLICABLE [AS-WEB cache-mapping ] constraint-field not defined in [ {0} ].",
115                                       new Object JavaDoc[] {descriptor.getName()}));
116
117
118
119         }else {
120             result.setStatus(Result.PASSED);
121         }
122         }catch(Exception JavaDoc ex){
123             oneFailed = true;
124             addErrorDetails(result, compName);
125             result.failed(smh.getLocalString
126                 (getClass().getName() + ".failed",
127                     "FAILED [AS-WEB cache-mapping] could not create the cache object"));
128         }
129     return result;
130     }
131
132     
133
134     boolean checkFieldConstraint(ConstraintField fieldCons, Result result,String JavaDoc mappingFor,
135                         WebBundleDescriptor descriptor,ComponentNameConstructor compName) {
136
137           boolean valid=true;
138           String JavaDoc fieldName;
139           String JavaDoc[] values;
140           if (fieldCons != null) {
141             // fieldName= fieldCons.getAttributeValue("name");
142
fieldName= fieldCons.getAttributeValue(ConstraintField.NAME);
143              values=fieldCons.getValue();
144              if(fieldName!=null && ! fieldName.equals("")){
145                 addGoodDetails(result, compName);
146                 result.passed(smh.getLocalString
147                       (getClass().getName() + ".passed1",
148                        "PASSED [AS-WEB cache-mapping] Proper field-constraint/fieldName [ {0} ] defined for [ {1} ].",
149                        new Object JavaDoc[] {fieldName,mappingFor}));
150
151              }else{
152                 valid=false;
153                 addErrorDetails(result, compName);
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                     addGoodDetails(result, compName);
164                     result.passed(smh.getLocalString
165                       (getClass().getName() + ".passed2",
166                        "PASSED [AS-WEB cache-mapping]Proper field-constraint/value [ {0} ] defined for [ {1} ], within the web archive/sun-web.xml of [ {2} ].",
167                        new Object JavaDoc[] {values[rep],mappingFor,descriptor.getName()}));
168
169                 }else {
170                     valid=false;
171                     addErrorDetails(result, compName);
172                     result.failed(smh.getLocalString
173                                       (getClass().getName() + ".failed2",
174                                       "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} ].",
175                                       new Object JavaDoc[] {values[rep],mappingFor,descriptor.getName()}));
176
177                 }
178
179              }
180           }
181
182           return valid;
183     }
184      
185
186 }
187
188
Popular Tags