コード例 #1
0
 public static void checkObject(Object data, Class<?> outType, Checkable checkable)
     throws CheckableDataException {
   checkIsNull(data, checkable);
   if (outType.isArray()) {
     checkArray((Object[]) data, outType, checkable);
   } else if (outType == Date.class || StringUtils.isNotEmpty(checkable.dateFormat())) {
     checkDate(ConvertUtil.toString(data), checkable);
   } else if (outType == String.class) {
     checkString(ConvertUtil.toString(data), checkable);
   } else if (outType == Double.class || outType == double.class) {
     checkDouble(ConvertUtil.toString(data), checkable);
   } else if (outType == Float.class || outType == float.class) {
     checkFloat(ConvertUtil.toString(data), checkable);
   } else if (outType == Integer.class || outType == int.class) {
     checkInteger(ConvertUtil.toString(data), checkable);
   } else if (!ClassUtil.isJavaType(outType)) {
     Field[] fields = outType.getDeclaredFields();
     for (int i = 0; i < fields.length; i++) {
       if (fields[i].isAnnotationPresent(Checkable.class)) {
         Checkable tmpCheckable = fields[i].getAnnotation(Checkable.class);
         try {
           fields[i].setAccessible(true);
           Object fieldValue = fields[i].get(data);
           fields[i].setAccessible(false);
           checkObject(fieldValue, fields[i].getType(), tmpCheckable);
         } catch (Exception e) {
           throw new CheckableDataException(e.getMessage(), e);
         }
       }
     }
   }
 }
コード例 #2
0
 public static void checkObjects(
     Object[] parameters, Class<?>[] outTypes, Annotation[][] annotations)
     throws CheckableDataException {
   if (parameters != null) {
     for (int i = 0; i < parameters.length; i++) {
       Annotation tmpAnnotation = ClassUtil.getAnnotation(annotations[i], Checkable.class);
       if (tmpAnnotation != null) {
         checkObject(parameters[i], outTypes[i], (Checkable) tmpAnnotation);
       }
     }
   }
 }
コード例 #3
0
ファイル: ClassUtil.java プロジェクト: noRelax/hfjyframework
 public static Map<String, Field> getClassAllFields(Class<?> classInfo) {
   Class<?> tmpClass = classInfo;
   if (!tmpClass.isInterface() && !ClassUtil.isJavaType(tmpClass)) {
     Map<String, Field> fieldMap = new HashMap<>();
     do {
       Field[] fields = tmpClass.getDeclaredFields();
       for (int f = 0; f < fields.length; f++) {
         fieldMap.put(fields[f].getName(), fields[f]);
       }
     } while ((tmpClass = tmpClass.getSuperclass()) != Object.class);
     return fieldMap;
   }
   return null;
 }