javax.enterprise.inject.spi.Bean.create()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(9.6k)|赞(0)|评价(0)|浏览(167)

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

Bean.create介绍

暂无

代码示例

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

@Override
@SuppressWarnings("unchecked")
public Object getInstance(ForeignDescriptor foreignDescriptor) {
  Bean bean = (Bean) foreignDescriptor.get();
  CreationalContext ctx = beanManager.createCreationalContext(bean);
  return bean.create(ctx);
}

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

@Test(groups = { "contexts", "producerMethod" })
@SpecAssertion(section = "6.4", id = "da")
public void testInstanceUsedForProducerMethodNotShared() throws Exception
{
 Bean<Tarantula> tarantulaBean = getBeans(Tarantula.class, PET_LITERAL).iterator().next();
 
 CreationalContext<Tarantula> creationalContext = getCurrentManager().createCreationalContext(tarantulaBean);
 Tarantula tarantula = tarantulaBean.create(creationalContext);
 Tarantula tarantula2 = tarantulaBean.create(creationalContext);
 assert tarantula != null;
 assert tarantula2 != null;
 assert tarantula != tarantula2;
}

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

@Test
@SpecAssertion(section = DEPENDENT_CONTEXT, id = "g")
// Dependent context is now always active
public void testContextIsActiveDuringInjection() {
  Bean<FoxRun> foxRunBean = getBeans(FoxRun.class).iterator().next();
  FoxRun foxRun = foxRunBean.create(new MockCreationalContext<FoxRun>());
  assert foxRun.fox != null;
}

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

@Test(groups = { "contexts", "producerMethod" })
@SpecAssertion(section = "6.4", id = "db")
public void testInstanceUsedForProducerFieldNotShared() throws Exception
{
 Bean<Tarantula> tarantulaBean = getBeans(Tarantula.class, TAME_LITERAL).iterator().next();
 CreationalContext<Tarantula> creationalContext = getCurrentManager().createCreationalContext(tarantulaBean);
 Tarantula tarantula = tarantulaBean.create(creationalContext);
 Tarantula tarantula2 = tarantulaBean.create(creationalContext);
 assert tarantula != null;
 assert tarantula2 != null;
 assert tarantula != tarantula2;
}

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

@Test(groups = { "contexts", "injection" })
@SpecAssertion(section = "6.4", id = "g") // Dependent context is now always active
public void testContextIsActiveDuringInjection()
{
 Bean<FoxRun> foxRunBean = getBeans(FoxRun.class).iterator().next();
 FoxRun foxRun = foxRunBean.create(new MockCreationalContext<FoxRun>());
 assert foxRun.fox != null;
}

代码示例来源:origin: hibernate/hibernate-orm

this.creationalContext = beanManager.createCreationalContext( null );
Set<Bean<?>> beans = beanManager.getBeans( beanType, new NamedBeanQualifier( beanName ) );
this.bean = (Bean<B>) beanManager.resolve( beans );
this.beanInstance = bean.create( creationalContext );

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

@Test(groups = { "injection", "producerMethod" })
@SpecAssertion(section = "2.3.5", id = "a")
public void testFieldInjectedFromProducerMethod() throws Exception
{
 Bean<Barn> barnBean = getBeans(Barn.class).iterator().next();
 Barn barn = barnBean.create(getCurrentManager().createCreationalContext(barnBean));
 assert barn.petSpider != null;
 assert barn.petSpider instanceof DefangedTarantula;
}

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

@Override
public Object resolve(Injectee injectee) {
  Injectee newInjectee = injectee;
  if (injectee.isFactory()) {
    newInjectee = getFactoryInjectee(injectee, ReflectionHelper.getTypeArgument(injectee.getRequiredType(), 0));
  }
  Bean<?> bean = descriptorCache.apply(newInjectee.getRequiredType());
  if (bean != null) {
    CreationalContext ctx = beanManager.get().createCreationalContext(bean);
    Object result = bean.create(ctx);
    if (injectee.isFactory()) {
      return (Supplier<Object>) () -> result;
    } else {
      return result;
    }
  }
  return null;
}

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

@Test(groups = { "enterpriseBeans", "lifecycle", "integration" })
@SpecAssertions({
  @SpecAssertion(section = "7.3.3", id = "b")})
public void testCreateSLSB()
{
 Bean<NeueStadt> stadtBean = getBeans(NeueStadt.class).iterator().next();
 assert stadtBean != null : "Expected a bean for stateful session bean Kassel";
 CreationalContext<NeueStadt> creationalContext = getCurrentManager().createCreationalContext(stadtBean);
 NeueStadt stadtInstance = stadtBean.create(creationalContext);
 assert stadtInstance != null : "Expected instance to be created by container";
 // Verify that the instance returned is a proxy by checking for all local interfaces
 Set<Class> interfaces = new HashSet<Class>(Arrays.asList(stadtInstance.getClass().getInterfaces()));
 assert interfaces.contains(NeueStadt.class);
 assert interfaces.contains(GeschichtslosStadt.class);
}

代码示例来源:origin: io.joynr.java/jeeintegration

@Override
  public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
    T instance = bean.create(beanManager.createCreationalContext(bean));
    return method.invoke(instance, args);
  }
}

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

@Test(groups = { "producerMethod" }, expectedExceptions = FooException.class)
@SpecAssertions({
 @SpecAssertion(section = "6.1", id = "a0")
})
public void testCreateRethrowsUncheckedException()
{
 Bean<Ship> shipBean = getBeans(Ship.class, FAIL_LITERAL).iterator().next();
 CreationalContext<Ship> shipCc = getCurrentManager().createCreationalContext(shipBean);
 shipBean.create(shipCc);
 assert false;
}

代码示例来源:origin: stackoverflow.com

@Inject BeanManager manager; //inject the bean manager into your class

public static MyExample getMyExample(String myExampleType){
  Set<Bean<?>> beans = manager.getBeans("example1"); //retrieve the bean by name. This returns a set, but you're ideally interested in only one bean
  Bean bean = beans.iterator().next(); //get the first (and ideally the only bean in the set)
  CreationalContext ctx = manager.createCreationalContext(bean); //CDI stipulation: there has to be a context associated with everything.
  MyExample theExample = bean.create(ctx); //create an instance of the bean and return

  return theExample;

}

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

@Test(expectedExceptions = FooException.class)
@SpecAssertions({ @SpecAssertion(section = CONTEXTUAL, id = "aa") })
public void testCreateRethrowsUncheckedException() {
  Bean<Ship> shipBean = getBeans(Ship.class, FAIL_LITERAL).iterator().next();
  CreationalContext<Ship> shipCc = getCurrentManager().createCreationalContext(shipBean);
  shipBean.create(shipCc);
  assert false;
}

代码示例来源:origin: io.joynr.java/jeeintegration

@SuppressWarnings({ "rawtypes", "unchecked", "serial" })
private Set<ProviderQosFactory> getProviderQosFactories() {
  Set<Bean<?>> providerQosFactoryBeans = beanManager.getBeans(ProviderQosFactory.class,
                                new AnnotationLiteral<Any>() {
                                });
  Set<ProviderQosFactory> providerQosFactories = new HashSet<>();
  for (Bean providerQosFactoryBean : providerQosFactoryBeans) {
    ProviderQosFactory factory = (ProviderQosFactory) providerQosFactoryBean.create(beanManager.createCreationalContext(providerQosFactoryBean));
    providerQosFactories.add(factory);
  }
  return providerQosFactories;
}

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

@Test(expectedExceptions = CreationException.class)
  @SpecAssertions({ @SpecAssertion(section = CONTEXTUAL, id = "aa") })
  public void testCreateWrapsCheckedExceptionAndRethrows() {
    Bean<Lorry> lorryBean = getBeans(Lorry.class, FAIL_LITERAL).iterator().next();
    CreationalContext<Lorry> lorryCc = getCurrentManager().createCreationalContext(lorryBean);
    lorryBean.create(lorryCc);
    assert false;
  }
}

代码示例来源:origin: org.jboss.seam.remoting/seam-remoting

@SuppressWarnings("unchecked")
private MetadataCache getMetadataCache() {
  if (metadataCache == null) {
    Bean<MetadataCache> bean = (Bean<MetadataCache>) beanManager.getBeans(
        MetadataCache.class).iterator().next();
    metadataCache = bean.create(beanManager.createCreationalContext(bean));
  }
  return metadataCache;
}

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

@Test(groups = { "producerMethod" })
@SpecAssertions({
 @SpecAssertion(section = "7.3.4", id = "k")
})
public void testCreateReturnsNullIfProducerDoesAndDependent()
{
 Bean<Spider> nullSpiderBean = getBeans(Spider.class, NULL_LITERAL).iterator().next();
 CreationalContext<Spider> nullSpiderBeanCc = getCurrentManager().createCreationalContext(nullSpiderBean);
 assert nullSpiderBean.create(nullSpiderBeanCc) == null;
}

代码示例来源:origin: org.jboss.seam.remoting/seam-remoting-core

@SuppressWarnings("unchecked")
private MetadataCache getMetadataCache()
{
 if (metadataCache == null)
 {
   Bean<MetadataCache> bean = (Bean<MetadataCache>) beanManager.getBeans(
      MetadataCache.class).iterator().next(); 
   metadataCache = bean.create(beanManager.createCreationalContext(bean));
 }
 return metadataCache;
}

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

@Test(groups = { "producerMethod" }, expectedExceptions = CreationException.class)
  @SpecAssertions({
   @SpecAssertion(section = "6.1", id = "a0")
  })
  public void testCreateWrapsCheckedExceptionAndRethrows()
  {
   Bean<Lorry> lorryBean = getBeans(Lorry.class, FAIL_LITERAL).iterator().next();
   CreationalContext<Lorry> lorryCc = getCurrentManager().createCreationalContext(lorryBean);
   lorryBean.create(lorryCc);
   assert false;
  }
}

代码示例来源:origin: org.tomitribe/crest-ssh-connector-impl

@Override
  public ScopedInstance<?> apply(final Class<?> ignored) {
    logger.info(m("create(%s)", beanClass.getName()));
    if (creationalContext == null) {
      final CreationalContext<T> context = beanManager.createCreationalContext(bean);
      return new ScopedInstance<T>(bean, context, bean.create(context));
    }
    return new ScopedInstance<T>(bean, creationalContext, bean.create(creationalContext));
  }
});

相关文章