Example usage for com.badlogic.gdx.utils.reflect ReflectionException ReflectionException

List of usage examples for com.badlogic.gdx.utils.reflect ReflectionException ReflectionException

Introduction

In this page you can find the example usage for com.badlogic.gdx.utils.reflect ReflectionException ReflectionException.

Prototype

public ReflectionException(Throwable cause) 

Source Link

Usage

From source file:es.eucm.ead.engine.Accessor.java

License:Open Source License

/**
 * Retrieves the property with the given name from the given object via
 * reflection ({@link ClassReflection}).
 * //  w  ww. j av a2s.  c o m
 * @param parent
 *            The object to retrieve from
 * @param propertyName
 *            The name of the property to be retrieved.
 * @return The {@link Property} wrapper. Allows reading and writing the
 *         value of the property
 * @throws ReflectionException
 *             if the property cannot be accessed
 */
private Property getProperty(String fullId, Object parent, String propertyName) throws ReflectionException {
    Class currentClass = parent.getClass();
    while (currentClass != null) {
        for (Field declaredField : ClassReflection.getDeclaredFields(currentClass)) {
            if (declaredField.getName().equals(propertyName)) {
                declaredField.setAccessible(true);
                return obtainProperty(declaredField, fullId, parent);
            }
        }
        currentClass = currentClass.getSuperclass();
    }
    throw new ReflectionException("Property " + propertyName + " could not be accessed by reflection");
}