Class BinderFactory

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

public class BinderFactory
extends java.lang.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
  • Nested Class Summary

    Nested Classes 
    Modifier and Type Class Description
    static class  BinderFactory.BindelModelEntryMap  
    static class  BinderFactory.BinderModelEntry
    Definition of an binder model entry (source and target types + context name).
  • Field Summary

    Fields 
    Modifier and Type Field Description
    protected static BinderFactory.BindelModelEntryMap binderModels
    Cache of registred binders indexed by their unique entry
  • Constructor Summary

    Constructors 
    Constructor Description
    BinderFactory()  
  • Method Summary

    Modifier and Type Method Description
    static void clear()
    Clear the cache of registred binder models.
    protected static BinderFactory.BindelModelEntryMap getBinderModels()  
    static <S,​ T> Binder.BinderModel<S,​T> getCachedBinderModel​(java.lang.Class<S> sourceType, java.lang.Class<T> targetType, java.lang.String contextName)
    Obtain a cached binder model.
    static <S,​ T> boolean isBinderModelExists​(java.lang.Class<S> sourceType, java.lang.Class<T> targetType, java.lang.String contextName)
    Tells if there is a cached binder model for the given parameters.
    static <S> Binder<S,​S> newBinder​(java.lang.Class<S> sourceType)
    Gets the registred mirror binder (source type = target type) with no context name specified.
    static <S,​ T> Binder<S,​T> newBinder​(java.lang.Class<S> sourceType, java.lang.Class<T> targetType)
    Gets the registred binder given his types with no context name.
    static <S,​ T> Binder<S,​T> newBinder​(java.lang.Class<S> sourceType, java.lang.Class<T> targetType, java.lang.String contextName)
    Gets the registred binder given his types with no context name.
    static <S,​ T,​ B extends Binder<S,​ T>>
    B
    newBinder​(java.lang.Class<S> sourceType, java.lang.Class<T> targetType, java.lang.String contextName, java.lang.Class<B> binderType)
    Gets the registred binder given his types and his context's name.
    static <S> Binder<S,​S> newBinder​(java.lang.Class<S> sourceType, java.lang.String contextName)
    Gets the registred mirror binder (source type = target type) with the given context name.
    static <S,​ T,​ B extends Binder<S,​ T>>
    B
    newBinder​(Binder.BinderModel<S,​T> model, java.lang.Class<B> binderType)
    Given a model and a binderType, instanciate a new binder and returns it.
    protected static <S,​ T,​ B extends Binder<S,​ T>>
    Binder<S,​T>
    newBinder0​(java.lang.Class<S> sourceType, java.lang.Class<T> targetType, java.lang.String contextName, java.lang.Class<B> binderType)
    Instanciate a new binder given his types and his context's name.
    static <S,​ T> Binder.BinderModel<S,​T> registerBinderModel​(Binder.BinderModel<S,​T> model)  
    static <S,​ T> Binder.BinderModel<S,​T> registerBinderModel​(Binder.BinderModel<S,​T> model, java.lang.String contextName)  
    static <S,​ T> Binder.BinderModel<S,​T> registerBinderModel​(Binder<S,​T> binder)  
    static <S,​ T> Binder.BinderModel<S,​T> registerBinderModel​(Binder<S,​T> binder, java.lang.String contextName)  
    static <S,​ T> Binder.BinderModel<S,​T> registerBinderModel​(BinderModelBuilder<S,​T> binderModelBuilder)  
    static <S,​ T> Binder.BinderModel<S,​T> registerBinderModel​(BinderModelBuilder<S,​T> binderModelBuilder, java.lang.String contextName)  
    protected static java.lang.String toString​(java.lang.Class<?> sourceType, java.lang.Class<?> targetType, java.lang.String contextName)  
    protected static java.lang.String toString​(Binder.BinderModel<?,​?> model, java.lang.String contextName)  

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Constructor Details

  • Method Details

    • newBinder

      public static <S> Binder<S,​S> newBinder​(java.lang.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​(java.lang.Class<S> sourceType, java.lang.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​(java.lang.Class<S> sourceType, java.lang.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​(java.lang.Class<S> sourceType, java.lang.Class<T> targetType, java.lang.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​(java.lang.Class<S> sourceType, java.lang.Class<T> targetType, java.lang.String contextName, java.lang.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 java.lang.IllegalArgumentException
      Throws:
      java.lang.IllegalArgumentException
    • registerBinderModel

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

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

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

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

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

      public static <S,​ T,​ B extends Binder<S,​ T>> B newBinder​(Binder.BinderModel<S,​T> model, java.lang.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​(java.lang.Class<S> sourceType, java.lang.Class<T> targetType, java.lang.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​(java.lang.Class<S> sourceType, java.lang.Class<T> targetType, java.lang.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 java.lang.String toString​(Binder.BinderModel<?,​?> model, java.lang.String contextName)
    • toString

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

      protected static <S,​ T,​ B extends Binder<S,​ T>> Binder<S,​T> newBinder0​(java.lang.Class<S> sourceType, java.lang.Class<T> targetType, java.lang.String contextName, java.lang.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.