本文整理汇总了Java中javax.enterprise.context.spi.Contextual.create方法的典型用法代码示例。如果您正苦于以下问题:Java Contextual.create方法的具体用法?Java Contextual.create怎么用?Java Contextual.create使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.enterprise.context.spi.Contextual
的用法示例。
在下文中一共展示了Contextual.create方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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;
}
示例2: 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;
}
示例3: get
import javax.enterprise.context.spi.Contextual; //导入方法依赖的package包/类
/**
* Get the instance (create it if it does not exist).
*
* @param <T> the type.
* @param contextual the contextual.
* @param creational the creational.
* @return the instance.
*/
public <T> T get(Contextual<T> contextual, CreationalContext<T> creational) {
T result = get(contextual);
if (result == null) {
String scopeId = (String) request.getAttribute(SCOPE_ID);
if (null == scopeId) {
scopeId = generateScopeId();
}
HttpSession session = request.getSession();
result = contextual.create(creational);
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) {
session.setAttribute(sessionKey, scopeMap);
scopeMap.put(INSTANCE + pc.getId(), result);
scopeMap.put(CREATIONAL + pc.getId(), creational);
}
}
return result;
}
示例4: 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;
}
示例5: get
import javax.enterprise.context.spi.Contextual; //导入方法依赖的package包/类
@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;
}
示例6: get
import javax.enterprise.context.spi.Contextual; //导入方法依赖的package包/类
@Override
public <T> T get(Contextual<T> bean, CreationalContext<T> crco) {
PortletSessionBeanHolder holder = PortletSessionBeanHolder.getBeanHolder();
if (holder == null) {
throw new ContextNotActiveException("The portlet session context is not active.");
}
T inst = holder.getBean(bean);
if (inst == null) {
inst = bean.create(crco);
holder.putBeanInstance(bean, crco, inst);
}
return inst;
}
示例7: getBean
import javax.enterprise.context.spi.Contextual; //导入方法依赖的package包/类
/**
* Returns an instance for the contextual type. If no existing bean is available,
* a new instance is created.
*
* @param bean Contextual type (Bean) for which an instance is desired
* @return The instance, or null if none exists
*/
@SuppressWarnings("unchecked")
public <T> T getBean(Contextual<T> bean, CreationalContext<T> crco) {
BeanInstance<?> bi = beans.get(bean);
if (bi == null) {
// No bean available, so create one.
BeanInstance<T> newbi = new BeanInstance<T>();
newbi.crco = crco;
newbi.instance = bean.create(crco);
bi = newbi;
beans.put(bean, newbi);
if (isTrace) {
StringBuilder txt = new StringBuilder(80);
txt.append("Created bean: ");
txt.append(((Bean<?>) bean).getBeanClass().getSimpleName());
LOG.trace(txt.toString());
}
}
return (T) bi.instance;
}
示例8: get
import javax.enterprise.context.spi.Contextual; //导入方法依赖的package包/类
@Override
public <T> T get(Contextual<T> contextual, CreationalContext<T> creationalContext) {
checkArgumentNotNull(contextual);
Map<Contextual<?>, ContextualInstance<?>> ctx = currentContext.get();
if (ctx == null) {
throw new ContextNotActiveException();
}
@SuppressWarnings("unchecked")
ContextualInstance<T> instance = (ContextualInstance<T>) ctx.get(contextual);
if (instance == null && creationalContext != null) {
instance = new ContextualInstance<T>(contextual.create(creationalContext), creationalContext, contextual);
ctx.put(contextual, instance);
}
return instance != null ? instance.get() : null;
}
示例9: get
import javax.enterprise.context.spi.Contextual; //导入方法依赖的package包/类
@Override
public <T> T get(final Contextual<T> component, final CreationalContext<T> creationalContext) {
checkActive();
final ConcurrentMap<Contextual<?>, Instance<?>> storage = getOrCreateCurrentStorage();
Instance<T> instance = (Instance<T>) storage.get(component);
if (instance == null) {
synchronized (this) {
instance = (Instance<T>) storage.get(component);
if (instance == null) {
final T value = component.create(creationalContext);
instance = new Instance<T>(value, creationalContext);
storage.putIfAbsent(component, instance);
}
}
}
return instance.value;
}
示例10: get
import javax.enterprise.context.spi.Contextual; //导入方法依赖的package包/类
public <T> T get(Contextual<T> component, CreationalContext<T> creationalContext)
{
Map<Contextual, TransactionBeanEntry> transactionBeanEntryMap =
TransactionBeanStorage.getInstance().getActiveTransactionContext();
if (transactionBeanEntryMap == null)
{
TransactionBeanStorage.close();
throw new ContextNotActiveException("Not accessed within a transactional method - use @" +
Transactional.class.getName());
}
TransactionBeanEntry transactionBeanEntry = transactionBeanEntryMap.get(component);
if (transactionBeanEntry != null)
{
return (T) transactionBeanEntry.getContextualInstance();
}
// if it doesn't yet exist, we need to create it now!
T instance = component.create(creationalContext);
transactionBeanEntry = new TransactionBeanEntry(component, instance, creationalContext);
transactionBeanEntryMap.put(component, transactionBeanEntry);
return instance;
}
示例11: put
import javax.enterprise.context.spi.Contextual; //导入方法依赖的package包/类
/**
* Put a bean into the cache.
*
* @param bean The bean to instantiate
* @param context The creational context used to instantiate the bean
* @return The instantiated bean instance
*/
@SuppressWarnings("unchecked")
<T> T put(Contextual<T> bean, CreationalContext<T> context) {
T obj = bean.create(context);
synchronized (cache) {
cache.put(bean, new CacheEntry(obj, (CreationalContext<Object>) context));
}
listener.instanceAdded(bean, context, obj);
return obj;
}
示例12: get
import javax.enterprise.context.spi.Contextual; //导入方法依赖的package包/类
@Override
public <T> T get(Contextual<T> contextual, CreationalContext<T> creationalContext) {
T instance = get(contextual);
if (instance == null) {
instance = contextual.create(creationalContext);
if (instance != null) {
contextualStore.get().put(contextual, instance);
}
}
return instance;
}