/*
 * 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.InvocationTargetException;
import java.lang.reflect.Method;

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

	ImmutableMethodProperty(String name, Class clas, String get_method)
			throws NoSuchMethodException
	{
		_name = name;

		_get = clas.getDeclaredMethod(get_method, null);
		_get.setAccessible(true);

		_type = _get.getReturnType();
	}

	public Class getType()
	{
		return _type;
	}

	public String getName()
	{
		return _name;
	}

	public Object getValue(Object that) throws InvocationTargetException
	{
		try {
			return _get.invoke(that, null);
		} catch(IllegalAccessException e) {
			throw new Error(e);
		}
	}

	public void setValue(Object that, Object value)
			throws InvocationTargetException
	{
		throw new UnsupportedOperationException("Property '" + _name
				+ "' of class " + _type + "is read-only.");
	}

	private String _name;
	private Class _type;
	private Method _get;
}