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


Java Contextual类代码示例

本文整理汇总了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;
}
 
开发者ID:dajudge,项目名称:testee.fi,代码行数:22,代码来源:DependencyInjectionRealm.java

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

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

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

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

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

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

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

示例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);
}
 
开发者ID:wildfly-swarm,项目名称:wildfly-swarm,代码行数:18,代码来源:DeploymentContextImpl.java

示例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;
    }

}
 
开发者ID:flowable,项目名称:flowable-engine,代码行数:23,代码来源:BusinessProcessContext.java

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

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

示例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;
  }

}
 
开发者ID:logicalhacking,项目名称:SecureBPMN,代码行数:24,代码来源:BusinessProcessContext.java

示例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;
        }
    }
}
 
开发者ID:canoo,项目名称:dolphin-platform,代码行数:20,代码来源:ClientScopeContext.java

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


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