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

import cc.smtweb.framework.core.mvc.controller.IBeanContext;
import cc.smtweb.framework.core.mvc.controller.IEditor;

import java.lang.reflect.Field;
import java.util.Map;

public class BindFieldAccess extends FieldAccess {
    private IEditor editor;
    private final String beanName;

    public BindFieldAccess(IEditor editor, Field field, String beanName) {
        super(field);
        this.editor = editor;
        this.beanName = beanName;
    }

    @Override
    protected Object getFieldValue(Object instance, IBeanContext context, Map<String, Object> params) {
        if (editor != null) {
            return editor.getParamValue(beanName, this.field.getType(), context, params, null, null);
        }

        return null;
    }
}
