当前位置: 首页>>代码示例>>Java>>正文


Java Contextual.create方法代码示例

本文整理汇总了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;
}
 
开发者ID:weld,项目名称:weld-junit,代码行数:19,代码来源:ContextImpl.java

示例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;
}
 
开发者ID:weld,项目名称:command-context-example,代码行数:20,代码来源:CommandContextImpl.java

示例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;
}
 
开发者ID:mvc-spec,项目名称:ozark,代码行数:34,代码来源:RedirectScopeManager.java

示例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;
}
 
开发者ID:fabiohxcx,项目名称:PedidoVenda,代码行数:27,代码来源:ViewScopedContext.java

示例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;
}
 
开发者ID:brenoemelo,项目名称:goFitOne,代码行数:26,代码来源:ViewScopedContext.java

示例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;
}
 
开发者ID:apache,项目名称:portals-pluto,代码行数:17,代码来源:PortletSessionScopedContext.java

示例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;
}
 
开发者ID:apache,项目名称:portals-pluto,代码行数:33,代码来源:PortletRequestScopedBeanHolder.java

示例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;
}
 
开发者ID:trimou,项目名称:trimou,代码行数:21,代码来源:RenderingContext.java

示例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;
}
 
开发者ID:apache,项目名称:incubator-batchee,代码行数:20,代码来源:BaseContext.java

示例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;
}
 
开发者ID:apache,项目名称:deltaspike,代码行数:27,代码来源:TransactionContext.java

示例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;
}
 
开发者ID:arievanwi,项目名称:osgi.ee,代码行数:17,代码来源:ContextBeansHolder.java

示例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;
}
 
开发者ID:bmwcarit,项目名称:joynr,代码行数:12,代码来源:JoynrJeeMessageContext.java


注:本文中的javax.enterprise.context.spi.Contextual.create方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。