• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java ContextNotActiveException类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中javax.enterprise.context.ContextNotActiveException的典型用法代码示例。如果您正苦于以下问题:Java ContextNotActiveException类的具体用法?Java ContextNotActiveException怎么用?Java ContextNotActiveException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



ContextNotActiveException类属于javax.enterprise.context包,在下文中一共展示了ContextNotActiveException类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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


示例16: getContextualStorage

import javax.enterprise.context.ContextNotActiveException; //导入依赖的package包/类
@Override
protected ContextualStorage getContextualStorage(Contextual<?> contextual, boolean createIfNotExist) {
	Session session = this.sessionHolder.get();
	// return the storage for the Contextual. This can only be achieved if the Session was seen before as the storage
	// will not contain the 
	if (session == null && !createIfNotExist) {
		session = getSession(contextual);
	}
	if (session == null) {
		throw new ContextNotActiveException("WebSocketContext: no WebSocket session set for the current Thread yet!");
	}
	return this.holder.getContextualStorage(this.beanManager, session.getId(), createIfNotExist);
}
 
开发者ID:dansiviter,项目名称:cito,代码行数:14,代码来源:WebSocketContext.java


示例17: activate

import javax.enterprise.context.ContextNotActiveException; //导入依赖的package包/类
@Override
public void activate() {
    try {
        beanManager.getContext(delegate.getScope());
        LOGGER.info("Command context already active");
    } catch (ContextNotActiveException e) {
        // Only activate the context if not already active
        delegate.activate();
        isActivator = true;
    }
}
 
开发者ID:weld,项目名称:command-context-example,代码行数:12,代码来源:CommandContextImpl.java


示例18: activate

import javax.enterprise.context.ContextNotActiveException; //导入依赖的package包/类
@Override
public void activate(Archive archive, String asName, boolean implicit) {
    try {
        beanManager.getContext(delegate.getScope());
        LOGGER.info("Command context already active");
    } catch (ContextNotActiveException e) {
        // Only activate the context if not already active
        delegate.activate(archive, asName, implicit);
        isActivator = true;
    }
}
 
开发者ID:wildfly-swarm,项目名称:wildfly-swarm,代码行数:12,代码来源:DeploymentContextImpl.java


示例19: getBroadestActiveContext

import javax.enterprise.context.ContextNotActiveException; //导入依赖的package包/类
protected Class<? extends ScopedAssociation> getBroadestActiveContext() {
    for (Class<? extends ScopedAssociation> scopeType : getAvailableScopedAssociationClasses()) {
        Annotation scopeAnnotation = scopeType.getAnnotations().length > 0 ? scopeType.getAnnotations()[0] : null;
        if (scopeAnnotation == null || !beanManager.isScope(scopeAnnotation.annotationType())) {
            throw new FlowableException("ScopedAssociation must carry exactly one annotation and it must be a @Scope annotation");
        }
        try {
            beanManager.getContext(scopeAnnotation.annotationType());
            return scopeType;
        } catch (ContextNotActiveException e) {
            LOGGER.trace("Context {} not active.", scopeAnnotation.annotationType());
        }
    }
    throw new FlowableException("Could not determine an active context to associate the current process instance / task instance with.");
}
 
开发者ID:flowable,项目名称:flowable-engine,代码行数:16,代码来源:DefaultContextAssociationManager.java


示例20: getBroadestActiveContext

import javax.enterprise.context.ContextNotActiveException; //导入依赖的package包/类
protected Class< ? extends ScopedAssociation> getBroadestActiveContext() {
  for (Class< ? extends ScopedAssociation> scopeType : getAvailableScopedAssociationClasses()) {
    Annotation scopeAnnotation = scopeType.getAnnotations().length > 0 ? scopeType.getAnnotations()[0] : null;
    if (scopeAnnotation == null || !beanManager.isScope(scopeAnnotation.annotationType())) {
      throw new ActivitiException("ScopedAssociation must carry exactly one annotation and it must be a @Scope annotation");
    }
    try {
      beanManager.getContext(scopeAnnotation.annotationType());
      return scopeType;
    } catch (ContextNotActiveException e) {
      log.finest("Context " + scopeAnnotation.annotationType() + " not active.");            
    }
  }
  throw new ActivitiException("Could not determine an active context to associate the current process instance / task instance with.");
}
 
开发者ID:logicalhacking,项目名称:SecureBPMN,代码行数:16,代码来源:DefaultBusinessProcessAssociationManager.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java WildcardType类代码示例发布时间:2022-05-21
下一篇:
Java Context类代码示例发布时间:2022-05-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap