package cn.axzo.msg.center.common.template;

import org.springframework.expression.EvaluationContext;
import org.springframework.expression.PropertyAccessor;
import org.springframework.expression.TypedValue;
import org.springframework.lang.NonNull;

import java.util.Map;

/**
 * @author yanglin
 */
class NullPropertyAccessor implements PropertyAccessor {

    static final NullPropertyAccessor INSTANCE = new NullPropertyAccessor();

    @Override
    public Class<?>[] getSpecificTargetClasses() {
        return new Class[]{String.class, Number.class, Map.class};
    }

    @Override
    public boolean canRead(@NonNull EvaluationContext context, Object target, @NonNull String name) {
        return true;
    }

    @NonNull
    @Override
    public TypedValue read(@NonNull EvaluationContext context, Object target, @NonNull String name) {
        return TypedValue.NULL;
    }

    @Override
    public boolean canWrite(@NonNull EvaluationContext context, Object target, @NonNull String name) {
        return false;
    }

    @Override
    public void write(@NonNull EvaluationContext context, Object target, @NonNull String name, Object newValue) {
    }
}
