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

io.quarkus.arc.runtime.ConfigBeanCreator Maven / Gradle / Ivy

There is a newer version: 3.17.0.CR1
Show newest version
package io.quarkus.arc.runtime;

import java.util.Map;

import jakarta.enterprise.context.spi.CreationalContext;
import jakarta.enterprise.inject.spi.DeploymentException;
import jakarta.enterprise.inject.spi.InjectionPoint;

import org.eclipse.microprofile.config.ConfigProvider;

import io.quarkus.arc.BeanCreator;
import io.quarkus.arc.impl.InjectionPointProvider;
import io.smallrye.config.inject.ConfigProducerUtil;

public class ConfigBeanCreator implements BeanCreator {
    @Override
    public Object create(CreationalContext creationalContext, Map params) {
        String requiredType = params.get("requiredType").toString();
        ClassLoader cl = Thread.currentThread().getContextClassLoader();
        if (cl == null) {
            cl = ConfigBeanCreator.class.getClassLoader();
        }

        try {
            Class.forName(requiredType, true, cl);
        } catch (ClassNotFoundException e) {
            throw new IllegalStateException("Cannot load required type: " + requiredType);
        }

        InjectionPoint injectionPoint = InjectionPointProvider.getCurrent(creationalContext);
        if (injectionPoint == null) {
            throw new IllegalStateException("No current injection point found");
        }

        ConfigStaticInitCheckInterceptor.recordConfigValue(injectionPoint, null);

        try {
            return ConfigProducerUtil.getValue(injectionPoint, ConfigProvider.getConfig());
        } catch (Exception e) {
            throw new DeploymentException(e);
        }
    }
}