org.infinispan.cdi.util.defaultbean.DefaultProducerMethod Maven / Gradle / Ivy
package org.infinispan.cdi.util.defaultbean;
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
import java.util.Set;
import javax.enterprise.context.spi.CreationalContext;
import javax.enterprise.inject.spi.AnnotatedMethod;
import javax.enterprise.inject.spi.Bean;
import javax.enterprise.inject.spi.BeanManager;
import org.infinispan.cdi.util.InjectableMethod;
// TODO Make this passivation capable
class DefaultProducerMethod extends AbstractDefaultProducerBean {
private final InjectableMethod producerMethod;
private final InjectableMethod disposerMethod;
static DefaultProducerMethod of(Bean originalBean, Type declaringBeanType, Set beanTypes, Set qualifiers, Set declaringBeanQualifiers, AnnotatedMethod method, AnnotatedMethod disposerMethod, BeanManager beanManager) {
return new DefaultProducerMethod(originalBean, declaringBeanType, beanTypes, qualifiers, declaringBeanQualifiers, method, disposerMethod, beanManager);
}
DefaultProducerMethod(Bean originalBean, Type declaringBeanType, Set beanTypes, Set qualifiers, Set declaringBeanQualifiers, AnnotatedMethod method, AnnotatedMethod disposerMethod, BeanManager beanManager) {
super(originalBean, declaringBeanType, beanTypes, qualifiers, declaringBeanQualifiers, beanManager);
this.producerMethod = new InjectableMethod(method, this, beanManager);
if (disposerMethod != null) {
this.disposerMethod = new InjectableMethod(disposerMethod, this, beanManager);
} else {
this.disposerMethod = null;
}
}
@Override
protected T getValue(Object receiver, CreationalContext creationalContext) {
return producerMethod.invoke(receiver, creationalContext);
}
@Override
public void destroy(T instance, CreationalContext creationalContext) {
if (disposerMethod != null) {
try {
disposerMethod.invoke(getReceiver(creationalContext), creationalContext);
} finally {
creationalContext.release();
}
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy