本文整理汇总了Java中javax.enterprise.context.ContextNotActiveException类的典型用法代码示例。如果您正苦于以下问题:Java ContextNotActiveException类的具体用法?Java ContextNotActiveException怎么用?Java ContextNotActiveException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ContextNotActiveException类属于javax.enterprise.context包,在下文中一共展示了ContextNotActiveException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: get
import javax.enterprise.context.ContextNotActiveException; //导入依赖的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.ContextNotActiveException; //导入依赖的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: toSocial
import javax.enterprise.context.ContextNotActiveException; //导入依赖的package包/类
@Override
public SocialActivitiesEvent toSocial(Object object) {
final ShowcaseSocialUserEvent event = (ShowcaseSocialUserEvent) object;
SocialUser socialUser = null;
try {
socialUser = socialUserRepositoryAPI.findSocialUser(event.getUsername());
} catch (ContextNotActiveException e) {
//clean repository
socialUser = new SocialUser("system");
}
final String desc = String.format("new social event (%d)",
counter.incrementAndGet());
return new SocialActivitiesEvent(socialUser,
SampleType.SAMPLE,
new Date())
.withAdicionalInfo("edited")
.withDescription(desc)
.withLink(String.format("Main$%d.java",
counter.get()),
"file",
SocialActivitiesEvent.LINK_TYPE.CUSTOM)
.withParam("scheme",
"http");
}
示例4: lookupEntityManager
import javax.enterprise.context.ContextNotActiveException; //导入依赖的package包/类
private static EntityManager lookupEntityManager(InjectionPoint ip, BeanManager bm) {
final Class def = Default.class;
@SuppressWarnings("unchecked")
final Class<? extends Annotation> annotation = ip.getQualifiers()
.stream()
.filter(q -> q.annotationType() == DAO.class)
.map(q -> ((DAO) q).value())
.findFirst()
.orElse(def);
if (bm.isQualifier(annotation)) {
return lookupEntityManager(bm, annotation);
} else {
throw new ContextNotActiveException("no datasource qualifier nor stereotype presents in the "
+ "injection point " + ip);
}
}
示例5: get
import javax.enterprise.context.ContextNotActiveException; //导入依赖的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;
}
示例6: produceFacesContext
import javax.enterprise.context.ContextNotActiveException; //导入依赖的package包/类
@Test
public void produceFacesContext() {
Resources tested = new Resources();
// case - faces context not initialized
try {
tested.produceFacesContext();
Assert.fail("ContextNotActiveException expected");
} catch (ContextNotActiveException e) {
// OK
}
// case - facet context initialized
try {
FacesContext fcMock = Mockito.mock(FacesContext.class);
FacesContextMock.setCurrentInstanceImpl(fcMock);
Assert.assertEquals(fcMock, tested.produceFacesContext());
} finally {
FacesContextMock.setCurrentInstanceImpl(null);
}
}
示例7: get
import javax.enterprise.context.ContextNotActiveException; //导入依赖的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;
}
示例8: testContextRegistered
import javax.enterprise.context.ContextNotActiveException; //导入依赖的package包/类
@Test
public void testContextRegistered() {
JoynrJeeMessageContext.getInstance().activate();
Context result = beanManager.getContext(JoynrJeeMessageScoped.class);
assertNotNull(result);
assertTrue(result instanceof JoynrJeeMessageContext);
JoynrJeeMessageContext.getInstance().deactivate();
try {
result = beanManager.getContext(JoynrJeeMessageScoped.class);
fail("Shouldn't get it after deactivation.");
} catch (ContextNotActiveException e) {
logger.trace("Context not available after deactivation as expected.");
}
}
示例9: produceFacesContext
import javax.enterprise.context.ContextNotActiveException; //导入依赖的package包/类
@Test
public void produceFacesContext() {
Resources tested = new Resources();
// case - faces context not initialized
try {
tested.produceFacesContext();
Assert.fail("ContextNotActiveException expected");
} catch (ContextNotActiveException e) {
// OK
}
// case - faces context initialized
try {
FacesContext fcMock = Mockito.mock(FacesContext.class);
FacesContextMock.setCurrentInstanceImpl(fcMock);
Assert.assertEquals(fcMock, tested.produceFacesContext());
} finally {
FacesContextMock.setCurrentInstanceImpl(null);
}
}
示例10: get
import javax.enterprise.context.ContextNotActiveException; //导入依赖的package包/类
public <T> T get(Contextual<T> component)
{
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();
}
return null;
}
示例11: entityManagerUsageWithoutTransaction
import javax.enterprise.context.ContextNotActiveException; //导入依赖的package包/类
@Test
public void entityManagerUsageWithoutTransaction()
{
try
{
//not available because there is no transactional method
entityManager.getTransaction();
Assert.fail(ContextNotActiveException.class.getName() + " expected!");
}
catch (ContextNotActiveException e)
{
//expected
}
Assert.assertEquals(false, TransactionBeanStorage.isOpen());
}
示例12: invalidEntityManagerUsageAfterTransaction
import javax.enterprise.context.ContextNotActiveException; //导入依赖的package包/类
@Test
public void invalidEntityManagerUsageAfterTransaction()
{
transactionalBean.executeInTransaction();
try
{
//not available because there is no transactional method
entityManager.getTransaction();
Assert.fail(ContextNotActiveException.class.getName() + " expected!");
}
catch (ContextNotActiveException e)
{
//expected
}
Assert.assertEquals(false, TransactionBeanStorage.isOpen());
}
示例13: isContextActive
import javax.enterprise.context.ContextNotActiveException; //导入依赖的package包/类
/**
* Checks if the context for the given scope annotation is active.
*
* @param scopeAnnotationClass The scope annotation (e.g. @RequestScoped.class)
* @param beanManager The {@link BeanManager}
* @return If the context is active.
*/
public static boolean isContextActive(Class<? extends Annotation> scopeAnnotationClass, BeanManager beanManager)
{
try
{
if (beanManager.getContext(scopeAnnotationClass) == null
|| !beanManager.getContext(scopeAnnotationClass).isActive())
{
return false;
}
}
catch (ContextNotActiveException e)
{
return false;
}
return true;
}
示例14: noWindowTest
import javax.enterprise.context.ContextNotActiveException; //导入依赖的package包/类
@Test(expected = ContextNotActiveException.class)
public void noWindowTest()
{
try
{
windowContext.activateWindow("w1");
implicitlyGroupedBean.setValue("x");
Assert.assertEquals("x", implicitlyGroupedBean.getValue());
this.windowContext.closeWindow("w1");
}
catch (ContextNotActiveException e)
{
Assert.fail();
}
implicitlyGroupedBean.getValue();
}
示例15: noWindowTest
import javax.enterprise.context.ContextNotActiveException; //导入依赖的package包/类
@Test(expected = ContextNotActiveException.class)
public void noWindowTest()
{
try
{
windowContext.activateWindow("w1");
explicitlyGroupedBeanX.setValue("x1");
explicitlyGroupedBeanY.setValue("x2");
Assert.assertEquals("x1", explicitlyGroupedBeanX.getValue());
Assert.assertEquals("x2", explicitlyGroupedBeanY.getValue());
this.windowContext.closeWindow("w1");
}
catch (ContextNotActiveException e)
{
Assert.fail();
}
explicitlyGroupedBeanX.getValue();
}