All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.infinispan.cdi.util.defaultbean.DefaultProducerField Maven / Gradle / Ivy

There is a newer version: 9.1.7.Final
Show newest version
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.AnnotatedField;
import javax.enterprise.inject.spi.Bean;
import javax.enterprise.inject.spi.BeanManager;

import org.infinispan.cdi.util.Reflections;

// TODO Make this passivation capable
class DefaultProducerField extends AbstractDefaultProducerBean {

    private final AnnotatedField field;

    static  DefaultProducerField of(Bean originalBean, Type declaringBeanType, Set beanTypes, Set qualifiers, Set declaringBeanQualifiers, AnnotatedField field, BeanManager beanManager) {
        return new DefaultProducerField(originalBean, declaringBeanType, beanTypes, qualifiers, declaringBeanQualifiers, field, beanManager);
    }

    DefaultProducerField(Bean originalBean, Type declaringBeanType, Set beanTypes, Set qualifiers, Set declaringBeanQualifiers, AnnotatedField field, BeanManager beanManager) {
        super(originalBean, declaringBeanType, beanTypes, qualifiers, declaringBeanQualifiers, beanManager);
        this.field = field;
        if (!field.getJavaMember().isAccessible()) {
            field.getJavaMember().setAccessible(true);
        }
    }

    @Override
    protected T getValue(Object receiver, CreationalContext creationalContext) {
        return Reflections.getFieldValue(field.getJavaMember(), receiver, Reflections.getRawType(field.getBaseType()));
    }

    @Override
    public void destroy(T instance, CreationalContext creationalContext) {
        // TODO: disposers
        creationalContext.release();
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy