package ink.wgink.common.rpc.rest.scanner;

import ink.wgink.common.rpc.rest.proxy.RestRemoteProxy;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.InitializingBean;

/**
 * @ClassName: RemoteRestFactoryBean
 * @Description: 远程调用bean工厂
 * @Author: wanggeng
 * @Date: 2021/9/20 9:27 上午
 * @Version: 1.0
 */
public class RemoteRestFactoryBean<T> implements InitializingBean, FactoryBean<T> {

    private String innerClassName;

    @Override
    public T getObject() throws Exception {
        return (T) RestRemoteProxy.getInstance(Class.forName(innerClassName));
    }

    @Override
    public Class<?> getObjectType() {
        try {
            return Class.forName(innerClassName);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
        return null;
    }

    public boolean isSingleton() {
        return true;
    }

    @Override
    public void afterPropertiesSet() throws Exception {
    }

    public void setInnerClassName(String innerClassName) {
        this.innerClassName = innerClassName;
    }
}
