/*
 * Created on Aug 2, 2005
 * 
 * $Log$
 * Revision 1.1  2005/08/03 00:35:29  dsowen
 * Initial commit.
 *
 */
package ws.fugue88.jpath;

/**
 * @author dsowen
 */
class Binder {

	Property getProperty(final Class type, final Identifier part)
			throws NoSuchPropertyException
	{
		try {
			return new MutableMethodProperty(part.getName(), type, "get"
					+ initialize(part.getName()), "set"
					+ initialize(part.getName()));
		} catch(NoSuchMethodException e) {
			try {
				return new ImmutableMethodProperty(part.getName(), type, "get"
						+ initialize(part.getName()));
			} catch(NoSuchMethodException e1) {
				try {
					return new FieldProperty(part.getName(), type,
							part.getName());
				} catch(NoSuchFieldException e2) {
					try {
						return new FieldProperty(part.getName(), type, "_"
								+ part.getName());
					} catch(NoSuchFieldException e3) {
						throw new NoSuchPropertyException(type, part.getName());
					}
				}
			}
		}
	}

	private static String initialize(final String s)
	{
		return s.substring(0, 1).toUpperCase() + s.substring(1);
	}
}