Class ResponseFactoryRegistry

java.lang.Object
io.github.grumpystuff.grumpyjson.registry.Sealable
io.github.grumpystuff.grumpyrest.response.ResponseFactoryRegistry

public final class ResponseFactoryRegistry extends Sealable
Allows to register ResponseFactorys that provide Response implementations for the response values returned by handlers.

This class does not extend Registry because it does not work with keys reported by its registrables (i.e. response factories), but directly calls all factories and uses the first non-null result.

  • Constructor Details

    • ResponseFactoryRegistry

      public ResponseFactoryRegistry()
      Constructor. This constructor does not register any factories, but the RestApi calling this constructor does.
  • Method Details

    • clear

      public void clear()
      Removes all response factories from this registry. This is useful because the registry that is used by a newly created RestApi contains default response factories, and the code using it might not want to use them.
    • register

      public void register(ResponseFactory factory)
      Registers a response factory to this registry, to be used when converting a response value to a Response.
      Parameters:
      factory - the response factory to register
    • onSeal

      protected void onSeal()
      Overrides:
      onSeal in class Sealable
    • createResponse

      public Response createResponse(RequestCycle requestCycle, Object value)
      Converts a response value to a Response using an appropriate response factory from this registry. If multiple response factories support conversion of that value, then the one registered later takes precedence.
      Parameters:
      requestCycle - the request cycle to create a response for. This is passed in case the response factory wants to do special stuff like look into request properties.
      value - the response value to convert to a Response
      Returns:
      the response