* @throws FacesException if the managed bean
* could not be created.
*/
public Object createAndMaybeStoreManagedBeans(FacesContext context,
String managedBeanName) throws FacesException {
ManagedBeanFactory managedBean = managedBeanFactoriesMap.get(managedBeanName);
if (managedBean == null) {
if (LOGGER.isLoggable(Level.FINE)) {
LOGGER.fine("Couldn't find a factory for " + managedBeanName);
}
return null;
}
Object bean;
Scope scope = managedBean.getScope();
boolean scopeIsApplication;
boolean scopeIsRequest;
ExternalContext extContext = context.getExternalContext();
if ((scopeIsApplication = (scope == Scope.APPLICATION)) ||
((scope == Scope.SESSION))) {
if (scopeIsApplication) {
synchronized (extContext.getContext()) {
try {
bean = managedBean.newInstance(context);
if (LOGGER.isLoggable(Level.FINE)) {
LOGGER.fine(MessageFormat.format("Created application scoped bean {0} successfully ", managedBeanName));
}
} catch (Exception ex) {
Object[] params = {managedBeanName};
if (LOGGER.isLoggable(Level.SEVERE)) {
LOGGER.log(Level.SEVERE,
"jsf.managed_bean_creation_error", params);
}
throw new FacesException(ex);
}
//add bean to appropriate scope
extContext.getApplicationMap().put(managedBeanName, bean);
}
} else {
synchronized (extContext.getSession(true)) {
try {
bean = managedBean.newInstance(context);
if (LOGGER.isLoggable(Level.FINE)) {
LOGGER.fine(MessageFormat.format("Created session scoped bean {0} successfully ", managedBeanName));
}
} catch (Exception ex) {
Object[] params = {managedBeanName};
if (LOGGER.isLoggable(Level.SEVERE)) {
LOGGER.log(Level.SEVERE,
"jsf.managed_bean_creation_error", params);
}
throw new FacesException(ex);
}
//add bean to appropriate scope
extContext.getSessionMap().put(managedBeanName, bean);
}
}
} else {
scopeIsRequest = (scope == Scope.REQUEST);
try {
bean = managedBean.newInstance(context);
if (LOGGER.isLoggable(Level.FINE)) {
LOGGER.log(Level.FINE, MessageFormat.format("Created bean {0} successfully ", managedBeanName));
}
} catch (Exception ex) {
Object[] params = {managedBeanName};