本文整理汇总了Java中javax.enterprise.context.spi.Contextual类的典型用法代码示例。如果您正苦于以下问题:Java Contextual类的具体用法?Java Contextual怎么用?Java Contextual使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Contextual类属于javax.enterprise.context.spi包,在下文中一共展示了Contextual类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: newInstance
import javax.enterprise.context.spi.Contextual; //导入依赖的package包/类
private <T> T newInstance(final Bean<T> bean, final ReleaseCallbackHandler handler) {
final CreationalContextImpl<T> ctx = contextFor(bean, handler);
final T instance = bean.create(ctx);
ctx.addDependentInstance(new ContextualInstance<T>() {
@Override
public T getInstance() {
return instance;
}
@Override
public CreationalContext<T> getCreationalContext() {
return ctx;
}
@Override
public Contextual<T> getContextual() {
return bean;
}
});
return instance;
}
示例2: getInstances
import javax.enterprise.context.spi.Contextual; //导入依赖的package包/类
/**
* Retrieves the map that contains transaction scoped beans for the current
* transaction.
*
* @param transactionSupport a bean that implements {@link TransactionSupport}.
* @return instances of transaction scoped beans for the current
* transaction.
*/
private <T> Map<Contextual<T>, ContextualInstance<T>> getInstances(
TransactionSupport transactionSupport) {
@SuppressWarnings("unchecked")
Map<Contextual<T>, ContextualInstance<T>> instances =
(Map<Contextual<T>, ContextualInstance<T>>) transactionSupport.getTransactionSynchronizationRegistry()
.getResource(TRANSACTION_BEANS_KEY);
if (instances == null) {
instances = new HashMap<Contextual<T>, ContextualInstance<T>>();
transactionSupport
.getTransactionSynchronizationRegistry()
.putResource(TRANSACTION_BEANS_KEY, instances);
registerSynchronization(transactionSupport, instances);
}
return instances;
}
示例3: get
import javax.enterprise.context.spi.Contextual; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public <T> T get(Contextual<T> contextual, CreationalContext<T> creationalContext) {
Map<Contextual<?>, ContextualInstance<?>> ctx = currentContext.get();
if (ctx == null) {
// Thread local not set - context is not active!
throw new ContextNotActiveException();
}
ContextualInstance<T> instance = (ContextualInstance<T>) ctx.get(contextual);
if (instance == null && creationalContext != null) {
// Bean instance does not exist - create one if we have CreationalContext
instance = new ContextualInstance<T>(contextual.create(creationalContext), creationalContext, contextual);
ctx.put(contextual, instance);
}
return instance != null ? instance.get() : null;
}
示例4: getSession
import javax.enterprise.context.spi.Contextual; //导入依赖的package包/类
/**
*
* @param contextual
* @return
*/
private Session getSession(Contextual<?> contextual) {
final List<Session> sessions = new ArrayList<>();
final SessionRegistry registry = getContextualReference(this.beanManager, SessionRegistry.class, false);
for (Entry<String, ContextualStorage> e : this.holder.getStorageMap().entrySet()) {
final Object key = e.getValue().getBeanKey(contextual);
if (e.getValue().getBean(key) != null) {
final Optional<Session> session = registry.getSession(e.getKey());
session.ifPresent(sessions::add);
}
}
if (sessions.size() > 1) {
throw new IllegalStateException("Too many sessions! [" + contextual + "]");
}
return sessions.isEmpty() ? null : sessions.get(0);
}
示例5: get
import javax.enterprise.context.spi.Contextual; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public <T> T get(Contextual<T> contextual, CreationalContext<T> creationalContext) {
Map<Contextual<?>, ContextualInstance<?>> ctx = currentContext.get();
if (ctx == null) {
// Thread local not set - context is not active!
throw new ContextNotActiveException();
}
ContextualInstance<T> instance = (ContextualInstance<T>) ctx.get(contextual);
if (instance == null && creationalContext != null) {
// Bean instance does not exist - create one if we have CreationalContext
instance = new ContextualInstance<T>(contextual.create(creationalContext), creationalContext, contextual);
ctx.put(contextual, instance);
}
return instance != null ? instance.get() : null;
}
示例6: deactivate
import javax.enterprise.context.spi.Contextual; //导入依赖的package包/类
public void deactivate() {
Map<Contextual<?>, ContextualInstance<?>> ctx = currentContext.get();
if (ctx == null) {
return;
}
for (ContextualInstance<?> instance : ctx.values()) {
try {
instance.destroy();
} catch (Exception e) {
LOGGER.warning("Unable to destroy instance" + instance.get() + " for bean: " + instance.getContextual());
}
}
ctx.clear();
currentContext.remove();
currentCommandExecution.remove();
}
示例7: destroy
import javax.enterprise.context.spi.Contextual; //导入依赖的package包/类
/**
* Destroy the instance.
*
* @param contextual the contextual.
*/
public void destroy(Contextual contextual) {
String scopeId = (String) request.getAttribute(SCOPE_ID);
if (null != scopeId) {
HttpSession session = request.getSession();
if (contextual instanceof PassivationCapable == false) {
throw new RuntimeException("Unexpected type for contextual");
}
PassivationCapable pc = (PassivationCapable) contextual;
final String sessionKey = SCOPE_ID + "-" + scopeId;
Map<String, Object> scopeMap = (Map<String, Object>) session.getAttribute(sessionKey);
if (null != scopeMap) {
Object instance = scopeMap.get(INSTANCE + pc.getId());
CreationalContext<?> creational = (CreationalContext<?>) scopeMap.get(CREATIONAL + pc.getId());
if (null != instance && null != creational) {
contextual.destroy(instance, creational);
creational.release();
}
}
}
}
示例8: get
import javax.enterprise.context.spi.Contextual; //导入依赖的package包/类
/**
* Get the instance.
*
* @param <T> the type.
* @param contextual the contextual.
* @return the instance, or null.
*/
public <T> T get(Contextual<T> contextual) {
T result = null;
String scopeId = (String) request.getAttribute(SCOPE_ID);
if (null != scopeId) {
HttpSession session = request.getSession();
if (contextual instanceof PassivationCapable == false) {
throw new RuntimeException("Unexpected type for contextual");
}
PassivationCapable pc = (PassivationCapable) contextual;
final String sessionKey = SCOPE_ID + "-" + scopeId;
Map<String, Object> scopeMap = (Map<String, Object>) session.getAttribute(sessionKey);
if (null != scopeMap) {
result = (T) scopeMap.get(INSTANCE + pc.getId());
} else {
request.setAttribute(SCOPE_ID, null); // old cookie, force new scope generation
}
}
return result;
}
示例9: deactivate
import javax.enterprise.context.spi.Contextual; //导入依赖的package包/类
public void deactivate() {
Map<Contextual<?>, ContextualInstance<?>> ctx = currentContext.get();
if (ctx == null) {
return;
}
for (ContextualInstance<?> instance : ctx.values()) {
try {
instance.destroy();
} catch (Exception e) {
e.printStackTrace();
}
}
ctx.clear();
currentContext.remove();
currentArchive.set(null);
currentName.set(null);
}
示例10: get
import javax.enterprise.context.spi.Contextual; //导入依赖的package包/类
@Override
public <T> T get(Contextual<T> contextual) {
Bean<T> bean = (Bean<T>) contextual;
String variableName = bean.getName();
BusinessProcess businessProcess = getBusinessProcess();
Object variable = businessProcess.getVariable(variableName);
if (variable != null) {
if (LOGGER.isDebugEnabled()) {
if (businessProcess.isAssociated()) {
LOGGER.debug("Getting instance of bean '{}' from Execution[{}]", variableName, businessProcess.getExecutionId());
} else {
LOGGER.debug("Getting instance of bean '{}' from transient bean store", variableName);
}
}
return (T) variable;
} else {
return null;
}
}
示例11: get
import javax.enterprise.context.spi.Contextual; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public <T> T get(final Contextual<T> component, final CreationalContext<T> creationalContext) {
assertActive();
T instance = get(component);
if (instance == null) {
if (creationalContext != null) {
Map<Contextual<?>, Object> componentInstanceMap = getComponentInstanceMap();
Map<Contextual<?>, CreationalContext<?>> creationalContextMap = getCreationalInstanceMap();
synchronized (componentInstanceMap) {
instance = (T) componentInstanceMap.get(component);
if (instance == null) {
instance = component.create(creationalContext);
if (instance != null) {
componentInstanceMap.put(component, instance);
creationalContextMap.put(component, creationalContext);
}
}
}
}
}
return instance;
}
示例12: processEvent
import javax.enterprise.context.spi.Contextual; //导入依赖的package包/类
/**
* We get PreDestroyViewMapEvent events from the JSF servlet and destroy our
* contextual instances. This should (theoretically!) also get fired if the
* webapp closes, so there should be no need to manually track all view
* scopes and destroy them at a shutdown.
*
* @see javax.faces.event.SystemEventListener#processEvent(javax.faces.event.SystemEvent)
*/
@SuppressWarnings("unchecked")
@Override
public void processEvent(final SystemEvent event) {
if (event instanceof PreDestroyViewMapEvent) {
Map<Contextual<?>, Object> componentInstanceMap = getComponentInstanceMap();
Map<Contextual<?>, CreationalContext<?>> creationalContextMap = getCreationalInstanceMap();
if (componentInstanceMap != null) {
for (Map.Entry<Contextual<?>, Object> componentEntry : componentInstanceMap.entrySet()) {
/*
* No way to inform the compiler of type <T> information, so
* it has to be abandoned here :(
*/
Contextual contextual = componentEntry.getKey();
Object instance = componentEntry.getValue();
CreationalContext creational = creationalContextMap.get(contextual);
contextual.destroy(instance, creational);
}
}
}
}
示例13: get
import javax.enterprise.context.spi.Contextual; //导入依赖的package包/类
@Override
public <T> T get(Contextual<T> contextual) {
Bean<T> bean = (Bean<T>) contextual;
String variableName = bean.getName();
BusinessProcess businessProcess = getBusinessProcess();
Object variable = businessProcess.getVariable(variableName);
if (variable != null) {
if (logger.isLoggable(Level.FINE)) {
if(businessProcess.isAssociated()) {
logger.fine("Getting instance of bean '" + variableName + "' from Execution[" + businessProcess.getExecutionId() + "].");
} else {
logger.fine("Getting instance of bean '" + variableName + "' from transient bean store");
}
}
return (T) variable;
} else {
return null;
}
}
示例14: getContextualStorage
import javax.enterprise.context.spi.Contextual; //导入依赖的package包/类
@Override
protected ContextualStorage getContextualStorage(Contextual<?> contextual, boolean createIfNotExist) {
Object val = getDolphinSession().getAttribute(CLIENT_STORAGE_ATTRIBUTE);
if(val != null) {
if(val instanceof ContextualStorage) {
return (ContextualStorage) val;
} else {
throw new ContextException("No ClientContext specified!");
}
} else {
if(createIfNotExist) {
ContextualStorage contextualStorage = new ContextualStorage(beanManager, false, false);
getDolphinSession().setAttribute(CLIENT_STORAGE_ATTRIBUTE, contextualStorage);
return contextualStorage;
} else {
return null;
}
}
}
示例15: ContextBeansHolder
import javax.enterprise.context.spi.Contextual; //导入依赖的package包/类
/**
* Create the holder/cache of the beans.
*
* @param listener A listener for changes to the cache
*/
ContextBeansHolder(ContextBeansListener listener) {
this.listener = listener;
if (this.listener == null) {
this.listener = new ContextBeansListener() {
@Override
public void instanceRemoved(Contextual<?> bean,
CreationalContext<?> context, Object instance) {
}
@Override
public void instanceAdded(Contextual<?> bean, CreationalContext<?> context,
Object instance) {
}
};
}
}