use of jakarta.enterprise.inject.spi.PassivationCapable in project core by weld.
the class ContextualStoreImpl method putIfAbsent.
/**
* Add a contextual (if not already present) to the store, and return it's
* id. If the contextual is passivation capable, it's id will be used,
* otherwise an id will be generated
*
* @param contextual the contextual to add
* @return the current id for the contextual
*/
@SuppressFBWarnings(value = "RV_RETURN_VALUE_OF_PUTIFABSENT_IGNORED", justification = "Using non-standard semantics of putIfAbsent")
public BeanIdentifier putIfAbsent(Contextual<?> contextual) {
if (contextual instanceof CommonBean<?>) {
// this is a Bean<?> created by Weld
CommonBean<?> bean = (CommonBean<?>) contextual;
passivationCapableContextuals.putIfAbsent(bean.getIdentifier(), contextual);
return bean.getIdentifier();
}
if (contextual instanceof PassivationCapable) {
// this is an extension-provided passivation capable bean
PassivationCapable passivationCapable = (PassivationCapable) contextual;
String id = passivationCapable.getId();
BeanIdentifier identifier = new StringBeanIdentifier(id);
passivationCapableContextuals.putIfAbsent(identifier, contextual);
return identifier;
} else {
BeanIdentifier id = contextuals.get(contextual);
if (id != null) {
return id;
} else {
synchronized (contextual) {
id = contextuals.get(contextual);
if (id == null) {
id = new StringBeanIdentifier(new StringBuilder().append(GENERATED_ID_PREFIX).append(idGenerator.incrementAndGet()).toString());
contextuals.put(contextual, id);
contextualsInverse.put(id, contextual);
}
return id;
}
}
}
}
use of jakarta.enterprise.inject.spi.PassivationCapable 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);
}
use of jakarta.enterprise.inject.spi.PassivationCapable in project mojarra by eclipse-ee4j.
the class ViewScopeContextManager method getBean.
/**
* Get the value from the view map (or null if not found).
*
* @param <T> the type.
* @param facesContext the faces context.
* @param contextual the contextual.
* @return the value or null if not found.
*/
@SuppressWarnings("unchecked")
public <T> T getBean(FacesContext facesContext, Contextual<T> contextual) {
T result = null;
Map<String, ViewScopeContextObject> contextMap = getContextMap(facesContext);
if (contextMap != null) {
if (!(contextual instanceof PassivationCapable)) {
throw new IllegalArgumentException("ViewScoped bean " + contextual.toString() + " must be PassivationCapable, but is not.");
}
ViewScopeContextObject contextObject = contextMap.get(((PassivationCapable) contextual).getId());
if (contextObject != null) {
String name = contextObject.getName();
LOGGER.log(FINEST, "Getting value for @ViewScoped bean with name: {0}", name);
result = (T) facesContext.getViewRoot().getViewMap(true).get(name);
}
}
return result;
}
use of jakarta.enterprise.inject.spi.PassivationCapable in project mojarra by eclipse-ee4j.
the class ClientWindowScopeContextManager method getBean.
/**
* Get the value from the ClientWindow-map (or null if not found).
*
* @param <T> the type.
* @param facesContext the faces context.
* @param contextual the contextual.
* @return the value or null if not found.
*/
@SuppressWarnings("unchecked")
public <T> T getBean(FacesContext facesContext, Contextual<T> contextual) {
T result = null;
Map<String, ClientWindowScopeContextObject> contextMap = getContextMap(facesContext);
if (contextMap != null) {
if (!(contextual instanceof PassivationCapable)) {
throw new IllegalArgumentException("ClientWindowScoped bean " + contextual.toString() + " must be PassivationCapable, but is not.");
}
ClientWindowScopeContextObject<T> contextObject = contextMap.get(((PassivationCapable) contextual).getId());
if (contextObject != null) {
return contextObject.getContextualInstance();
}
}
return result;
}
use of jakarta.enterprise.inject.spi.PassivationCapable in project mojarra by eclipse-ee4j.
the class ClientWindowScopeContextManager method createBean.
/**
* Create the bean.
*
* @param <T> the type.
* @param facesContext the faces context.
* @param contextual the contextual.
* @param creational the creational.
* @return the value or null if not found.
*/
public <T> T createBean(FacesContext facesContext, Contextual<T> contextual, CreationalContext<T> creational) {
LOGGER.log(FINEST, "Creating @ClientWindowScoped CDI bean using contextual: {0}", contextual);
if (!(contextual instanceof PassivationCapable)) {
throw new IllegalArgumentException("ClientWindowScoped bean " + contextual.toString() + " must be PassivationCapable, but is not.");
}
T contextualInstance = contextual.create(creational);
if (contextualInstance != null) {
String passivationCapableId = ((PassivationCapable) contextual).getId();
getContextMap(facesContext).put(passivationCapableId, new ClientWindowScopeContextObject(passivationCapableId, contextualInstance));
}
return contextualInstance;
}
Aggregations