use of org.apache.myfaces.cdi.util.ContextualInstanceInfo in project myfaces by apache.
the class FacesScopeContext method get.
@Override
public <T> T get(Contextual<T> bean, CreationalContext<T> creationalContext) {
FacesContext facesContext = FacesContext.getCurrentInstance();
checkActive(facesContext);
ContextualStorage storage = getContextualStorage(true, facesContext);
Map<Object, ContextualInstanceInfo<?>> contextMap = storage.getStorage();
ContextualInstanceInfo<?> contextualInstanceInfo = contextMap.get(storage.getBeanKey(bean));
if (contextualInstanceInfo != null) {
@SuppressWarnings("unchecked") final T instance = (T) contextualInstanceInfo.getContextualInstance();
if (instance != null) {
return instance;
}
}
return storage.createContextualInstance(bean, creationalContext);
}
use of org.apache.myfaces.cdi.util.ContextualInstanceInfo in project myfaces by apache.
the class ClientWindowScopeContext method get.
@Override
public <T> T get(Contextual<T> bean) {
FacesContext facesContext = FacesContext.getCurrentInstance();
checkActive(facesContext);
if (facesContext != null) {
ContextualStorage storage = getStorageHolder(facesContext).getContextualStorage(getCurrentClientWindowId(facesContext), false);
if (storage != null) {
Map<Object, ContextualInstanceInfo<?>> contextMap = storage.getStorage();
ContextualInstanceInfo<?> contextualInstanceInfo = contextMap.get(storage.getBeanKey(bean));
if (contextualInstanceInfo != null) {
return (T) contextualInstanceInfo.getContextualInstance();
}
}
} else {
throw new IllegalStateException("FacesContext cannot be found when resolving bean " + bean.toString());
}
return null;
}
use of org.apache.myfaces.cdi.util.ContextualInstanceInfo in project myfaces by apache.
the class ViewScopeCDIMap method put.
@Override
public Object put(String key, Object value) {
ContextualInstanceInfo info = new ContextualInstanceInfo();
info.setContextualInstance(value);
return getCreationalContextInstances().put(key, info);
}
use of org.apache.myfaces.cdi.util.ContextualInstanceInfo in project myfaces by apache.
the class ViewScopeContext method get.
@Override
public <T> T get(Contextual<T> bean) {
FacesContext facesContext = FacesContext.getCurrentInstance();
checkActive(facesContext);
// force session creation if ViewScoped is used
facesContext.getExternalContext().getSession(true);
ViewScopeContextualStorage storage = getContextualStorage(facesContext, false);
if (storage == null) {
return null;
}
Map<Object, ContextualInstanceInfo<?>> contextMap = storage.getStorage();
ContextualInstanceInfo<?> contextualInstanceInfo = contextMap.get(storage.getBeanKey(bean));
if (contextualInstanceInfo == null) {
return null;
}
return (T) contextualInstanceInfo.getContextualInstance();
}
use of org.apache.myfaces.cdi.util.ContextualInstanceInfo in project myfaces by apache.
the class ViewScopeContext method get.
@Override
public <T> T get(Contextual<T> bean, CreationalContext<T> creationalContext) {
FacesContext facesContext = FacesContext.getCurrentInstance();
checkActive(facesContext);
if (passivatingScope && !(bean instanceof PassivationCapable)) {
throw new IllegalStateException(bean.toString() + " doesn't implement " + PassivationCapable.class.getName());
}
// force session creation if ViewScoped is used
facesContext.getExternalContext().getSession(true);
ViewScopeContextualStorage storage = getContextualStorage(facesContext, true);
Map<Object, ContextualInstanceInfo<?>> contextMap = storage.getStorage();
ContextualInstanceInfo<?> contextualInstanceInfo = contextMap.get(storage.getBeanKey(bean));
if (contextualInstanceInfo != null) {
@SuppressWarnings("unchecked") final T instance = (T) contextualInstanceInfo.getContextualInstance();
if (instance != null) {
return instance;
}
}
return storage.createContextualInstance(bean, creationalContext);
}
Aggregations