org.openmrs.util
Class HandlerUtil

java.lang.Object
  extended by org.openmrs.util.HandlerUtil

public class HandlerUtil
extends java.lang.Object

Utility class that provides useful methods for working with classes that are annotated with the Handler annotation

Since:
1.5

Constructor Summary
HandlerUtil()
           
 
Method Summary
static
<H,T> java.util.List<H>
getHandlersForType(java.lang.Class<H> handlerType, java.lang.Class<T> type)
          Retrieves a List of all registered components from the Context that are of the passed handlerType and one or more of the following is true: The handlerType is annotated as a Handler that supports the passed type The passed type is null - this effectively returns all components of the passed handlerType The returned handlers are ordered in the list based upon the order property.
static java.lang.Integer getOrderOfHandler(java.lang.Class<?> handlerClass)
          Utility method to return the order attribute of the Handler annotation on the passed class.
static
<H,T> H
getPreferredHandler(java.lang.Class<H> handlerType, java.lang.Class<T> type)
          Retrieves the preferred Handler for a given handlerType and type.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HandlerUtil

public HandlerUtil()
Method Detail

getHandlersForType

public static <H,T> java.util.List<H> getHandlersForType(java.lang.Class<H> handlerType,
                                                         java.lang.Class<T> type)
Retrieves a List of all registered components from the Context that are of the passed handlerType and one or more of the following is true: The returned handlers are ordered in the list based upon the order property.

Parameters:
handlerType - Indicates the type of class to return
type - Indicates the type that the given handlerType must support (or null for any)
Returns:
a List of all matching Handlers for the given parameters, ordered by Handler#order
Expected behavior:
return a list of all classes that can handle the passed type, return classes registered in a module, return an empty list if no classes can handle the passed type

getPreferredHandler

public static <H,T> H getPreferredHandler(java.lang.Class<H> handlerType,
                                          java.lang.Class<T> type)
Retrieves the preferred Handler for a given handlerType and type. A preferred handler is the Handler that has the lowest defined order attribute in it's annotation. If multiple Handlers are found for the passed parameters at the lowest specified order, then an APIException is thrown.

Parameters:
handlerType - the class that is an annotated Handler to retrieve
type - the class that the annotated Handler must support
Returns:
the class of the passed hanlerType with the lowest configured order
Expected behavior:
return the preferred handler for the passed handlerType and type, throw a APIException if no handler is found, throw a APIException if multiple preferred handlers are found

getOrderOfHandler

public static java.lang.Integer getOrderOfHandler(java.lang.Class<?> handlerClass)
Utility method to return the order attribute of the Handler annotation on the passed class. If the passed class does not have a Handler annotation, a RuntimeException is thrown

Parameters:
handlerClass -
Returns:
the order attribute value

OpenMRS-1.7.x

Generated Apr 27 2012 10:06 PM. NOTE - these libraries are in active development and subject to change