com.jdroid.javaweb.utils.ReflectionUtils Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jdroid-java-webapp Show documentation
Show all versions of jdroid-java-webapp Show documentation
Jdroid library for Java Web apps
The newest version!
package com.jdroid.javaweb.utils;
import org.apache.commons.beanutils.NestedNullException;
import org.apache.commons.beanutils.PropertyUtils;
import com.jdroid.java.exception.UnexpectedException;
/**
* Reflection related utilities
*/
public abstract class ReflectionUtils extends com.jdroid.java.utils.ReflectionUtils {
/**
* @param The type of the result object
* @param from The object where invoke the property
* @param propertyName The name of the property to invoke
* @return The property value
*/
@SuppressWarnings("unchecked")
public static T getPropertyValue(Object from, String propertyName) {
try {
return (T)PropertyUtils.getNestedProperty(from, propertyName);
} catch (NestedNullException exception) {
// if any the nested objects is null we return null as value
return null;
} catch (Exception ex) {
throw new UnexpectedException("Error getting the property: '" + propertyName + "' of: " + from);
}
}
}