Pessoal, estou criando uma annotation básica aqui. da seguinte forma:
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
public @ interface ValidateRange {
public int max();
public int min();
}
e o método pra validar é :
public void validate(Object o) throws Exception{
Class classe = o.getClass();
Field[] fields = classe.getDeclaredFields();
for(Field f : fields){
if(f.isAnnotationPresent(ValidateRange.class)){
f.setAccessible(true);
if(f.get(o).toString().length() > CAMPO_MAX_DA_ANNOTATION)
throw new Exception("Campo "+f.getName()+“bla bla bla”);
}
}
}
Eis o problema, nao consigo pegar o CAMPO_MAX_DA_ANNOTATION, ou seja, os atributos da annotation, pra poder manipulá-los dentro do validate, alguém poderia me ajudar?
abraço.