@Test
 @SpecAssertions({@SpecAssertion(section = BM_OBTAIN_PRODUCER, id = "b")})
 public void testStaticProducerField() {
   AnnotatedField<? super Factory> field =
       this.<Factory, AnnotatedField<Factory>>getAnnotatedMember(Factory.class, "WOODY");
   Producer<Toy> producer =
       cast(getCurrentManager().getProducerFactory(field, null).createProducer(null));
   assertNotNull(producer);
   assertTrue(producer.getInjectionPoints().isEmpty());
   Toy woody = producer.produce(getCurrentManager().<Toy>createCreationalContext(null));
   assertEquals("Woody", woody.getName());
 }
 @Test
 @SpecAssertions({@SpecAssertion(section = BM_OBTAIN_PRODUCER, id = "a")})
 public void testStaticProducerMethod() {
   AnnotatedMethod<? super Factory> method =
       this.<Factory, AnnotatedMethod<Factory>>getAnnotatedMember(Factory.class, "getBuzz");
   Producer<Toy> producer =
       cast(getCurrentManager().getProducerFactory(method, null).createProducer(null));
   assertNotNull(producer);
   validateInjectionPoints(producer.getInjectionPoints());
   Toy buzz = producer.produce(getCurrentManager().<Toy>createCreationalContext(null));
   assertEquals("Buzz Lightyear", buzz.getName());
 }
 @Test
 @SpecAssertions({@SpecAssertion(section = BM_OBTAIN_PRODUCER, id = "b")})
 public void testNonStaticProducerField() {
   AnnotatedField<? super AnotherFactory> field =
       this.<AnotherFactory, AnnotatedField<AnotherFactory>>getAnnotatedMember(
           AnotherFactory.class, "jessie");
   Bean<AnotherFactory> declaringBean =
       cast(getCurrentManager().resolve(getCurrentManager().getBeans(AnotherFactory.class)));
   Producer<Toy> producer =
       cast(getCurrentManager().getProducerFactory(field, declaringBean).createProducer(null));
   assertNotNull(producer);
   assertTrue(producer.getInjectionPoints().isEmpty());
   Toy jessie = producer.produce(getCurrentManager().<Toy>createCreationalContext(null));
   assertEquals("Jessie", jessie.getName());
 }
 @Test
 @SpecAssertions({@SpecAssertion(section = BM_OBTAIN_PRODUCER, id = "a")})
 public void testNonStaticProducerMethod() {
   AnnotatedMethod<? super AnotherFactory> method =
       this.<AnotherFactory, AnnotatedMethod<AnotherFactory>>getAnnotatedMember(
           AnotherFactory.class, "getRex");
   Bean<AnotherFactory> declaringBean =
       cast(getCurrentManager().resolve(getCurrentManager().getBeans(AnotherFactory.class)));
   Producer<Toy> producer =
       cast(getCurrentManager().getProducerFactory(method, declaringBean).createProducer(null));
   assertNotNull(producer);
   validateInjectionPoints(producer.getInjectionPoints());
   Toy rex = producer.produce(getCurrentManager().<Toy>createCreationalContext(null));
   assertEquals("Rex", rex.getName());
 }
  @Override
  public T create(CreationalContext<T> createEnv) {
    T value = _producer.produce(createEnv);

    createEnv.push(value);

    return value;
  }
  /** Call destroy */
  @Override
  public void destroy(T instance, CreationalContext<T> cxt) {
    if (_producer == _methodProducer)
      _methodProducer.destroy(instance, (CreationalContextImpl<T>) cxt);
    else _producer.dispose(instance);

    if (cxt instanceof CreationalContextImpl<?>) {
      CreationalContextImpl<?> env = (CreationalContextImpl<?>) cxt;

      env.clearTarget();
    }

    cxt.release();
  }
 public void validateProducer(Producer<?> producer) {
   if (container.getState().equals(ContainerState.VALIDATED)
       || container.getState().equals(ContainerState.INITIALIZED)) {
     // We are past the bootstrap and therefore we can validate the producer immediately
     validator.validateProducer(producer, beanManager);
   } else {
     // Validate injection points for definition errors now
     for (InjectionPoint ip : producer.getInjectionPoints()) {
       validator.validateInjectionPointForDefinitionErrors(ip, ip.getBean(), beanManager);
       validator.validateEventMetadataInjectionPoint(ip);
     }
     // Schedule validation for deployment problems to be done later
     producersToValidate.add(producer);
   }
 }