}
}
private void configureApplication()
{
Application application = ((ApplicationFactory)
FactoryFinder.getFactory(FactoryFinder.APPLICATION_FACTORY)).getApplication();
FacesConfigData dispenser = getDispenser();
application.setActionListener(ClassUtils.buildApplicationObject(ActionListener.class,
dispenser.getActionListenerIterator(), null));
if (dispenser.getDefaultLocale() != null)
{
application.setDefaultLocale(LocaleUtils.toLocale(dispenser.getDefaultLocale()));
}
if (dispenser.getDefaultRenderKitId() != null)
{
application.setDefaultRenderKitId(dispenser.getDefaultRenderKitId());
}
if (dispenser.getMessageBundle() != null)
{
application.setMessageBundle(dispenser.getMessageBundle());
}
application.setNavigationHandler(ClassUtils.buildApplicationObject(NavigationHandler.class,
ConfigurableNavigationHandler.class,
BackwardsCompatibleNavigationHandlerWrapper.class,
dispenser.getNavigationHandlerIterator(),
application.getNavigationHandler()));
application.setStateManager(ClassUtils.buildApplicationObject(StateManager.class,
dispenser.getStateManagerIterator(),
application.getStateManager()));
application.setResourceHandler(ClassUtils.buildApplicationObject(ResourceHandler.class,
dispenser.getResourceHandlerIterator(),
application.getResourceHandler()));
List<Locale> locales = new ArrayList<Locale>();
for (String locale : dispenser.getSupportedLocalesIterator())
{
locales.add(LocaleUtils.toLocale(locale));
}
application.setSupportedLocales(locales);
application.setViewHandler(ClassUtils.buildApplicationObject(ViewHandler.class,
dispenser.getViewHandlerIterator(),
application.getViewHandler()));
for (SystemEventListener systemEventListener : dispenser.getSystemEventListeners())
{
try
{
//note here used to be an instantiation to deal with the explicit source type in the registration,
// that cannot work because all system events need to have the source being passed in the constructor
//instead we now rely on the standard system event types and map them to their appropriate
// constructor types
Class eventClass = ClassUtils.classForName((systemEventListener.getSystemEventClass() != null)
? systemEventListener.getSystemEventClass()
: SystemEvent.class.getName());
if (systemEventListener.getSourceClass() != null && systemEventListener.getSourceClass().length() > 0)
{
application.subscribeToEvent(
(Class<? extends SystemEvent>) eventClass,
ClassUtils.classForName(systemEventListener.getSourceClass()),
(javax.faces.event.SystemEventListener)
ClassUtils.newInstance(systemEventListener.getSystemEventListenerClass()));
}
else
{
application.subscribeToEvent(
(Class<? extends SystemEvent>) eventClass,
(javax.faces.event.SystemEventListener)
ClassUtils.newInstance(systemEventListener.getSystemEventListenerClass()));
}
}
catch (ClassNotFoundException e)
{
log.log(Level.SEVERE, "System event listener could not be initialized, reason:", e);
}
}
for (String componentType : dispenser.getComponentTypes())
{
application.addComponent(componentType, dispenser.getComponentClass(componentType));
}
for (String converterId : dispenser.getConverterIds())
{
application.addConverter(converterId, dispenser.getConverterClassById(converterId));
}
for (String converterClass : dispenser.getConverterClasses())
{
try
{
application.addConverter(ClassUtils.simpleClassForName(converterClass),
dispenser.getConverterClassByClass(converterClass));
}
catch (Exception ex)
{
log.log(Level.SEVERE, "Converter could not be added. Reason:", ex);
}
}
for (String validatorId : dispenser.getValidatorIds())
{
application.addValidator(validatorId, dispenser.getValidatorClass(validatorId));
}
// programmatically add the BeanValidator if the following requirements are met:
// - bean validation has not been disabled
// - bean validation is available in the classpath
String beanValidatorDisabled = _externalContext.getInitParameter(
BeanValidator.DISABLE_DEFAULT_BEAN_VALIDATOR_PARAM_NAME);
final boolean defaultBeanValidatorDisabled = (beanValidatorDisabled != null
&& beanValidatorDisabled.toLowerCase().equals("true"));
boolean beanValidatorInstalledProgrammatically = false;
if (!defaultBeanValidatorDisabled
&& ExternalSpecifications.isBeanValidationAvailable())
{
// add the BeanValidator as default validator
application.addDefaultValidatorId(BeanValidator.VALIDATOR_ID);
beanValidatorInstalledProgrammatically = true;
}
// add the default-validators from the config files
for (String validatorId : dispenser.getDefaultValidatorIds())
{
application.addDefaultValidatorId(validatorId);
}
// do some checks if the BeanValidator was not installed as a
// default-validator programmatically, but via a config file.
if (!beanValidatorInstalledProgrammatically
&& application.getDefaultValidatorInfo()
.containsKey(BeanValidator.VALIDATOR_ID))
{
if (!ExternalSpecifications.isBeanValidationAvailable())
{
// the BeanValidator was installed via a config file,
// but bean validation is not available
log.log(Level.WARNING, "The BeanValidator was installed as a " +
"default-validator from a faces-config file, but bean " +
"validation is not available on the classpath, " +
"thus it will not work!");
}
else if (defaultBeanValidatorDisabled)
{
// the user disabled the default bean validator in web.xml,
// but a config file added it, which is ok with the spec
// (section 11.1.3: "though manual installation is still possible")
// --> inform the user about this scenario
log.log(Level.INFO, "The BeanValidator was disabled as a " +
"default-validator via the config parameter " +
BeanValidator.DISABLE_DEFAULT_BEAN_VALIDATOR_PARAM_NAME +
" in web.xml, but a faces-config file added it, " +
"thus it actually was installed as a default-validator.");
}
}
for (Behavior behavior : dispenser.getBehaviors())
{
application.addBehavior(behavior.getBehaviorId(), behavior.getBehaviorClass());
}
RuntimeConfig runtimeConfig = getRuntimeConfig();
runtimeConfig.setPropertyResolverChainHead(ClassUtils.buildApplicationObject(PropertyResolver.class,