Created
June 22, 2018 19:42
-
-
Save os890/ead4a1fe3e379f04e457c7a717cd082e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@ApplicationScoped | |
public class EnumLabelsResolver implements LabelResolver { | |
@Override | |
public List<String> resolveLabelsFor(ConstraintDescriptor<?> constraintDescriptor) { | |
List<String> result = new ArrayList<>(); | |
for (Method annotationMethod : constraintDescriptor.getAnnotation().annotationType().getDeclaredMethods()) { | |
if (LabelId.class.isAssignableFrom(annotationMethod.getReturnType())) { | |
try { | |
LabelId labelId = (LabelId) annotationMethod.invoke(constraintDescriptor.getAnnotation()); | |
result.add(labelId.getId()); | |
} catch (Exception e) { | |
throw ExceptionUtils.throwAsRuntimeException(e); | |
} | |
} | |
} | |
return result; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@ApplicationScoped | |
public class EnumMessageTemplateResolver implements MessageTemplateResolver { | |
@Override | |
public String resolveMessageTemplateFor(ConstraintDescriptor<?> constraintDescriptor) { | |
for (Method annotationMethod : constraintDescriptor.getAnnotation().annotationType().getDeclaredMethods()) { | |
if (MessageId.class.isAssignableFrom(annotationMethod.getReturnType())) { | |
try { | |
MessageId messageId = (MessageId) annotationMethod.invoke(constraintDescriptor.getAnnotation()); | |
return "{" + messageId.getId() + "}"; | |
} catch (Exception e) { | |
throw ExceptionUtils.throwAsRuntimeException(e); | |
} | |
} | |
} | |
return null; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment