示例#1
0
 /**
  * Returns newly created class instance.
  *
  * @param theClass class to process
  * @param arguments class constructor arguments
  * @return newly created class instance
  */
 public static <T> T createInstanceSafely(final Class theClass, final Object... arguments) {
   try {
     return createInstance(theClass, arguments);
   } catch (final Throwable e) {
     if (safeMethodsLoggingEnabled) {
       FlatLafLogger.warn("ReflectionUtils method failed: createInstanceSafely", e);
     }
     return null;
   }
 }
示例#2
0
 /**
  * Returns specified class field's type. This method will also look for the field in super-classes
  * if any exist.
  *
  * @param classType type of the class where field can be located
  * @param fieldName field name
  * @return specified class field's type
  */
 public static Class<?> getFieldTypeSafely(final Class classType, final String fieldName) {
   try {
     return getFieldType(classType, fieldName);
   } catch (final NoSuchFieldException e) {
     if (safeMethodsLoggingEnabled) {
       FlatLafLogger.warn("ReflectionUtils method failed: getFieldTypeSafely", e);
     }
     return null;
   }
 }
示例#3
0
 /**
  * Returns class for the specified canonical name.
  *
  * @param canonicalName class canonical name
  * @return class for the specified canonical name
  */
 public static Class getClassSafely(final String canonicalName) {
   try {
     return Class.forName(canonicalName);
   } catch (final ClassNotFoundException e) {
     if (safeMethodsLoggingEnabled) {
       FlatLafLogger.warn("ReflectionUtils method failed: getClassSafely", e);
     }
     return null;
   }
 }
示例#4
0
 /**
  * Returns static field value from the specified class.
  *
  * @param classType class type
  * @param fieldName class field name
  * @return static field value from the specified class
  */
 public static <T> T getStaticFieldValueSafely(final Class classType, final String fieldName) {
   try {
     return getStaticFieldValue(classType, fieldName);
   } catch (final Throwable e) {
     if (safeMethodsLoggingEnabled) {
       FlatLafLogger.warn("ReflectionUtils method failed: getStaticFieldValueSafely", e);
     }
     return null;
   }
 }
示例#5
0
 /**
  * Returns object field value. This method allows to access even private object fields.
  *
  * @param object object instance
  * @param field object field
  * @param <T> field value type
  * @return object field value
  */
 public static <T> T getFieldValueSafely(final Object object, final String field) {
   try {
     return getFieldValue(object, field);
   } catch (final Throwable e) {
     if (safeMethodsLoggingEnabled) {
       FlatLafLogger.warn("ReflectionUtils method failed: getFieldValueSafely", e);
     }
     return null;
   }
 }
示例#6
0
 /**
  * Returns result given by called method.
  *
  * @param object object instance
  * @param methodName method name
  * @param arguments method arguments
  * @return result given by called method
  */
 public static <T> T callMethodSafely(
     final Object object, final String methodName, final Object... arguments) {
   try {
     return callMethod(object, methodName, arguments);
   } catch (final Throwable e) {
     if (safeMethodsLoggingEnabled) {
       FlatLafLogger.warn("ReflectionUtils method failed: callMethodSafely", e);
     }
     return null;
   }
 }
示例#7
0
 /**
  * Returns object's method with the specified name and arguments. If method is not found in the
  * object class all superclasses will be searched for that method.
  *
  * @param aClass object class
  * @param methodName method name
  * @param arguments method arguments
  * @return object's method with the specified name and arguments
  */
 public static Method getMethodSafely(
     final Class aClass, final String methodName, final Object... arguments) {
   try {
     return getMethod(aClass, methodName, arguments);
   } catch (final Throwable e) {
     if (safeMethodsLoggingEnabled) {
       FlatLafLogger.warn("ReflectionUtils method failed: getMethodSafely", e);
     }
     return null;
   }
 }
示例#8
0
 /**
  * Applies specified value to object field. This method allows to access and modify even private
  * object fields.
  *
  * @param object object instance
  * @param field object field
  * @param value field value
  * @return true if value was applied successfully, false otherwise
  */
 public static boolean setFieldValueSafely(
     final Object object, final String field, final Object value) {
   try {
     setFieldValue(object, field, value);
     return true;
   } catch (final Throwable e) {
     if (safeMethodsLoggingEnabled) {
       FlatLafLogger.warn("ReflectionUtils method failed: setFieldValueSafely", e);
     }
     return false;
   }
 }