javax.enterprise.context.spi.Context.isActive()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(6.6k)|赞(0)|评价(0)|浏览(162)

本文整理了Java中javax.enterprise.context.spi.Context.isActive()方法的一些代码示例,展示了Context.isActive()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Context.isActive()方法的具体详情如下:
包路径:javax.enterprise.context.spi.Context
类名称:Context
方法名:isActive

Context.isActive介绍

[英]Determines if the context object is active.
[中]确定上下文对象是否处于活动状态。

代码示例

代码示例来源:origin: org.omnifaces/omnifaces

/**
 * @see Beans#isActive(Class)
 */
public static <S extends Annotation> boolean isActive(BeanManager beanManager, Class<S> scope) {
  try {
    return beanManager.getContext(scope).isActive();
  }
  catch (Exception ignore) {
    logger.log(FINEST, "Ignoring thrown exception; given scope is very unlikely active anyway.", ignore);
    return false;
  }
}

代码示例来源:origin: omnifaces/omnifaces

/**
 * @see Beans#isActive(Class)
 */
public static <S extends Annotation> boolean isActive(BeanManager beanManager, Class<S> scope) {
  try {
    return beanManager.getContext(scope).isActive();
  }
  catch (Exception ignore) {
    logger.log(FINEST, "Ignoring thrown exception; given scope is very unlikely active anyway.", ignore);
    return false;
  }
}

代码示例来源:origin: org.jboss.jsr299.tck/jsr299-tck-impl

public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException
{
 if (!jsr299Manager.getContext(ApplicationScoped.class).isActive())
 {
   throw new ServletException("Application context is not active");
 }
 else
 {
   chain.doFilter(request, response);
 }
}

代码示例来源:origin: org.jboss.jsr299.tck/jsr299-tck-impl

@Override
protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
{
 if (!jsr299Manager.getContext(SessionScoped.class).isActive())
 {
   throw new ServletException("Session is not active");
 }
 else
 {
   super.service(req, resp);
 }
}

代码示例来源:origin: org.jboss.jsr299.tck/jsr299-tck-impl

@PostConstruct
public void construct()
{
 try
 {
   dependentContextActiveDuringPostConstruct = beanManager.getContext(Dependent.class).isActive();
 }
 catch (ContextNotActiveException e) 
 {
   dependentContextActiveDuringPostConstruct = false;
 }
}

代码示例来源:origin: org.jboss.cdi.tck/cdi-tck-impl

public void testConversationContextIsActive() {
  try {
    result = beanManager.getContext(ConversationScoped.class).isActive();
  } catch (ContextNotActiveException expected) {
    result = false;
  }
}

代码示例来源:origin: org.jboss.jsr299.tck/jsr299-tck-impl

@Override
protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
{
 if (!jsr299Manager.getContext(ApplicationScoped.class).isActive())
 {
   throw new ServletException("Application context is not active");
 }
 else
 {
   super.service(req, resp);
 }
}

代码示例来源:origin: org.glassfish/javax.faces

/**
 * Returns true if given scope is active in current context.
 */
public static <S extends Annotation> boolean isScopeActive(Class<S> scope) {
  BeanManager beanManager = Util.getCdiBeanManager(FacesContext.getCurrentInstance());
  try {
    Context context = beanManager.getContext(scope);
    return context.isActive();
  } catch (ContextNotActiveException ignore) {
    return false;
  }
}

代码示例来源:origin: org.glassfish/jakarta.faces

/**
 * Returns true if given scope is active in current context.
 */
public static <S extends Annotation> boolean isScopeActive(Class<S> scope) {
  BeanManager beanManager = Util.getCdiBeanManager(FacesContext.getCurrentInstance());
  try {
    Context context = beanManager.getContext(scope);
    return context.isActive();
  } catch (ContextNotActiveException ignore) {
    return false;
  }
}

代码示例来源:origin: org.jboss.cdi.tck/cdi-tck-impl

@Test
@SpecAssertion(section = AFTER_BEAN_DISCOVERY, id = "f")
public void testAddContext() {
  Context context = getCurrentManager().getContext(SuperScoped.class);
  assertNotNull(context);
  assertTrue(context.isActive());
  assertTrue(context instanceof SuperContext);
}

代码示例来源:origin: org.jboss.cdi.tck/cdi-tck-impl

@PostConstruct
public void init() {
  if (beanManager != null && beanManager.getContext(ApplicationScoped.class).isActive() && service != null
      && service.ping()) {
    isApplicationContextActiveDuringPostConstruct = true;
  }
}

代码示例来源:origin: org.jboss.cdi.tck/cdi-tck-impl

@PostConstruct
public void init() {
  if (beanManager != null && beanManager.getContext(ApplicationScoped.class).isActive() && service != null
      && service.ping()) {
    isApplicationContextActiveDuringPostConstruct = true;
  }
}

代码示例来源:origin: org.jboss.cdi.tck/cdi-tck-impl

private void checkRequestContextActive() throws ServletException {
  if (beanManager == null || !beanManager.getContext(RequestScoped.class).isActive() || simpleBean == null) {
    throw new ServletException("Request context is not active");
  }
  // Check bean invocation
  simpleBean.getId();
}

代码示例来源:origin: org.jboss.jsr299.tck/jsr299-tck-impl

public void contextInitialized(ServletContextEvent sce)
{
 boolean result = manager.getContext(ApplicationScoped.class).isActive();
 this.result.setApplicationScopeActiveForServletContextListener(result);
}

代码示例来源:origin: org.jboss.jsr299.tck/jsr299-tck-impl

public void sessionCreated(HttpSessionEvent hsc)
{
 boolean result = manager.getContext(ApplicationScoped.class).isActive();
 this.result.setApplicationScopeActiveForHttpSessionListener(result);
}

代码示例来源:origin: org.jboss.jsr299.tck/jsr299-tck-impl

public void requestInitialized(ServletRequestEvent sre)
{
 boolean result = manager.getContext(ApplicationScoped.class).isActive();
 this.result.setApplicationScopeActiveForServletRequestListener(result);
}

代码示例来源:origin: org.apache.tomee/openejb-http

public static void ensureRequestScope(final ContextsService cs, final ServletRequestListener listener) {
  final Context reqCtx = cs.getCurrentContext(RequestScoped.class);
  if (reqCtx == null || !cs.getCurrentContext(RequestScoped.class).isActive()) {
    listener.requestInitialized(null);
    FAKE_REQUEST.set(true);
  }
}

代码示例来源:origin: org.jboss.jsr299.tck/jsr299-tck-impl

@Test(groups = { "contexts" }, expectedExceptions = { ContextNotActiveException.class })
@SpecAssertion(section = "6.2", id = "m")
public void testInvokingGetOnInactiveContextFails()
{
 Context sessionContext = getCurrentManager().getContext(SessionScoped.class);
 assert sessionContext.isActive();
 setContextInactive(sessionContext);
 Contextual<MySessionBean> mySessionBean = getBeans(MySessionBean.class).iterator().next();
 sessionContext.get(mySessionBean);
}

代码示例来源:origin: org.apache.openwebbeans/openwebbeans-web

private boolean ensureRequestScope()
{
  Context context = this.lifeCycle.getContextService().getCurrentContext(RequestScoped.class);
  if (context == null || !context.isActive())
  {
    requestInitialized(null);
    return true;
  }
  return false;
}

代码示例来源:origin: org.jboss.jsr299.tck/jsr299-tck-impl

@Test(groups = { "contexts" })
@SpecAssertions({
 @SpecAssertion(section = "6.2", id = "ha"),
 @SpecAssertion(section = "6.4", id = "g")
})
public void testContextIsActive()
{
 assert getCurrentManager().getContext(Dependent.class).isActive();
}

相关文章

微信公众号

最新文章

更多