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

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

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

Context.get介绍

[英]Return an existing instance of a certain contextual type or a null value.
[中]返回特定上下文类型的现有实例或空值。

代码示例

代码示例来源:origin: HotswapProjects/HotswapAgent

@SuppressWarnings({ "unchecked", "rawtypes" })
private static void doReinjectBeanInstance(BeanManagerImpl beanManager, AbstractClassBean bean, Context context) {
  Object instance = context.get(bean);
  if (instance != null) {
    doCallInject(beanManager, bean, instance);
  }
}

代码示例来源:origin: HotswapProjects/HotswapAgent

@SuppressWarnings({ "unchecked", "rawtypes" })
private static void doReinjectBeanInstance(BeanManagerImpl beanManager, InjectionTargetBean bean, Context context) {
  Object instance = context.get(bean);
  if (instance != null) {
    bean.getProducer().inject(instance, beanManager.createCreationalContext(bean));
    LOGGER.info("Bean '{}' injection points was reinjected.", bean.getBeanClass().getName());
  }
}

代码示例来源:origin: HotswapProjects/HotswapAgent

/**
   * Will re-inject any managed beans in the target. Will not call any other life-cycle methods
   *
   * @param ctx
   * @param managedBean
   */
  public static void reinitialize(Context ctx, Contextual<Object> contextual) {
    try {
      ManagedBean<Object> managedBean = ManagedBean.class.cast(contextual);
      LOGGER.debug("Re-Initializing........ {},: {}", managedBean, ctx);
      Object get = ctx.get(managedBean);
      if (get != null) {
        LOGGER.debug("Bean injection points are reinitialized '{}'", managedBean);
        managedBean.getProducer().inject(get, managedBean.getBeanManager().createCreationalContext(managedBean));
      }
    } catch (Exception e) {
      LOGGER.error("Error reinitializing bean {},: {}", e, contextual, ctx);
    }
  }
}

代码示例来源:origin: HotswapProjects/HotswapAgent

/**
   * Will re-inject any managed beans in the target. Will not call any other life-cycle methods
   *
   * @param ctx
   * @param managedBean
   */
  @SuppressWarnings("unchecked")
  static void reinitialize(Context ctx, Contextual<Object> contextual) {
    try {
      ManagedBean<Object> managedBean = ManagedBean.class.cast(contextual);
      LOGGER.debug("Re-Initializing bean '{}' in context '{}'", managedBean, ctx);
      Object get = ctx.get(managedBean);
      if (get != null) {
        LOGGER.debug("Bean injection points are reinitialized '{}'", managedBean);
        CreationalContextImpl<Object> creationalContext = managedBean.getWebBeansContext().getCreationalContextFactory().getCreationalContext(managedBean);
        managedBean.getProducer().inject(get, creationalContext);
      }
    } catch (Exception e) {
      LOGGER.error("Error reinitializing bean '{}' in context '{}'", e, contextual, ctx);
    }
  }
}

代码示例来源:origin: org.jboss.weld.se/weld-se

@Override
public <T> T get(Contextual<T> contextual) {
  contextual = store.getSerializableContextual(contextual);
  return context.get(contextual);
}

代码示例来源:origin: org.apache.myfaces.core/myfaces-impl

public static <T> T getInstance(BeanManager beanManager, Bean<T> bean, boolean create)
{
  Context context = beanManager.getContext(bean.getScope());
  if (create)
  {
    return context.get(bean, beanManager.createCreationalContext(bean));
  }
  else
  {
    return context.get(bean);
  }
}

代码示例来源:origin: weld/core

@Override
public <T> T get(Contextual<T> contextual, CreationalContext<T> creationalContext) {
  contextual = store.getSerializableContextual(contextual);
  return context.get(contextual, creationalContext);
}

代码示例来源:origin: org.jboss.weld.se/weld-se

@Override
public <T> T get(Contextual<T> contextual, CreationalContext<T> creationalContext) {
  contextual = store.getSerializableContextual(contextual);
  return context.get(contextual, creationalContext);
}

代码示例来源:origin: weld/core

@Override
public <T> T get(Contextual<T> contextual, CreationalContext<T> creationalContext) {
  contextual = store.getSerializableContextual(contextual);
  return context.get(contextual, creationalContext);
}

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

@Override
public <T> T get(Contextual<T> contextual)
{
  return context.get(sbv.getSerializableBean(contextual));
}

代码示例来源:origin: weld/core

@Override
public <T> T get(Contextual<T> contextual) {
  contextual = store.getSerializableContextual(contextual);
  return context.get(contextual);
}

代码示例来源:origin: com.sun.jersey/jersey-servlet

public static CDIExtension getCdiExtensionInstance(BeanManager beanManager) {
  Bean<?> bean = getBean(beanManager, CDIExtension.class);
  if  (bean == null) {
    return null;
  }
  return ( CDIExtension ) beanManager.getContext( ApplicationScoped.class ).get( bean );
}

代码示例来源:origin: weld/core

@Override
T get(Bean<T> bean, BeanManagerImpl manager, CreationalContext<?> ctx) {
  Context context = manager.getContext(bean.getScope());
  T instance = context.get(bean);
  if (instance == null) {
    if (ctx == null) {
      ctx = manager.createCreationalContext(bean);
    }
    instance = context.get(bean, Reflections.<CreationalContext<T>> cast(ctx));
  }
  return instance;
}

代码示例来源:origin: weld/core

@Override
T get(Bean<T> bean, BeanManagerImpl manager, CreationalContext<?> ctx) {
  Context context = manager.getContext(bean.getScope());
  T instance = context.get(bean);
  if (instance == null) {
    if (ctx == null) {
      ctx = manager.createCreationalContext(bean);
    }
    instance = context.get(bean, Reflections.<CreationalContext<T>> cast(ctx));
  }
  return instance;
}

代码示例来源:origin: org.jboss.weld.se/weld-se

@Override
T get(Bean<T> bean, BeanManagerImpl manager, CreationalContext<?> ctx) {
  Context context = manager.getContext(bean.getScope());
  T instance = context.get(bean);
  if (instance == null) {
    if (ctx == null) {
      ctx = manager.createCreationalContext(bean);
    }
    instance = context.get(bean, Reflections.<CreationalContext<T>> cast(ctx));
  }
  return instance;
}

代码示例来源:origin: org.jboss.weld.se/weld-se-shaded

@Override
T get(Bean<T> bean, BeanManagerImpl manager, CreationalContext<?> ctx) {
  Context context = manager.getContext(bean.getScope());
  T instance = context.get(bean);
  if (instance == null) {
    if (ctx == null) {
      ctx = manager.createCreationalContext(bean);
    }
    instance = context.get(bean, Reflections.<CreationalContext<T>> cast(ctx));
  }
  return instance;
}

代码示例来源:origin: weld/core

@Override
T get(Bean<T> bean, BeanManagerImpl manager, CreationalContext<?> ctx) {
  Context context = manager.getContext(bean.getScope());
  T instance = context.get(bean);
  if (instance == null) {
    if (ctx == null) {
      ctx = manager.createCreationalContext(bean);
    }
    instance = context.get(bean, Reflections.<CreationalContext<T>> cast(ctx));
  }
  return instance;
}

代码示例来源:origin: org.jboss.weld.integration/weld-jboss-int-jboss-ejb

@SuppressWarnings("unchecked")
private void addInterceptorInstance(Interceptor<Object> interceptor, InvocationContext invocationContext)
{
 CreationalContext<Object> creationalContext = (CreationalContext<Object>) invocationContext.getContextData().get(SessionBeanInterceptor.CREATIONAL_CONTEXT);
 Object instance = beanManager.getContext(interceptor.getScope()).get(interceptor, creationalContext);
 SerializableContextualInstance<Interceptor<Object>,Object> serializableContextualInstance
    = beanManager.getServices().get(ContextualStore.class).getSerializableContextualInstance(interceptor, instance, creationalContext);
 interceptorInstances.put(interceptor.getBeanClass().getName(), serializableContextualInstance);
}

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

@Test
@SpecAssertions({ @SpecAssertion(section = CREATIONAL_CONTEXT, id = "d"), @SpecAssertion(section = CREATIONAL_CONTEXT, id = "g") })
public void testCreateReturnsSameBeanPushed() {
  final CreationalContext<ShoeFactory> creationalContext = new MockCreationalContext<ShoeFactory>();
  final Contextual<ShoeFactory> bean = getBeans(ShoeFactory.class).iterator().next();
  MockCreationalContext.reset();
  ShoeFactory instance = getCurrentManager().getContext(Dependent.class).get(bean, creationalContext);
  if (MockCreationalContext.isPushCalled()) {
    assert instance == MockCreationalContext.getLastBeanPushed();
  }
}

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

@Test
@SpecAssertion(section = CONTEXT, id = "nb")
public void testGetMayNotReturnNullUnlessContextualCreateReturnsNull() {
  // The case of no creational context is already tested where a null is
  // returned. Here we just test that the contextual create can return null.
  MyContextual bean = AfterBeanDiscoveryObserver.getBean();
  bean.setShouldReturnNullInstances(true);
  CreationalContext<MySessionBean> creationalContext = new MockCreationalContext<MySessionBean>();
  assert getCurrentManager().getContext(SessionScoped.class).get(bean, creationalContext) == null;
  assert bean.isCreateCalled();
}

相关文章