UIRepresentationUtil

public final class UIRepresentationUtil

The UiRepresentationUtil class provides a mechanism for finding methods with the org.motechproject.mds.annotations.UIRepresentation and invoke the method with the annotation to provide a UIRepresentation string for an entity instance.

Methods

uiRepresentationString

public static String uiRepresentationString(Object instance)

Looks for a method annotated UIRepresentation in the provided instance and invokes it in order to fetch the String representation, provided by the annotated method. This method is null-safe and will return empty string for null inputs. This method will return null if the contract for this method is not fulfilled. This method expects that:

  • There’s exactly one method annotated UIRepresentation in the provided instance object
  • The annotated method returns String
  • The annotated method does not take any parameters

If the contract is fulfilled, the annotated method of the instance is invoked and the result of the annotated method is returned by this method.

Parameters:
  • instance – an instance for which we wish to get UI String representation
Returns:

UI representation of the provided instance, as returned by the method annotated UIRepresentation, null if provided instance does not fulfill this method’s contract or empty string if the instance passed to this method is null