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


Java ContextNotActiveException类代码示例

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

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

示例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");
}
 
开发者ID:kiegroup,项目名称:appformer,代码行数:25,代码来源:ShowcaseSocialUserEventAdapter.java

示例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);
    }
}
 
开发者ID:Tibor17,项目名称:javaee-samples,代码行数:19,代码来源:DaoProducer.java

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

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

}
 
开发者ID:macanhhuy,项目名称:dcp-api,代码行数:24,代码来源:ResourcesTest.java

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

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

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

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

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

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

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

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

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

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


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