1 23 package com.sun.enterprise.tools.verifier.tests.web; 24 25 import com.sun.enterprise.tools.verifier.tests.web.WebTest; 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 31 37 public class WebEnvEntryValue extends WebTest implements WebCheck { 38 39 40 50 public Result check(WebBundleDescriptor descriptor) { 51 52 Result result = getInitializedResult(); 53 ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor(); 54 55 boolean oneFailed = false; 56 boolean globalFailed = false; 57 if (!descriptor.getEnvironmentProperties().isEmpty()) { 58 int oneEnvValue = 0; 59 int oneNA = 0; 60 for (Iterator itr2 = descriptor.getEnvironmentProperties().iterator(); 63 itr2.hasNext();) { 64 oneEnvValue++; 65 EnvironmentProperty nextEnvironmentProperty = 66 (EnvironmentProperty) itr2.next(); 67 if ((nextEnvironmentProperty.getValue() != null) && (nextEnvironmentProperty.getValue().length() > 0)) { 68 if (nextEnvironmentProperty.getType().equals("java.lang.String")) { 69 try { 72 new String (nextEnvironmentProperty.getValue()); 73 } catch (Exception e) { 74 if (debug) { 75 e.printStackTrace(); 76 } 77 oneFailed = true; 78 } 79 } else if (nextEnvironmentProperty.getType().equals("java.lang.Character")) { 80 try { 81 if (nextEnvironmentProperty.getValue().length() == 1) { 82 char c = (nextEnvironmentProperty.getValue()).charAt(0); 83 new Character (c); 84 } 85 else oneFailed = true; 86 } catch (Exception e) { 87 if (debug) { 88 e.printStackTrace(); 89 } 90 oneFailed = true; 91 } 92 }else if (nextEnvironmentProperty.getType().equals("java.lang.Integer")) { 93 try { 94 new Integer (nextEnvironmentProperty.getValue()); 95 } catch (NumberFormatException e) { 96 if (debug) { 97 e.printStackTrace(); 98 } 99 oneFailed = true; 100 } 101 } else if (nextEnvironmentProperty.getType().equals("java.lang.Boolean")) { 102 try { 105 new Boolean (nextEnvironmentProperty.getValue()); 106 } catch (Exception e) { 107 if (debug) { 108 e.printStackTrace(); 109 } 110 oneFailed = true; 111 } 112 } else if (nextEnvironmentProperty.getType().equals("java.lang.Double")) { 113 try { 114 new Double (nextEnvironmentProperty.getValue()); 115 } catch (NumberFormatException e) { 116 if (debug) { 117 e.printStackTrace(); 118 } 119 oneFailed = true; 120 } 121 } else if (nextEnvironmentProperty.getType().equals("java.lang.Byte")) { 122 try { 123 new Byte (nextEnvironmentProperty.getValue()); 124 } catch (NumberFormatException e) { 125 if (debug) { 126 e.printStackTrace(); 127 } 128 oneFailed = true; 129 } 130 } else if (nextEnvironmentProperty.getType().equals("java.lang.Short")) { 131 try { 132 new Short (nextEnvironmentProperty.getValue()); 133 } catch (NumberFormatException e) { 134 if (debug) { 135 e.printStackTrace(); 136 } 137 oneFailed = true; 138 } 139 } else if (nextEnvironmentProperty.getType().equals("java.lang.Long")) { 140 try { 141 new Long (nextEnvironmentProperty.getValue()); 142 } catch (NumberFormatException e) { 143 if (debug) { 144 e.printStackTrace(); 145 } 146 oneFailed = true; 147 } 148 } else if (nextEnvironmentProperty.getType().equals("java.lang.Float")) { 149 try { 150 new Float (nextEnvironmentProperty.getValue()); 151 } catch (NumberFormatException e) { 152 if (debug) { 153 e.printStackTrace(); 154 } 155 oneFailed = true; 156 } 157 } else { 158 oneFailed = true; 159 } 160 if (oneFailed) { 161 result.addErrorDetails(smh.getLocalString 162 ("tests.componentNameConstructor", 163 "For [ {0} ]", 164 new Object [] {compName.toString()})); 165 result.addErrorDetails 166 (smh.getLocalString 167 (getClass().getName() + ".failed", 168 "Error: Environment entry value [ {0} ] does not have valid value [ {1} ] for constructor of the specified type [ {2} ] that takes a single String parameter within web archive [ {3} ]", 169 new Object [] {nextEnvironmentProperty.getName(),nextEnvironmentProperty.getValue(),nextEnvironmentProperty.getType(),descriptor.getName()})); 170 globalFailed = true; 171 oneFailed = false; 172 } else { 173 result.addGoodDetails(smh.getLocalString 174 ("tests.componentNameConstructor", 175 "For [ {0} ]", 176 new Object [] {compName.toString()})); 177 result.addGoodDetails 178 (smh.getLocalString 179 (getClass().getName() + ".passed", 180 "Environment entry value [ {0} ] has valid value [ {1} ] for constructor of the specified type [ {2} ] that takes a single String parameter within web archive [ {3} ]", 181 new Object [] {nextEnvironmentProperty.getName(),nextEnvironmentProperty.getValue(),nextEnvironmentProperty.getType(),descriptor.getName()})); 182 } 183 } else { 184 result.addNaDetails(smh.getLocalString 188 ("tests.componentNameConstructor", 189 "For [ {0} ]", 190 new Object [] {compName.toString()})); 191 result.addNaDetails(smh.getLocalString 192 (getClass().getName() + ".notApplicable1", 193 "Environment entry [ {0} ] initial value is not defined within web application [ {1} ]", 194 new Object [] {nextEnvironmentProperty.getName(), descriptor.getName()})); 195 oneNA++; 196 } 197 } 198 if (globalFailed){ 199 result.setStatus(Result.FAILED); 200 } else if (oneNA == oneEnvValue) { 201 result.setStatus(Result.NOT_APPLICABLE); 202 } else { 203 result.setStatus(Result.PASSED); 204 } 205 } else { 206 result.addNaDetails(smh.getLocalString 207 ("tests.componentNameConstructor", 208 "For [ {0} ]", 209 new Object [] {compName.toString()})); 210 result.notApplicable(smh.getLocalString 211 (getClass().getName() + ".notApplicable", 212 "There are no environment entry elements defined within this web archive [ {0} ]", 213 new Object [] {descriptor.getName()})); 214 } 215 216 return result; 217 } 218 } 219 | Popular Tags |