I have an abstract
class that consumers of my library are expected to implement:
public abstract class StatusIndicator {
protected StatusIndicator(Class<? extends StatusIndicator> thisClass) {
if (cl.isAnnotationPresent(StatusOrdering.class)) {
StatusOrdering ord = cl.getAnnotation(StatusOrdering.class);
return ord.value();
}
}
}
This is a sample implementation by a project consuming my library:
@StatusOrdering(7) // Invalid
// @StatusOrdering(1) // Valid
// @StatusOrdering(11) // Valid
public class MyAppStatusIndicator extends StatusIndicator {
public AppStatusIndicator() {
super(AppStatusIndicator.class);
}
}
The StatusOrdering
annotation, which can optionally be added by consumers to their StatusIndicator
implementation class as seen above, looks like this:
@Target({ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
public @interface StatusOrdering {
int value() default 0;
}
Is there any way I can use something like Java Bean Validation to ensure that the value provided to the @StatusOrdering(3)
annotation is a positive number and not between 5 and 10? Ideally during the annotation processing phase so that I dont need to explicitly invoke the framework's validator manually.
I can only modify the source code for the StatusOrdering
annotation and StatusIndicator
abstract
class, I cannot directly modify the application implementation i.e MyAppStatusIndicator