本文整理汇总了Java中javax.enterprise.inject.spi.PassivationCapable类的典型用法代码示例。如果您正苦于以下问题:Java PassivationCapable类的具体用法?Java PassivationCapable怎么用?Java PassivationCapable使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
PassivationCapable类属于javax.enterprise.inject.spi包,在下文中一共展示了PassivationCapable类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: destroy
import javax.enterprise.inject.spi.PassivationCapable; //导入依赖的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();
}
}
}
}
示例2: get
import javax.enterprise.inject.spi.PassivationCapable; //导入依赖的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;
}
示例3: accept
import javax.enterprise.inject.spi.PassivationCapable; //导入依赖的package包/类
@Override
public boolean accept(final Bean<?> bean) {
if (BuiltInOwbBean.class.isInstance(bean) || ExtensionBean.class.isInstance(bean)) {
return false;
}
if (OwbBean.class.isInstance(bean)) {
final OwbBean owbBean = OwbBean.class.cast(bean);
if (owbBean.isPassivationCapable())
{
if (hasBean(owbBean.getId()))
{
return false;
}
}
} else if (PassivationCapable.class.isInstance(bean)) {
if (hasBean(PassivationCapable.class.cast(bean).getId())) {
return false;
}
}
final Set<Annotation> qualifiers = bean.getQualifiers();
return beanManager.getBeans(
bean.getBeanClass(),
qualifiers.isEmpty() ? EMPTY_ANNOTATIONS : qualifiers.toArray(new Annotation[qualifiers.size()])).isEmpty();
}
示例4: writeObject
import javax.enterprise.inject.spi.PassivationCapable; //导入依赖的package包/类
private void writeObject(ObjectOutputStream out) throws IOException
{
if (!(bean instanceof PassivationCapable))
{
throw new NotSerializableException("Bean is not PassivationCapable: " + bean.toString());
}
String passivationId = ((PassivationCapable) bean).getId();
if (passivationId == null)
{
throw new NotSerializableException(bean.toString());
}
out.writeLong(serialVersionUID);
out.writeObject(passivationId);
out.writeObject(instance);
out.writeObject(creationalContext);
}
示例5: get
import javax.enterprise.inject.spi.PassivationCapable; //导入依赖的package包/类
@Override
public <T> T get(Contextual<T> bean)
{
try
{
return super.get(bean);
}
finally
{
if (bean instanceof PassivationCapable)
{
PassivationCapable pc = (PassivationCapable) bean;
viewAccessBeanAccessHistory.getAccessedBeans().add(pc.getId());
}
}
}
示例6: init
import javax.enterprise.inject.spi.PassivationCapable; //导入依赖的package包/类
private synchronized void init()
{
if (this.deltaSpikeProxyInvocationHandler == null)
{
this.deltaSpikeProxyInvocationHandler = BeanProvider.getContextualReference(
beanManager, DeltaSpikeProxyInvocationHandler.class, false);
Set<Bean<H>> handlerBeans = BeanProvider.getBeanDefinitions(
delegateInvocationHandlerClass, false, true, beanManager);
if (handlerBeans.size() != 1)
{
StringBuilder beanInfo = new StringBuilder();
for (Bean<H> bean : handlerBeans)
{
if (beanInfo.length() != 0)
{
beanInfo.append(", ");
}
beanInfo.append(bean);
if (bean instanceof PassivationCapable)
{
beanInfo.append(" bean-id: ").append(((PassivationCapable) bean).getId());
}
}
throw new IllegalStateException(handlerBeans.size() + " beans found for "
+ delegateInvocationHandlerClass + " found beans: " + beanInfo.toString());
}
this.handlerBean = handlerBeans.iterator().next();
}
}
示例7: get
import javax.enterprise.inject.spi.PassivationCapable; //导入依赖的package包/类
@Override
public <T> T get(Contextual<T> bean, CreationalContext<T> creationalContext)
{
if (creationalContext == null)
{
return get(bean);
}
checkActive();
if (passivatingScope)
{
if (!(bean instanceof PassivationCapable))
{
throw new IllegalStateException(bean.toString() +
" doesn't implement " + PassivationCapable.class.getName());
}
}
ContextualStorage storage = getContextualStorage(bean, 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);
}
示例8: getBeanKey
import javax.enterprise.inject.spi.PassivationCapable; //导入依赖的package包/类
/**
* If the context is a passivating scope then we return
* the passivationId of the Bean. Otherwise we use
* the Bean directly.
* @return the key to use in the context map
*/
public <T> Object getBeanKey(Contextual<T> bean)
{
if (passivationCapable)
{
// if the
return ((PassivationCapable) bean).getId();
}
return bean;
}
示例9: convertToConversationKey
import javax.enterprise.inject.spi.PassivationCapable; //导入依赖的package包/类
public static ConversationKey convertToConversationKey(Contextual<?> contextual, BeanManager beanManager)
{
if (!(contextual instanceof Bean))
{
if (contextual instanceof PassivationCapable)
{
contextual = beanManager.getPassivationCapableBean(((PassivationCapable) contextual).getId());
}
else
{
throw new IllegalArgumentException(
contextual.getClass().getName() + " is not of type " + Bean.class.getName());
}
}
Bean<?> bean = (Bean<?>) contextual;
//don't cache it (due to the support of different producers)
ConversationGroup conversationGroupAnnotation = findConversationGroupAnnotation(bean);
Class<?> conversationGroup;
if (conversationGroupAnnotation != null)
{
conversationGroup = conversationGroupAnnotation.value();
}
else
{
conversationGroup = bean.getBeanClass();
}
Set<Annotation> qualifiers = bean.getQualifiers();
return new ConversationKey(conversationGroup, qualifiers.toArray(new Annotation[qualifiers.size()]));
}