1 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 38 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 servletName; 58 String urlPattern; 59 ConstraintField[] fieldConstraints=null; 60 61 String 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 } 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 [] {mappingFor,descriptor.getName()})); 95 96 } 97 } 98 } } 100 101 } 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 [] {descriptor.getName()})); 116 117 118 119 }else { 120 result.setStatus(Result.PASSED); 121 } 122 }catch(Exception 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 mappingFor, 135 WebBundleDescriptor descriptor,ComponentNameConstructor compName) { 136 137 boolean valid=true; 138 String fieldName; 139 String [] values; 140 if (fieldCons != null) { 141 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 [] {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 [] {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 [] {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 [] {values[rep],mappingFor,descriptor.getName()})); 176 177 } 178 179 } 180 } 181 182 return valid; 183 } 184 185 186 } 187 188 | Popular Tags |