package cc.smtweb.framework.core.mvc.controller.binder;

import cc.smtweb.framework.core.cache.CacheManager;
import cc.smtweb.framework.core.mvc.controller.IBeanContext;
import cc.smtweb.framework.core.mvc.controller.IEditor;
import org.apache.commons.lang3.StringUtils;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

public class CacheEditor implements IEditor {
    private CacheManager cacheManager;

    public CacheEditor(CacheManager cacheManager) {
        this.cacheManager = cacheManager;
    }

    @Override
    public Object getParamValue(String paramName, Class<?> paramType, IBeanContext context, Map<String, Object> params, String body, HttpServletRequest request) {
        if (StringUtils.isNotBlank(paramName)) {
            return cacheManager.getCache(paramName);
        } else {
            return cacheManager.getCache(paramType.getSimpleName());
        }
    }
}
