Class BinderFactory

java.lang.Object
org.nuiton.util.beans.BinderFactory

public class BinderFactory extends Object
Factory of Binder.

Obtain a new binder

To obtain a new binder you can use the newBinder(XXX) methods. For example to obtain a mirrored binder (same source and target type) which will be able to copy all accepting properties, use this code :
Binder<BeanA, BeanA> binder = BinderFactory.newBinder(BeanA.class);

Usage of contextale binder

It is possible to use different binder for same source and target type, using a extra context name parameter, like this :
Binder<BeanA, BeanA> binder = BinderFactory.newBinder(BeanA.class, "mycontext");
This is usefull when you register your own binder model in the factory (see next section) to bind different things from the same type of objects...

Register a new binder model

To register a new binder's model use one of the method registerBinderModel(XXX). More documentation will come soon, yu can see the package info javadoc or unit tests...
Since:
1.5.3
Author:
Tony Chemit - chemit@codelutin.com
  • Field Details

  • Constructor Details

    • BinderFactory

      public BinderFactory()
  • Method Details

    • newBinder

      public static <S> Binder<S,S> newBinder(Class<S> sourceType)
      Gets the registred mirror binder (source type = target type) with no context name specified.
      Type Parameters:
      S - the type of source and target
      Parameters:
      sourceType - the type of source and target
      Returns:
      the registred binder or null if not found.
    • newBinder

      public static <S> Binder<S,S> newBinder(Class<S> sourceType, String contextName)
      Gets the registred mirror binder (source type = target type) with the given context name.
      Type Parameters:
      S - the type of source and target
      Parameters:
      sourceType - the type of source and target
      contextName - the context's name of the searched binder
      Returns:
      the registred binder or null if not found.
    • newBinder

      public static <S,T> Binder<S,T> newBinder(Class<S> sourceType, Class<T> targetType)
      Gets the registred binder given his types with no context name.
      Type Parameters:
      S - the type of source
      T - the type of target
      Parameters:
      sourceType - the type of source
      targetType - the type of target
      Returns:
      the registred binder or null if not found.
    • newBinder

      public static <S,T> Binder<S,T> newBinder(Class<S> sourceType, Class<T> targetType, String contextName)
      Gets the registred binder given his types with no context name.
      Type Parameters:
      S - the type of source
      T - the type of target
      Parameters:
      sourceType - the type of source
      targetType - the type of target
      contextName - the context's name of the searched binder
      Returns:
      the registred binder or null if not found.
    • newBinder

      public static <S, T, B extends Binder<S,T>> B newBinder(Class<S> sourceType, Class<T> targetType, String contextName, Class<B> binderType)
      Gets the registred binder given his types and his context's name.
      Type Parameters:
      S - the type of source
      T - the type of target
      B - the type of binder
      Parameters:
      sourceType - the type of source
      targetType - the type of target
      contextName - the context's name of the searched binder
      binderType - type of binder required
      Returns:
      the new instanciated binder.
    • registerBinderModel

      public static <S,T> Binder.BinderModel<S,T> registerBinderModel(BinderModelBuilder<S,T> binderModelBuilder) throws IllegalArgumentException
      Throws:
      IllegalArgumentException
    • registerBinderModel

      public static <S,T> Binder.BinderModel<S,T> registerBinderModel(Binder<S,T> binder) throws IllegalArgumentException
      Throws:
      IllegalArgumentException
    • registerBinderModel

      public static <S,T> Binder.BinderModel<S,T> registerBinderModel(Binder.BinderModel<S,T> model) throws IllegalArgumentException
      Throws:
      IllegalArgumentException
    • registerBinderModel

      public static <S,T> Binder.BinderModel<S,T> registerBinderModel(BinderModelBuilder<S,T> binderModelBuilder, String contextName) throws IllegalArgumentException
      Throws:
      IllegalArgumentException
    • registerBinderModel

      public static <S,T> Binder.BinderModel<S,T> registerBinderModel(Binder<S,T> binder, String contextName) throws IllegalArgumentException
      Throws:
      IllegalArgumentException
    • registerBinderModel

      public static <S,T> Binder.BinderModel<S,T> registerBinderModel(Binder.BinderModel<S,T> model, String contextName) throws IllegalArgumentException
      Throws:
      IllegalArgumentException
    • newBinder

      public static <S, T, B extends Binder<S,T>> B newBinder(Binder.BinderModel<S,T> model, Class<B> binderType)
      Given a model and a binderType, instanciate a new binder and returns it. Note: This method will NOT register the model in the factory. If you want to reuse your model, please use one of the registerBinderModel(XXX) method.
      Type Parameters:
      S - the source type
      T - the target type
      B - the type of the binder
      Parameters:
      model - the model used by the binder
      binderType - the type of the binder
      Returns:
      the new instanciated binder
      Since:
      2.1
    • clear

      public static void clear()
      Clear the cache of registred binder models. Note : This is a convienient method for test purposes and should be used in a normal usage of this provider.
    • isBinderModelExists

      public static <S,T> boolean isBinderModelExists(Class<S> sourceType, Class<T> targetType, String contextName)
      Tells if there is a cached binder model for the given parameters.
      Type Parameters:
      S - the type of source
      T - the type of target
      Parameters:
      sourceType - the type of source
      targetType - the type of target
      contextName - the context's name of the searched binder
      Returns:
      true if there is a cached binder model for the given parameters, false otherwise.
    • getCachedBinderModel

      public static <S,T> Binder.BinderModel<S,T> getCachedBinderModel(Class<S> sourceType, Class<T> targetType, String contextName)
      Obtain a cached binder model.
      Type Parameters:
      S - the type of source
      T - the type of target
      Parameters:
      sourceType - the type of source
      targetType - the type of target
      contextName - the context's name of the searched binder
      Returns:
      the cached binder model or null if not found.
    • getBinderModels

      protected static BinderFactory.BindelModelEntryMap getBinderModels()
    • toString

      protected static String toString(Binder.BinderModel<?,?> model, String contextName)
    • toString

      protected static String toString(Class<?> sourceType, Class<?> targetType, String contextName)
    • newBinder0

      protected static <S, T, B extends Binder<S,T>> Binder<S,T> newBinder0(Class<S> sourceType, Class<T> targetType, String contextName, Class<B> binderType)
      Instanciate a new binder given his types and his context's name. If the corresponding binder model does not exist, then it will be created and cached (using the BinderModelBuilder.newDefaultBuilder(Class, Class) method).
      Type Parameters:
      S - the type of source
      T - the type of target
      B - the type of binder
      Parameters:
      sourceType - the type of source
      targetType - the type of target
      contextName - the context's name of the searched binder
      binderType - type of binder required
      Returns:
      the new instanciated binder.