1 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 41 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 servletName; 61 String urlPattern; 62 ConstraintField[] fieldConstraints=null; 63 64 String 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 } 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 [] {mappingFor,descriptor.getName()})); 98 99 } 100 } 101 } } 103 104 } 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 [] {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 mappingFor, 130 WebBundleDescriptor descriptor,WebComponentNameConstructor compName) { 131 132 boolean valid=true; 133 String fieldName; 134 String [] 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 [] {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 [] {fieldName,mappingFor})); 147 148 }else{ 149 valid=false; 150 result.failed(smh.getLocalString 151 ("tests.componentNameConstructor", 152 "For [ {0} ]", 153 new Object [] {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 [] {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 [] {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 [] {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 [] {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 [] {values[rep],mappingFor,descriptor.getName()})); 182 183 } 184 185 } 186 } 187 188 return valid; 189 } 190 191 192 } 193 194 | Popular Tags |