protected ControllerProxy<?, ?> getController(ModelMetadata model)
     throws IncompatibleControllerException {
   Class<?> keyType = model.getKeyField().getType();
   Class<?> modelType = model.getType();
   ControllerProxy<?, ?> crud = getControllerProxy(keyType, modelType);
   if (crud == null) crud = getDynamicController(keyType, modelType, model);
   return crud;
 }
  private F.Either<ControllerProxy, ? extends Result> controllerOrNotFound(final String name) {
    F.Option<ModelMetadata> modelInfo = getModel(name);
    if (!modelInfo.isDefined())
      return F.Either.Right(notFound("Model with name " + name + " not found!"));

    ModelMetadata model = modelInfo.get();

    F.Option<? extends ControllerProxy<?, ?>> crud;
    try {
      crud = getController(model);
    } catch (IncompatibleControllerException e) {
      crud = null;
    }

    if (crud == null || !crud.isDefined())
      return F.Either.Right(notFound("Controller for model " + model.getType() + " not found"));

    ControllerProxy controller = crud.get();
    return F.Either.Left(controller);
  }
 private F.Option<? extends ControllerProxy<?, ?>> getController(ModelMetadata model)
     throws IncompatibleControllerException {
   ControllerProxy<?, ?> crud =
       controllerRegistry.getController(model.getKeyField().getType(), model.getType());
   return crud == null ? F.Option.<ControllerProxy<?, ?>>None() : F.Option.Some(crud);
 }