Interface BindHandler

All Known Implementing Classes:
AbstractBindHandler, BoundPropertiesTrackingBindHandler, IgnoreErrorsBindHandler, IgnoreTopLevelConverterNotFoundBindHandler, NoUnboundElementsBindHandler, ValidationBindHandler

public interface BindHandler
Callback interface that can be used to handle additional logic during element binding.
Since:
2.0.0
Author:
Phillip Webb, Madhura Bhave
  • Field Details

    • DEFAULT

      static final BindHandler DEFAULT
      Default no-op bind handler.
  • Method Details

    • onStart

      default <T> @Nullable Bindable<T> onStart(ConfigurationPropertyName name, Bindable<T> target, BindContext context)
      Called when binding of an element starts but before any result has been determined.
      Type Parameters:
      T - the bindable source type
      Parameters:
      name - the name of the element being bound
      target - the item being bound
      context - the bind context
      Returns:
      the actual item that should be used for binding (may be null)
    • onSuccess

      default @Nullable Object onSuccess(ConfigurationPropertyName name, Bindable<?> target, BindContext context, Object result)
      Called when binding of an element ends with a successful result. Implementations may change the ultimately returned result or perform addition validation.
      Parameters:
      name - the name of the element being bound
      target - the item being bound
      context - the bind context
      result - the bound result (never null)
      Returns:
      the actual result that should be used (may be null)
    • onCreate

      default Object onCreate(ConfigurationPropertyName name, Bindable<?> target, BindContext context, Object result)
      Called when binding of an element ends with an unbound result and a newly created instance is about to be returned. Implementations may change the ultimately returned result or perform addition validation.
      Parameters:
      name - the name of the element being bound
      target - the item being bound
      context - the bind context
      result - the newly created instance (never null)
      Returns:
      the actual result that should be used (must not be null)
      Since:
      2.2.2
    • onFailure

      default @Nullable Object onFailure(ConfigurationPropertyName name, Bindable<?> target, BindContext context, Exception error) throws Exception
      Called when binding fails for any reason (including failures from onSuccess(ConfigurationPropertyName, Bindable, BindContext, Object) or onCreate(ConfigurationPropertyName, Bindable, BindContext, Object) calls). Implementations may choose to swallow exceptions and return an alternative result.
      Parameters:
      name - the name of the element being bound
      target - the item being bound
      context - the bind context
      error - the cause of the error (if the exception stands it may be re-thrown)
      Returns:
      the actual result that should be used (may be null).
      Throws:
      Exception - if the binding isn't valid
    • onFinish

      default void onFinish(ConfigurationPropertyName name, Bindable<?> target, BindContext context, @Nullable Object result) throws Exception
      Called when binding finishes with either bound or unbound result. This method will not be called when binding failed, even if a handler returns a result from onFailure(ConfigurationPropertyName, Bindable, BindContext, Exception).
      Parameters:
      name - the name of the element being bound
      target - the item being bound
      context - the bind context
      result - the bound result (may be null)
      Throws:
      Exception - if the binding isn't valid