/*
 * @author Ranides Atterwim <ranides@gmail.com>
 * @copyright Ranides Atterwim
 * @license WTFPL
 * @url http://ranides.net/projects/assira
 */

package net.ranides.assira.reflection.impl.bean;

import net.ranides.assira.reflection.IMethod;

/**
 *
 * @author Ranides Atterwim <ranides@gmail.com>
 */
public class RPField extends ABeanProperty {
    
    private final IMethod setter;
    private final IMethod getter;

    public RPField(RBeanPropertyInfo info) {
        super(info.type(), info.name());
        this.getter = info.vgetter();
        this.setter = info.vsetter();
    }
    
    @Override
    public void set(Object that, Object value) {
        if(null == setter) {
            throw new UnsupportedOperationException("Property " + name() + " is read-only");
        }
        setter.apply(that, value);
    }

    @Override
    public Object get(Object that) {
        if(null == getter) {
            throw new UnsupportedOperationException("Property " + name() + " is write-only");
        }
        return getter.apply(that);
    }

    @Override
    public boolean isReadable() {
        return getter != null;
    }

    @Override
    public boolean isWritable() {
        return setter != null;
    }

}
