Java Class.getDeclaredAnnotation Examples

Java Class.getDeclaredAnnotation - 2 examples found. These are the top rated real world Java examples of Class.getDeclaredAnnotation extracted from open source projects. You can rate examples to help us improve the quality of examples.
  public DataConverter(Class<T> clazz)
      throws TooManyPrimaryKeys, NotAnnotatedAsTableClassException, PrimaryKeyIsNotColumnException,
          NoPrimaryKeyException {
    if (clazz.getAnnotation(Table.class) == null) {
      throw new NotAnnotatedAsTableClassException();
    } else {
      if (!clazz.getDeclaredAnnotation(Table.class).name().equals("")) {
        tableName = clazz.getDeclaredAnnotation(Table.class).name();
      } else {
        tableName = CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, clazz.getSimpleName());
      }
    }
    fields = new ArrayList<FieldConverter>();
    for (Field field : clazz.getDeclaredFields()) {
      Class<?> type = field.getType();
      Annotation primaryKeyAnnotation = field.getDeclaredAnnotation(PrimaryKey.class),
          columnAnnotation = field.getDeclaredAnnotation(Column.class);

      if (primaryKeyAnnotation != null) {
        if (columnAnnotation == null) {
          throw new PrimaryKeyIsNotColumnException();
        }
        if (primaryKeyField != null) {
          throw new TooManyPrimaryKeys();
        }
        primaryKeyField = field;
      }
      if (columnAnnotation != null) {
        String name = null;
        if (!field.getDeclaredAnnotation(Column.class).name().equals("")) {
          name = field.getDeclaredAnnotation(Column.class).name();
        } else {
          name = CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, field.getName());
        }
        FieldConverter currentFieldConverter = new FieldConverter(name, field);
        fields.add(currentFieldConverter);
        if (field.equals(primaryKeyField)) {
          primaryKeyFieldConverter = currentFieldConverter;
        }
      }
      Annotation[] annotations = field.getDeclaredAnnotations();
      for (Annotation annotation : annotations) {
        annotation.getClass();
      }
    }
    if (primaryKeyField == null) {
      throw new NoPrimaryKeyException();
    }
  }
 /**
  * 根据传入进来的handler对象,获取对象是否被@EBusHandler注解,如果此类被注解,那么需要判断此类中的全局变量
  * 是否有被@EBusField进行注解。如果注解了,需要添加到Ebus中。
  *
  * @param obj
  */
 public static void scanEBus(Object obj) {
   if (obj == null) {
     return;
   }
   EventBus ebs = InstallVertIOService.getVertx().eventBus();
   Class className = obj.getClass();
   Annotation anno = className.getDeclaredAnnotation(EBusHandler.class);
   if (anno != null) {
     Field[] fields = className.getDeclaredFields();
     for (Field field : fields) {
       EBusField ebf = (EBusField) field.getAnnotation(EBusField.class);
       if (ebf != null) {
         String value = ebf.value();
         try {
           ebs.registerHandler(value, (Handler<Message>) field.get(obj));
         } catch (IllegalArgumentException e) {
           // TODO Auto-generated catch block
           e.printStackTrace();
         } catch (IllegalAccessException e) {
           // TODO Auto-generated catch block
           e.printStackTrace();
         }
       }
     }
   }
 }