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

io.quarkus.resteasy.reactive.common.runtime.ArcBeanFactory Maven / Gradle / Ivy

There is a newer version: 3.15.2
Show newest version
package io.quarkus.resteasy.reactive.common.runtime;

import org.jboss.resteasy.reactive.spi.BeanFactory;

import io.quarkus.arc.runtime.BeanContainer;

public class ArcBeanFactory implements BeanFactory {

    private final BeanContainer.Factory factory;
    // for toString
    private final String targetClassName;

    public ArcBeanFactory(Class target, BeanContainer beanContainer) {
        targetClassName = target.getName();
        factory = beanContainer.instanceFactory(target);
    }

    @Override
    public String toString() {
        return "ArcBeanFactory[" + targetClassName + "]";
    }

    @Override
    public BeanInstance createInstance() {
        BeanContainer.Instance instance;
        try {
            instance = factory.create();
            return new BeanInstance() {
                @Override
                public T getInstance() {
                    return instance.get();
                }

                @Override
                public void close() {
                    instance.close();
                }
            };
        } catch (Exception e) {
            if (factory.getClass().getName().contains("DefaultInstanceFactory")) {
                throw new IllegalArgumentException(
                        "Unable to create class '" + targetClassName
                                + "'. To fix the problem, make sure this class is a CDI bean.",
                        e);
            }
            throw e;
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy