1 23 package org.hammurapi; 24 25 import java.util.Collection ; 26 import java.util.Collections ; 27 import java.util.HashSet ; 28 import java.util.Iterator ; 29 import java.util.LinkedList ; 30 import java.util.Set ; 31 32 import com.pavelvlasov.config.ConfigurationException; 33 import com.pavelvlasov.config.Parameterizable; 34 35 41 public class InspectorDescriptorStack implements InspectorDescriptor { 42 private LinkedList stack=new LinkedList (); 43 44 public String getDescription() { 45 Iterator it=stack.iterator(); 46 while (it.hasNext()) { 47 InspectorDescriptor descriptor=(InspectorDescriptor) it.next(); 48 if (descriptor.getDescription()!=null) { 49 return descriptor.getDescription(); 50 } 51 } 52 return null; 53 } 54 55 public String getCategory() { 56 Iterator it=stack.iterator(); 57 while (it.hasNext()) { 58 InspectorDescriptor descriptor=(InspectorDescriptor) it.next(); 59 if (descriptor.getCategory()!=null) { 60 return descriptor.getCategory(); 61 } 62 } 63 return "Miscellaneous"; 64 } 65 66 public Boolean isEnabled() { 67 Iterator it=stack.iterator(); 68 while (it.hasNext()) { 69 InspectorDescriptor descriptor=(InspectorDescriptor) it.next(); 70 if (descriptor.isEnabled()!=null) { 71 return descriptor.isEnabled(); 72 } 73 } 74 return null; 75 } 76 77 public String getName() { 78 Iterator it=stack.iterator(); 79 while (it.hasNext()) { 80 InspectorDescriptor descriptor=(InspectorDescriptor) it.next(); 81 if (descriptor.getName()!=null) { 82 return descriptor.getName(); 83 } 84 } 85 return null; 86 } 87 88 Integer defaultSeverity=new Integer (1); 89 private Set parameterized=new HashSet (); 90 91 public Integer getSeverity() { 92 Iterator it=stack.iterator(); 93 while (it.hasNext()) { 94 InspectorDescriptor descriptor=(InspectorDescriptor) it.next(); 95 if (descriptor.getSeverity()!=null) { 96 return descriptor.getSeverity(); 97 } 98 } 99 return defaultSeverity; 100 } 101 102 public Integer getOrder() { 103 Iterator it=stack.iterator(); 104 while (it.hasNext()) { 105 InspectorDescriptor descriptor=(InspectorDescriptor) it.next(); 106 if (descriptor.getOrder()!=null) { 107 return descriptor.getOrder(); 108 } 109 } 110 return null; 111 } 112 113 public String getRationale() { 114 Iterator it=stack.iterator(); 115 while (it.hasNext()) { 116 InspectorDescriptor descriptor=(InspectorDescriptor) it.next(); 117 if (descriptor.getRationale()!=null) { 118 return descriptor.getRationale(); 119 } 120 } 121 return null; 122 } 123 124 public String getViolationSample() { 125 Iterator it=stack.iterator(); 126 while (it.hasNext()) { 127 InspectorDescriptor descriptor=(InspectorDescriptor) it.next(); 128 if (descriptor.getViolationSample()!=null) { 129 return descriptor.getViolationSample(); 130 } 131 } 132 return null; 133 } 134 135 public String getFixSample() { 136 Iterator it=stack.iterator(); 137 while (it.hasNext()) { 138 InspectorDescriptor descriptor=(InspectorDescriptor) it.next(); 139 if (descriptor.getFixSample()!=null) { 140 return descriptor.getFixSample(); 141 } 142 } 143 return null; 144 } 145 146 public String getResources() { 147 Iterator it=stack.iterator(); 148 while (it.hasNext()) { 149 InspectorDescriptor descriptor=(InspectorDescriptor) it.next(); 150 if (descriptor.getResources()!=null) { 151 return descriptor.getResources(); 152 } 153 } 154 return null; 155 } 156 157 public String getMessage() { 158 Iterator it=stack.iterator(); 159 while (it.hasNext()) { 160 InspectorDescriptor descriptor=(InspectorDescriptor) it.next(); 161 if (descriptor.getMessage()!=null) { 162 return descriptor.getMessage(); 163 } 164 } 165 return getDescription(); 166 } 167 168 172 public void addFirst(InspectorDescriptor descriptor) { 173 stack.addFirst(descriptor); 174 } 175 176 public void addLast(InspectorDescriptor descriptor) { 177 stack.addLast(descriptor); 178 } 179 180 public Inspector getInspector() throws ConfigurationException { 181 Iterator it=stack.iterator(); 182 while (it.hasNext()) { 183 InspectorDescriptor descriptor=(InspectorDescriptor) it.next(); 184 Inspector inspector=descriptor.getInspector(); 185 if (inspector!=null) { 186 if (!getParameters().isEmpty()) { 187 if (inspector instanceof Parameterizable) { 188 if (!parameterized.contains(inspector)) { 189 parameterized.add(inspector); 190 Iterator pit=getParameters().iterator(); 191 while (pit.hasNext()) { 192 ParameterEntry pe=(ParameterEntry) pit.next(); 193 if (!((Parameterizable) inspector).setParameter(pe.getName(), pe.getValue())) { 194 throw new ConfigurationException(inspector.getClass().getName()+" does not support parameter "+pe.getName()); 195 } 196 } 197 } 198 } else { 199 throw new ConfigurationException(inspector.getClass().getName()+" does not implement "+Parameterizable.class.getName()); 200 } 201 } 202 return inspector; 203 } 204 } 205 return null; 206 } 207 208 public Collection getParameters() { 209 LinkedList ret=new LinkedList (); 210 LinkedList rstack=new LinkedList (stack); 211 Collections.reverse(rstack); 212 Iterator it=rstack.iterator(); 213 while (it.hasNext()) { 214 Collection params=((InspectorDescriptor) it.next()).getParameters(); 215 if (params!=null) { 216 ret.addAll(params); 217 } 218 } 219 return ret; 220 } 221 222 public String getMessage(String key) { 223 Iterator it=stack.iterator(); 224 while (it.hasNext()) { 225 InspectorDescriptor descriptor=(InspectorDescriptor) it.next(); 226 if (descriptor.getMessage(key)!=null) { 227 return descriptor.getMessage(key); 228 } 229 } 230 return null; 231 } 232 233 public Boolean isWaivable() { 234 Iterator it=stack.iterator(); 235 while (it.hasNext()) { 236 InspectorDescriptor descriptor=(InspectorDescriptor) it.next(); 237 if (descriptor.isWaivable()!=null) { 238 return descriptor.isWaivable(); 239 } 240 } 241 return null; 242 } 243 244 public Collection getWaiveCases() { 245 LinkedList ret=new LinkedList (); 246 Iterator it=ret.iterator(); 247 while (it.hasNext()) { 248 Collection waiveCases=((InspectorDescriptor) it.next()).getWaiveCases(); 249 if (waiveCases!=null) { 250 ret.addAll(waiveCases); 251 } 252 } 253 return ret; 254 } 255 256 public String getWaivedInspectorName(String inspectorKey) { 257 Iterator it=stack.iterator(); 258 while (it.hasNext()) { 259 InspectorDescriptor descriptor=(InspectorDescriptor) it.next(); 260 String ret=descriptor.getWaivedInspectorName(inspectorKey); 261 if (ret!=null) { 262 return ret; 263 } 264 } 265 return null; 266 } 267 268 public String getWaiveReason(String inspectorKey) { 269 Iterator it=stack.iterator(); 270 while (it.hasNext()) { 271 InspectorDescriptor descriptor=(InspectorDescriptor) it.next(); 272 String ret=descriptor.getWaiveReason(inspectorKey); 273 if (ret!=null) { 274 return ret; 275 } 276 } 277 return null; 278 } 279 280 public Collection getWaivedInspectorNames() { 281 LinkedList ret=new LinkedList (); 282 Iterator it=ret.iterator(); 283 while (it.hasNext()) { 284 Collection win=((InspectorDescriptor) it.next()).getWaivedInspectorNames(); 285 if (win!=null) { 286 ret.addAll(win); 287 } 288 } 289 return ret; 290 } 291 292 public Collection getFilteredInspectorDesriptors(InspectorSet inspectorSet, Collection chain) { 293 Iterator it=stack.iterator(); 294 while (it.hasNext()) { 295 chain=((InspectorDescriptor) it.next()).getFilteredInspectorDesriptors(inspectorSet, chain); 296 } 297 return chain; 298 } 299 300 public Collection getAfterInspectorNames() { 301 LinkedList ret=new LinkedList (); 302 Iterator it=ret.iterator(); 303 while (it.hasNext()) { 304 Collection ain=((InspectorDescriptor) it.next()).getAfterInspectorNames(); 305 if (ain!=null) { 306 ret.addAll(ain); 307 } 308 } 309 return ret; 310 } 311 } 312 | Popular Tags |