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

com.kuaishou.business.extension.spring.ExtPointBean Maven / Gradle / Ivy

The newest version!
package com.kuaishou.business.extension.spring;

import java.util.Optional;

import org.springframework.beans.factory.FactoryBean;
import org.springframework.cglib.proxy.Enhancer;

import com.kuaishou.business.core.Invoker;
import com.kuaishou.business.core.extpoint.ExtPoint;

import lombok.RequiredArgsConstructor;
import lombok.Setter;

@RequiredArgsConstructor
public class ExtPointBean implements FactoryBean {

    private final Class extPoint;

    private final Invoker invoke;

    @Setter
    private T defaultImpl;


    @Override
	public T getObject() {
        final Enhancer enhancer = new Enhancer();
        enhancer.setSuperclass(extPoint);
        final ExtPointBeanProxyMethod extPointBeanProxyMethod = new ExtPointBeanProxyMethod<>(extPoint, invoke);
        extPointBeanProxyMethod.setDefaultImpl(Optional.ofNullable(defaultImpl));
        enhancer.setCallback(extPointBeanProxyMethod);
        return (T) enhancer.create();
    }

    @Override
    public Class getObjectType() {
        return extPoint;
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy