// Path: disconf-core/src/main/java/com/baidu/disconf/core/common/constants/DisConfigTypeEnum.java
// public enum DisConfigTypeEnum {
// 
//     FILE(0, "配置文件"), ITEM(1, "配置项");
// 
//     private int type = 0;
//     private String modelName = null;
// 
//     private DisConfigTypeEnum(int type, String modelName) {
//         this.type = type;
//         this.modelName = modelName;
//     }
// 
//     public static DisConfigTypeEnum getByType(int type) {
// 
//         int index = 0;
//         for (DisConfigTypeEnum disConfigTypeEnum : DisConfigTypeEnum.values()) {
// 
//             if (type == index) {
//                 return disConfigTypeEnum;
//             }
// 
//             index++;
//         }
// 
//         return null;
//     }
// 
//     public int getType() {
//         return type;
//     }
// 
//     public void setType(int type) {
//         this.type = type;
//     }
// 
//     public String getModelName() {
//         return modelName;
//     }
// 
//     public void setModelName(String modelName) {
//         this.modelName = modelName;
//     }
// 
// }


import java.lang.reflect.Field;
import java.lang.reflect.Method;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.reflect.MethodSignature;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.baidu.disconf.client.common.annotations.DisconfFile;
import com.baidu.disconf.client.common.annotations.DisconfFileItem;
import com.baidu.disconf.client.common.annotations.DisconfItem;
import com.baidu.disconf.client.config.DisClientConfig;
import com.baidu.disconf.client.store.DisconfStoreProcessor;
import com.baidu.disconf.client.store.DisconfStoreProcessorFactory;
import com.baidu.disconf.client.support.utils.MethodUtils;
import com.baidu.disconf.core.common.constants.DisConfigTypeEnum;
package com.baidu.disconf.client.store.aspect;




/**
 * 配置拦截
 *
 * @author liaoqiqi
 * @version 2014-6-11
 */
@Aspect
public class DisconfAspectJ {

    protected static final Logger LOGGER = LoggerFactory.getLogger(DisconfAspectJ.class);

    @Pointcut(value = "execution(public * *(..))")
    public void anyPublicMethod() {
    }

    /**
     * 获取配置文件数据, 只有开启disconf远程才会进行切面
     *
     * @throws Throwable
     */
    @Around("anyPublicMethod() && @annotation(disconfFileItem)")
    public Object decideAccess(ProceedingJoinPoint pjp, DisconfFileItem disconfFileItem) throws Throwable {

        if (DisClientConfig.getInstance().ENABLE_DISCONF) {

            MethodSignature ms = (MethodSignature) pjp.getSignature();
            Method method = ms.getMethod();

            //
            // 文件名
            //
            Class<?> cls = method.getDeclaringClass();
            DisconfFile disconfFile = cls.getAnnotation(DisconfFile.class);

            //
            // Field名
            //
// Path: disconf-core/src/main/java/com/baidu/disconf/core/common/constants/DisConfigTypeEnum.java
// public enum DisConfigTypeEnum {
// 
//     FILE(0, "配置文件"), ITEM(1, "配置项");
// 
//     private int type = 0;
//     private String modelName = null;
// 
//     private DisConfigTypeEnum(int type, String modelName) {
//         this.type = type;
//         this.modelName = modelName;
//     }
// 
//     public static DisConfigTypeEnum getByType(int type) {
// 
//         int index = 0;
//         for (DisConfigTypeEnum disConfigTypeEnum : DisConfigTypeEnum.values()) {
// 
//             if (type == index) {
//                 return disConfigTypeEnum;
//             }
// 
//             index++;
//         }
// 
//         return null;
//     }
// 
//     public int getType() {
//         return type;
//     }
// 
//     public void setType(int type) {
//         this.type = type;
//     }
// 
//     public String getModelName() {
//         return modelName;
//     }
// 
//     public void setModelName(String modelName) {
//         this.modelName = modelName;
//     }
// 
// }


// Path: disconf-client/src/main/java/com/baidu/disconf/client/store/aspect/DisconfAspectJ.java
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.reflect.MethodSignature;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.baidu.disconf.client.common.annotations.DisconfFile;
import com.baidu.disconf.client.common.annotations.DisconfFileItem;
import com.baidu.disconf.client.common.annotations.DisconfItem;
import com.baidu.disconf.client.config.DisClientConfig;
import com.baidu.disconf.client.store.DisconfStoreProcessor;
import com.baidu.disconf.client.store.DisconfStoreProcessorFactory;
import com.baidu.disconf.client.support.utils.MethodUtils;
import com.baidu.disconf.core.common.constants.DisConfigTypeEnum;

package com.baidu.disconf.client.store.aspect;




/**
 * 配置拦截
 *
 * @author liaoqiqi
 * @version 2014-6-11
 */
@Aspect
public class DisconfAspectJ {

    protected static final Logger LOGGER = LoggerFactory.getLogger(DisconfAspectJ.class);

    @Pointcut(value = "execution(public * *(..))")
    public void anyPublicMethod() {
    }

    /**
     * 获取配置文件数据, 只有开启disconf远程才会进行切面
     *
     * @throws Throwable
     */
    @Around("anyPublicMethod() && @annotation(disconfFileItem)")
    public Object decideAccess(ProceedingJoinPoint pjp, DisconfFileItem disconfFileItem) throws Throwable {

        if (DisClientConfig.getInstance().ENABLE_DISCONF) {

            MethodSignature ms = (MethodSignature) pjp.getSignature();
            Method method = ms.getMethod();

            //
            // 文件名
            //
            Class<?> cls = method.getDeclaringClass();
            DisconfFile disconfFile = cls.getAnnotation(DisconfFile.class);

            //
            // Field名
            //
            Field field = MethodUtils.getFieldFromMethod(method, cls.getDeclaredFields(), DisConfigTypeEnum.FILE);