示例#1
0
 public static Object getFieldValue(Object target, String name, boolean strict) {
   Class<?> type = target.getClass();
   try {
     Field field = type.getField(name);
     return getFieldValue(field, target, strict);
   } catch (NoSuchFieldException e) {
     if (strict) throw ExceptionMapper.configurationException(e, type.getName() + '.' + name);
     else {
       escalator.escalate("Class '" + type + "' does not have a field '" + name + "'", type, name);
       return null;
     }
   }
 }
示例#2
0
 /**
  * Creates an instance of the class using the default constructor.
  *
  * @since 0.2.06
  */
 @SuppressWarnings("cast")
 private static <T> T newInstanceFromDefaultConstructor(Class<T> type) {
   if (type == null) return null;
   if (logger.isDebugEnabled()) logger.debug("Instantiating " + type.getSimpleName());
   if (deprecated(type))
     escalator.escalate(
         "Instantiating a deprecated class: " + type.getName(), BeanUtil.class, null);
   try {
     return (T) type.newInstance();
   } catch (InstantiationException e) {
     throw ExceptionMapper.configurationException(e, type);
   } catch (IllegalAccessException e) {
     throw ExceptionMapper.configurationException(e, type);
   }
 }
示例#3
0
 public static <T> T newInstance(
     Constructor<T> constructor, boolean strict, Object... parameters) {
   if (!strict) parameters = convertArray(parameters, constructor.getParameterTypes());
   Class<T> type = constructor.getDeclaringClass();
   if (deprecated(type))
     escalator.escalate(
         "Instantiating a deprecated class: " + type.getName(), BeanUtil.class, null);
   try {
     return constructor.newInstance(parameters);
   } catch (InstantiationException e) {
     throw ExceptionMapper.configurationException(e, type);
   } catch (IllegalAccessException e) {
     throw ExceptionMapper.configurationException(e, type);
   } catch (InvocationTargetException e) {
     throw ExceptionMapper.configurationException(e, type);
   }
 }