1 16 package org.apache.myfaces.config.impl.digester; 17 18 import java.util.ArrayList ; 19 import java.util.Collections ; 20 import java.util.HashMap ; 21 import java.util.Iterator ; 22 import java.util.List ; 23 import java.util.Map ; 24 25 import javax.faces.render.RenderKitFactory; 26 27 import org.apache.myfaces.config.FacesConfigDispenser; 28 import org.apache.myfaces.config.impl.digester.elements.Application; 29 import org.apache.myfaces.config.impl.digester.elements.Converter; 30 import org.apache.myfaces.config.impl.digester.elements.FacesConfig; 31 import org.apache.myfaces.config.impl.digester.elements.Factory; 32 import org.apache.myfaces.config.impl.digester.elements.LocaleConfig; 33 import org.apache.myfaces.config.impl.digester.elements.RenderKit; 34 35 36 53 public class DigesterFacesConfigDispenserImpl implements FacesConfigDispenser 54 { 55 56 private List configs = new ArrayList (); 57 private List applicationFactories = new ArrayList (); 58 private List facesContextFactories = new ArrayList (); 59 private List lifecycleFactories = new ArrayList (); 60 private List renderKitFactories = new ArrayList (); 61 private Map components = new HashMap (); 62 private Map validators = new HashMap (); 63 private String defaultRenderKitId; 64 private LocaleConfig localeConfig; 65 private List actionListeners = new ArrayList (); 66 private List lifecyclePhaseListeners = new ArrayList (); 67 private String messageBundle; 68 private List navigationHandlers = new ArrayList (); 69 private List viewHandlers = new ArrayList (); 70 private List stateManagers = new ArrayList (); 71 private List propertyResolver = new ArrayList (); 72 private List variableResolver = new ArrayList (); 73 private Map converterById = new HashMap (); 74 private Map converterByClass = new HashMap (); 75 private Map converterConfigurationByClassName = new HashMap (); 76 private Map renderKits = new HashMap (); 77 private List managedBeans = new ArrayList (); 78 private List navigationRules = new ArrayList (); 79 80 81 86 public void feed(Object facesConfig) 87 { 88 FacesConfig config = (FacesConfig) facesConfig; 89 configs.add(config); 90 for (Iterator iterator = config.getFactories().iterator(); iterator.hasNext();) 91 { 92 Factory factory = (Factory) iterator.next(); 93 applicationFactories.addAll(factory.getApplicationFactory()); 94 facesContextFactories.addAll(factory.getFacesContextFactory()); 95 lifecycleFactories.addAll(factory.getLifecycleFactory()); 96 renderKitFactories.addAll(factory.getRenderkitFactory()); 97 } 98 components.putAll(config.getComponents()); 99 validators.putAll(config.getValidators()); 100 101 for (Iterator iterator = config.getApplications().iterator(); iterator.hasNext();) 102 { 103 Application application = (Application) iterator.next(); 104 if (!application.getDefaultRenderkitId().isEmpty()) 105 { 106 defaultRenderKitId = (String ) application.getDefaultRenderkitId().get(application.getDefaultRenderkitId().size() - 1); 107 } 108 if (!application.getMessageBundle().isEmpty()) 109 { 110 messageBundle = (String ) application.getMessageBundle().get(application.getMessageBundle().size() - 1); 111 } 112 if (!application.getLocaleConfig().isEmpty()) 113 { 114 localeConfig = (LocaleConfig) application.getLocaleConfig().get(application.getLocaleConfig().size() - 1); 115 } 116 actionListeners.addAll(application.getActionListener()); 117 navigationHandlers.addAll(application.getNavigationHandler()); 118 viewHandlers.addAll(application.getViewHandler()); 119 stateManagers.addAll(application.getStateManager()); 120 propertyResolver.addAll(application.getPropertyResolver()); 121 variableResolver.addAll(application.getVariableResolver()); 122 } 123 for (Iterator iterator = config.getConverters().iterator(); iterator.hasNext();) 124 { 125 Converter converter = (Converter) iterator.next(); 126 127 if (converter.getConverterId() != null) 128 { 129 converterById.put(converter.getConverterId(), converter.getConverterClass()); 130 } 131 else 132 { 133 converterByClass.put(converter.getForClass(), converter.getConverterClass()); 134 } 135 136 converterConfigurationByClassName.put(converter.getConverterClass(),converter); 137 } 138 139 for (Iterator iterator = config.getRenderKits().iterator(); iterator.hasNext();) 140 { 141 RenderKit renderKit = (RenderKit) iterator.next(); 142 String renderKitId = renderKit.getId(); 143 144 if (renderKitId == null) { 145 renderKitId = RenderKitFactory.HTML_BASIC_RENDER_KIT; 146 } 147 148 RenderKit existing = (RenderKit) renderKits.get(renderKitId); 149 150 if (existing == null) { 151 renderKits.put(renderKit.getId(), renderKit); 152 } else { 153 existing.merge(renderKit); 154 } 155 } 156 lifecyclePhaseListeners.addAll(config.getLifecyclePhaseListener()); 157 managedBeans.addAll(config.getManagedBeans()); 158 navigationRules.addAll(config.getNavigationRules()); 159 } 160 161 162 167 public void feedApplicationFactory(String factoryClassName) 168 { 169 applicationFactories.add(factoryClassName); 170 } 171 172 173 178 public void feedFacesContextFactory(String factoryClassName) 179 { 180 lifecycleFactories.add(factoryClassName); 181 } 182 183 184 189 public void feedLifecycleFactory(String factoryClassName) 190 { 191 lifecycleFactories.add(factoryClassName); 192 } 193 194 195 200 public void feedRenderKitFactory(String factoryClassName) 201 { 202 renderKitFactories.add(factoryClassName); 203 } 204 205 206 209 public Iterator getApplicationFactoryIterator() 210 { 211 return applicationFactories.iterator(); 212 } 213 214 215 218 public Iterator getFacesContextFactoryIterator() 219 { 220 return facesContextFactories.iterator(); 221 } 222 223 224 227 public Iterator getLifecycleFactoryIterator() 228 { 229 return lifecycleFactories.iterator(); 230 } 231 232 233 236 public Iterator getRenderKitFactoryIterator() 237 { 238 return renderKitFactories.iterator(); 239 } 240 241 242 245 public Iterator getActionListenerIterator() 246 { 247 List listeners = new ArrayList (actionListeners); 248 return listeners.iterator(); 249 } 250 251 252 255 public String getDefaultRenderKitId() 256 { 257 return defaultRenderKitId; 258 } 259 260 261 264 public String getMessageBundle() 265 { 266 return messageBundle; 267 } 268 269 270 273 public Iterator getNavigationHandlerIterator() 274 { 275 List handlers = new ArrayList (navigationHandlers); 276 return handlers.iterator(); 277 } 278 279 280 283 public Iterator getViewHandlerIterator() 284 { 285 List handlers = new ArrayList (viewHandlers); 286 return handlers.iterator(); 287 } 288 289 290 293 public Iterator getStateManagerIterator() 294 { 295 List managers = new ArrayList (stateManagers); 296 return managers.iterator(); 297 } 298 299 300 303 public Iterator getPropertyResolverIterator() 304 { 305 List resolver = new ArrayList (propertyResolver); 306 return resolver.iterator(); 307 } 308 309 310 313 public Iterator getVariableResolverIterator() 314 { 315 List resolver = new ArrayList (variableResolver); 316 317 return resolver.iterator(); 318 } 319 320 321 324 public String getDefaultLocale() 325 { 326 if (localeConfig != null) 327 { 328 return localeConfig.getDefaultLocale(); 329 } 330 return null; 331 } 332 333 334 337 public Iterator getSupportedLocalesIterator() 338 { 339 if (localeConfig != null) 340 { 341 return localeConfig.getSupportedLocales().iterator(); 342 } 343 return Collections.EMPTY_LIST.iterator(); 344 } 345 346 347 350 public Iterator getComponentTypes() 351 { 352 return components.keySet().iterator(); 353 } 354 355 356 359 public String getComponentClass(String componentType) 360 { 361 return (String ) components.get(componentType); 362 } 363 364 365 368 public Iterator getConverterIds() 369 { 370 return converterById.keySet().iterator(); 371 } 372 373 374 377 public Iterator getConverterClasses() 378 { 379 return converterByClass.keySet().iterator(); 380 } 381 382 public Iterator getConverterConfigurationByClassName() 383 { 384 return converterConfigurationByClassName.keySet().iterator(); 385 } 386 387 public Converter getConverterConfiguration(String converterClassName) 388 { 389 return (Converter) converterConfigurationByClassName.get(converterClassName); 390 } 391 392 393 396 public String getConverterClassById(String converterId) 397 { 398 return (String ) converterById.get(converterId); 399 } 400 401 402 405 public String getConverterClassByClass(String className) 406 { 407 return (String ) converterByClass.get(className); 408 } 409 410 411 414 public Iterator getValidatorIds() 415 { 416 return validators.keySet().iterator(); 417 } 418 419 420 423 public String getValidatorClass(String validatorId) 424 { 425 return (String ) validators.get(validatorId); 426 } 427 428 429 432 public Iterator getManagedBeans() 433 { 434 return managedBeans.iterator(); 435 } 436 437 438 441 public Iterator getNavigationRules() 442 { 443 return navigationRules.iterator(); 444 } 445 446 447 450 public Iterator getRenderKitIds() 451 { 452 return renderKits.keySet().iterator(); 453 } 454 455 456 459 public String getRenderKitClass(String renderKitId) 460 { 461 RenderKit renderKit = (RenderKit) renderKits.get(renderKitId); 462 return renderKit.getRenderKitClass(); 463 } 464 465 466 469 public Iterator getRenderers(String renderKitId) 470 { 471 RenderKit renderKit = (RenderKit) renderKits.get(renderKitId); 472 return renderKit.getRenderer().iterator(); 473 } 474 475 476 479 public Iterator getLifecyclePhaseListeners() 480 { 481 return lifecyclePhaseListeners.iterator(); 482 } 483 484 } 485 | Popular Tags |