/*
 * Created on Mar 15, 2005
 *
 * $Log$
 * Revision 1.1  2005/08/03 00:35:29  dsowen
 * Initial commit.
 *
 * Revision 1.2  2005/04/10 19:48:29  dowen
 * Renamed package.
 *
 * Revision 1.1  2005/03/19 16:49:20  dowen
 * Initial commit.
 *
 */
package ws.fugue88.jpath;

import java.lang.reflect.Field;

/**
 * @author dsowen
 */
class FieldProperty implements Property {

	FieldProperty(String name, Class clas, String field)
			throws NoSuchFieldException
	{
		_name = name;

		_field = clas.getDeclaredField(field);
		_field.setAccessible(true);

		_type = _field.getType();
	}

	public String getName()
	{
		return _name;
	}

	public Class getType()
	{
		return _type;
	}

	public Object getValue(Object that)
	{
		try {
			return _field.get(that);
		} catch(IllegalAccessException e) {
			throw new Error(e);
		}
	}

	public void setValue(Object that, Object value)
	{
		try {
			_field.set(that, value);
		} catch(IllegalAccessException e) {
			throw new Error(e);
		}
	}

	private String _name;
	private Class _type;
	private Field _field;
}