Package org.nuiton.util.beans
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 thenewBinder(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 methodregisterBinderModel(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 classBinderFactory.BindelModelEntryMapstatic classBinderFactory.BinderModelEntryDefinition of an binder model entry (source and target types + context name). -
Field Summary
Fields Modifier and Type Field Description protected static BinderFactory.BindelModelEntryMapbinderModelsCache of registred binders indexed by their unique entry -
Constructor Summary
Constructors Constructor Description BinderFactory() -
Method Summary
Modifier and Type Method Description static voidclear()Clear the cache of registred binder models.protected static BinderFactory.BindelModelEntryMapgetBinderModels()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> booleanisBinderModelExists(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>>
BnewBinder(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>>
BnewBinder(Binder.BinderModel<S,T> model, java.lang.Class<B> binderType)Given amodeland abinderType, 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.StringtoString(java.lang.Class<?> sourceType, java.lang.Class<?> targetType, java.lang.String contextName)protected static java.lang.StringtoString(Binder.BinderModel<?,?> model, java.lang.String contextName)
-
Field Details
-
binderModels
Cache of registred binders indexed by their unique entry
-
-
Constructor Details
-
BinderFactory
public BinderFactory()
-
-
Method Details
-
newBinder
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
nullif 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 targetcontextName- the context's name of the searched binder- Returns:
- the registred binder or
nullif 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 sourceT- the type of target- Parameters:
sourceType- the type of sourcetargetType- the type of target- Returns:
- the registred binder or
nullif 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 sourceT- the type of target- Parameters:
sourceType- the type of sourcetargetType- the type of targetcontextName- the context's name of the searched binder- Returns:
- the registred binder or
nullif 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 sourceT- the type of targetB- the type of binder- Parameters:
sourceType- the type of sourcetargetType- the type of targetcontextName- the context's name of the searched binderbinderType- 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 amodeland abinderType, 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 theregisterBinderModel(XXX)method.- Type Parameters:
S- the source typeT- the target typeB- the type of the binder- Parameters:
model- the model used by the binderbinderType- 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 sourceT- the type of target- Parameters:
sourceType- the type of sourcetargetType- the type of targetcontextName- the context's name of the searched binder- Returns:
trueif there is a cached binder model for the given parameters,falseotherwise.
-
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 sourceT- the type of target- Parameters:
sourceType- the type of sourcetargetType- the type of targetcontextName- the context's name of the searched binder- Returns:
- the cached binder model or
nullif not found.
-
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 theBinderModelBuilder.newDefaultBuilder(Class, Class)method).- Type Parameters:
S- the type of sourceT- the type of targetB- the type of binder- Parameters:
sourceType- the type of sourcetargetType- the type of targetcontextName- the context's name of the searched binderbinderType- type of binder required- Returns:
- the new instanciated binder.
-