package com.lideeyunji.core.framework.config.aspect.enhance.strategy.java;

import com.lideeyunji.core.framework.config.aspect.enhance.model.EnhanceContext;
import com.lideeyunji.core.framework.config.aspect.enhance.plugin.*;
import com.lideeyunji.core.framework.entity.EnhanceJavaEntity;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;

/**
 * Spring方式增强
 */
@Slf4j
public class SpringEnhanceJavaStrategy extends BaseEnhanceJavaStrategy implements EnhanceJavaStrategy {

    //执行
    @Override
    public void execute(EnhanceJavaEntity enhanceJavaEntity, EnhanceContext context, String type, JoinPoint joinPoint) throws Throwable {
        String javaClassUrl = enhanceJavaEntity.getJavaClassUrl();//
        this.executeSpringEnhance(javaClassUrl, type, context, joinPoint);
    }
    /*
     * 执行spring增强
     */
    private void executeSpringEnhance(String javaClassUrl, String type, EnhanceContext context, JoinPoint joinPoint) throws Throwable {
        switch (type) {
            case "start"://前置增强
                super.executeBeforeEnhance(javaClassUrl, context);
                break;
            case "end"://后置增强
                super.executeAfterEnhance(javaClassUrl, context);
                break;
            case "around":
                super.executeAroundEnhance(javaClassUrl, context, joinPoint);
                break;
            case "throwing":
                super.executeThrowEnhance(javaClassUrl, context);
                break;
            default:
                break;
        }
    }

}
