/* Classes.java

{{IS_NOTE
	Purpose:
		
	Description:
		
	History:
		Aug 29, 2012 8:57:08 AM , Created by Sam
}}IS_NOTE

Copyright (C) 2012 Potix Corporation. All Rights Reserved.

{{IS_RIGHT
}}IS_RIGHT
*/
package org.zkoss.zpoiex.util;

import java.lang.reflect.Field;

/**
 * @author Sam
 *
 */
public class Classes {

	/**
	 * Gets the specified field by searching all fields including
	 * any access control and any base class.
	 * The search sequence is: this class's fields, and then
	 * the superclass's fields.
	 *
	 * <p>Note: public fields don't be treated different. If the caller
	 * wants to search public fields first, it has to call Class.getField
	 * first.
	 *
	 * @param cls the class to search
	 * @param name the field name
	 * @return the Field object
	 * @exception NoSuchFieldException if a matching field is not found.
	 * @exception SecurityException if access to the information is denied.
	 * @see #getAccessibleObject(Class, String, Class[], int)
	 * @see #getAnyMethod(Class, String, Class[])
	 */
	public static final Field getAnyField(Class<?> cls, String name)
	throws NoSuchFieldException {
		for (;;) {
			try {
				return cls.getDeclaredField(name);
			} catch (NoSuchFieldException ex) {
				cls = cls.getSuperclass();
				if (cls == null)
					throw ex;
			}
		}
	}
}
