MethodBasedSetter.java

package org.microspace.specific;

import java.lang.reflect.Method;

import org.microspace.exception.IllegalOperationException;
import org.microspace.table.column.Setter;

/**
 * Method based Setter.
 * 
 * @author Gaspar Sinai - {@literal gaspar.sinai@microspace.org}
 * @version 2016-06-26
 * @param <T> is the Table type.
 */
public class MethodBasedSetter<T> implements Setter<T> {

	final Method method;
	final String name;
	
	public MethodBasedSetter (Method method, String name) {
		this.method = method;
		this.name = name;
	}
	
	public Method getMethod () {
		return method;
	}
	
	public String getName() {
		return name;
	}

	public void set(Object target, Object o) {
		try {
			method.invoke(target, o);
		} catch (Exception e) {
			throw new IllegalOperationException ("Cant envoke " + name, e);
		}
	}

}