|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: REQUIRED | OPTIONAL | DETAIL: ELEMENT |
@Target(value=TYPE) @Retention(value=RUNTIME) @Inherited @Documented public @interface Handler
This annotation serves as a general mechanism for providing metadata about a class that serves as
a 'Handler' for another class or classes.
This is generally useful for situations where a Handler class has a method that is only
valid for certain implementations of a given class, but for which it is not desirable to restrict
this method to a given type.
As an example, take Validator
class and implementations.
As currently designed, a Validator takes in an open-ended Object to validate:
public void validate(Object obj, Errors errors)
To provide more context around what type of objects may successfully be passed in here for
validation, a Validator also requires implementation of:
public boolean supports(Class c)
The weakness of this approach is that the classes that this Validator supports are not exposed.
You must first have a class to Validate and check whether it is supported. It would be preferable
if each Validator exposed as class metadata the type of Objects that it was capable of
Validating. Then, via reflection, much more could be determined about the appropriate Validator
for a given object than is currently possible. This is the problem that this annotation aims to
solve.
The use of this method would therefore be as follows:
Optional Element Summary | |
---|---|
int |
order
Provides a means for specifying the relative order of this Handler against another Handler of the same type. |
java.lang.Class<?>[] |
supports
A list of Classes that this Handler can handle. |
public abstract java.lang.Class<?>[] supports
public abstract int order
Date
class, and one handler had an order of 100 and the other had an order of 50, the
consuming code could utilize this information to determine which handler is preferred. By
convention, the handler with the lowest order generally gains precedence.
|
OpenMRS-1.7.x | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: REQUIRED | OPTIONAL | DETAIL: ELEMENT |