Class BinderModelBuilder<S,T>
- Type Parameters:
S- FIXMET- FIXME
public class BinderModelBuilder<S,T>
extends java.lang.Object
Binder.BinderModel.
A such object is designed to build only one model of binder and can not be
used directly to create a new binder, it prepares only the model of a new
binder, which after must be registred in the BinderFactory to obtain
a real Binder.
If you want to create more than one binder model, use each time a new binder builder.
To obtain a new instance of a build please use one of the factories method :
newEmptyBuilder(Class)} to create a binder model with same source and target typenewEmptyBuilder(Class, Class)to create a binder model with a possible different source and target typenewDefaultBuilder(Class)to create a binder model with same source and target type and then fill the model with all matching properties.newDefaultBuilder(Class, Class)to create a binder model with a possible different source and target type and then fill the model with all matching properties.
addSimpleProperties(String...)to add in the binder model simple properties (a simple property is a property present in both source and target type)addProperty(String, String)to add in the binder model a single property (from source type) to be copied to another property (in target type)addProperties(String...)to add in the binder model properties (says here you specify some couple of properties (sourcePropertyName, targetPropertyName) to be added in the binder model)addBinder(String, Binder)to add in the binder model another binder to be used to copy the given simple property (same name in source and target type)addCollectionStrategy(Binder.CollectionStrategy, String...)to specify the strategy to be used to bind some collection some source type to target typeaddCollectionBinder(Binder, String...)to bind a collection: a new collection will be created and all elements of sources will be copy using the given binder.
builder.addSimpleProperties(...).addProperty(...).addBinder(...)Here is an example of how to use the
BinderModelBuilder :
BinderModelBuilder<Bean, Bean> builder = new BinderModelBuilder(Bean.class);
builder.addSimpleProperties("name", "surname");
BinderFactory.registerBinderModel(builder);
Binder<Bean, Bean> binder = BinderFactory.getBinder(BeanA.class);
Once the binder is registred into the BinderFactory, you can get it
each time you need it :
Binder<Bean, Bean> binder = BinderFactory.getBinder(Bean.class);
- Since:
- 1.5.3
- Author:
- Tony Chemit - chemit@codelutin.com
- See Also:
Binder.BinderModel,Binder
-
Field Summary
Fields Modifier and Type Field Description protected booleancanTypeMismatchCan the source and target type mismatch for a property ?protected Binder.BinderModel<S,T>modelcurrent model used to build the binderprotected java.util.Map<java.lang.String,java.beans.PropertyDescriptor>sourceDescriptorssource properties descriptorsprotected java.util.Map<java.lang.String,java.beans.PropertyDescriptor>targetDescriptorstarget properties descriptors -
Constructor Summary
Constructors Modifier Constructor Description protectedBinderModelBuilder(java.lang.Class<S> sourceType, java.lang.Class<T> targetType)Creates a binder for the given types. -
Method Summary
Modifier and Type Method Description BinderModelBuilder<S,T>addBinder(java.lang.String propertyName, Binder<?,?> binder)BinderModelBuilder<S,T>addCollectionBinder(Binder binder, java.lang.String... propertyNames)BinderModelBuilder<S,T>addCollectionStrategy(Binder.CollectionStrategy strategy, java.lang.String... propertyNames)protected BinderModelBuilder<S,T>addCollectionStrategy0(java.lang.String propertyName, Binder.CollectionStrategy strategy, Binder binder)<K, V> BinderModelBuilder<S,T>addFunction(java.lang.Class<K> type, com.google.common.base.Function<K,V> function)BinderModelBuilder<S,T>addProperties(java.lang.String... sourceAndTargetProperties)Add to the binder model some properties.BinderModelBuilder<S,T>addProperty(java.lang.String sourceProperty, java.lang.String targetProperty)Add to the binder model some simple properties (says source property name = target property name).protected voidaddProperty0(java.lang.String sourceProperty, java.lang.String targetProperty)BinderModelBuilder<S,T>addSimpleProperties(java.lang.String... properties)Add to the binder model some simple properties (says source property name = target property name).BinderModelBuilder<T,S>buildInverseModelBuilder()Creates a new model builder inversing the the source and target of this builder.BinderModelBuilder<S,T>canTypeMismatch(boolean canTypeMismatch)Change the value of propertycanTypeMismatch.protected voidclear()protected Binder.BinderModel<S,T>getModel()protected static voidloadDescriptors(java.lang.Class<?> type, java.util.Map<java.lang.String,java.beans.PropertyDescriptor> descriptors)static <S> BinderModelBuilder<S,S>newDefaultBuilder(java.lang.Class<S> sourceType)Creates a new mirrored model builder and fill the model with all matching and available property from the given type.static <S, T> BinderModelBuilder<S,T>newDefaultBuilder(java.lang.Class<S> sourceType, java.lang.Class<T> targetType)Creates a new model builder and fill the model with all matching and available properties from the source type to the target type.static <S, T> BinderModelBuilder<S,T>newDefaultBuilder(java.lang.Class<S> sourceType, java.lang.Class<T> targetType, boolean checkType)Creates a new model builder and fill the model with all matching and available properties from the source type to the target type.static <S> BinderModelBuilder<S,S>newEmptyBuilder(java.lang.Class<S> type)Creates a new mirrored and empty model binder for the giventype.static <S, T> BinderModelBuilder<S,T>newEmptyBuilder(java.lang.Class<S> sourceType, java.lang.Class<T> targetType)Creates a new empty model binder for the given types.voidsetInstanceFactory(InstanceFactory<T> instanceFactory)set factory of target instanceBinder<S,T>toBinder()<B extends Binder<S, T>>
BtoBinder(java.lang.Class<B> binderType)
-
Field Details
-
canTypeMismatch
protected boolean canTypeMismatchCan the source and target type mismatch for a property ? -
model
current model used to build the binder -
sourceDescriptors
protected java.util.Map<java.lang.String,java.beans.PropertyDescriptor> sourceDescriptorssource properties descriptors -
targetDescriptors
protected java.util.Map<java.lang.String,java.beans.PropertyDescriptor> targetDescriptorstarget properties descriptors
-
-
Constructor Details
-
BinderModelBuilder
Creates a binder for the given types.- Parameters:
sourceType- type of the source of the bindertargetType- type of the target of the binder
-
-
Method Details
-
newEmptyBuilder
Creates a new mirrored and empty model binder for the giventype.- Type Parameters:
S- FIXME- Parameters:
type- the type of mirrored binder- Returns:
- the new instanciated builder
-
newEmptyBuilder
public static <S, T> BinderModelBuilder<S,T> newEmptyBuilder(java.lang.Class<S> sourceType, java.lang.Class<T> targetType)Creates a new empty model binder for the given types.- Type Parameters:
S- FIXMET- FIXME- Parameters:
sourceType- type of the source of the bindertargetType- type of the target of the binder- Returns:
- the new instanciated builder
-
newDefaultBuilder
Creates a new mirrored model builder and fill the model with all matching and available property from the given type.- Type Parameters:
S- FIXMES- the mirrored type of the binder model to create- Parameters:
sourceType- the mirrored type of the binder model to create- Returns:
- the new instanciated model builder fully filled
-
newDefaultBuilder
public static <S, T> BinderModelBuilder<S,T> newDefaultBuilder(java.lang.Class<S> sourceType, java.lang.Class<T> targetType)Creates a new model builder and fill the model with all matching and available properties from the source type to the target type.- Type Parameters:
S- the source type of the binder model to createT- the target type of the binder model to create- Parameters:
sourceType- the source type of the model to createtargetType- the target type of the model to create- Returns:
- the new instanciated model builder fully filled
-
newDefaultBuilder
public static <S, T> BinderModelBuilder<S,T> newDefaultBuilder(java.lang.Class<S> sourceType, java.lang.Class<T> targetType, boolean checkType)Creates a new model builder and fill the model with all matching and available properties from the source type to the target type.- Type Parameters:
S- the source type of the binder model to createT- the target type of the binder model to create- Parameters:
sourceType- the source type of the model to createtargetType- the target type of the model to createcheckType- flag to check if properties has same types, otherwise skip them- Returns:
- the new instanciated model builder fully filled
- Since:
- 2.4.5
-
canTypeMismatch
Change the value of propertycanTypeMismatch.- Parameters:
canTypeMismatch- newcanTypeMismatchvalue- Returns:
- the builder
-
addFunction
public <K, V> BinderModelBuilder<S,T> addFunction(java.lang.Class<K> type, com.google.common.base.Function<K,V> function) -
toBinder
Convinient method to create directly aBinderusing the underlyingmodelthe builder contains.Note: Using this method will not make reusable the model via the
BinderFactory.- Returns:
- a new binder using the model of the builder.
- Since:
- 2.1
- See Also:
BinderFactory.newBinder(Binder.BinderModel, Class)
-
toBinder
Convinient method to create directly aBinderusing the underlyingmodelthe builder contains.Note: Using this method will not make reusable the model via the
BinderFactory.- Type Parameters:
B- type of binder to create- Parameters:
binderType- type of binder to create- Returns:
- a new binder using the model of the builder.
- Since:
- 2.1
- See Also:
BinderFactory.newBinder(Binder.BinderModel, Class)
-
setInstanceFactory
set factory of target instance- Parameters:
instanceFactory- FIXME
-
addSimpleProperties
public BinderModelBuilder<S,T> addSimpleProperties(java.lang.String... properties) throws java.lang.IllegalStateException, java.lang.NullPointerExceptionAdd to the binder model some simple properties (says source property name = target property name).Note: If no model is present, the method will fail.
- Parameters:
properties- the name of mirrored property- Returns:
- the instance of the builder
- Throws:
java.lang.IllegalStateException- if no model was previously createdjava.lang.NullPointerException- if a property isnull
-
addProperty
public BinderModelBuilder<S,T> addProperty(java.lang.String sourceProperty, java.lang.String targetProperty) throws java.lang.IllegalStateException, java.lang.NullPointerExceptionAdd to the binder model some simple properties (says source property name = target property name).Note: If no model is present, the method will fail.
- Parameters:
sourceProperty- the name of the source property to bindtargetProperty- the name of the target property to bind- Returns:
- the instance of the builder
- Throws:
java.lang.IllegalStateException- if no model was previously createdjava.lang.NullPointerException- if a parameter isnull
-
addProperties
public BinderModelBuilder<S,T> addProperties(java.lang.String... sourceAndTargetProperties) throws java.lang.IllegalStateException, java.lang.IllegalArgumentException, java.lang.NullPointerExceptionAdd to the binder model some properties.Parameter
sourceAndTargetPropertiesmust be a array of couple ofsourceProperty,targetProperty.Example :
builder.addProperties("name","name2","text","text");Note: If no model is present, the method will fail.
- Parameters:
sourceAndTargetProperties- the couple of (sourceProperty - targetProperty) to bind- Returns:
- the instance of the builder
- Throws:
java.lang.IllegalStateException- if no model was previously createdjava.lang.IllegalArgumentException- if there is not the same number of source and target propertiesjava.lang.NullPointerException- if a parameter isnull
-
addBinder
-
addCollectionStrategy
public BinderModelBuilder<S,T> addCollectionStrategy(Binder.CollectionStrategy strategy, java.lang.String... propertyNames) -
addCollectionBinder
public BinderModelBuilder<S,T> addCollectionBinder(Binder binder, java.lang.String... propertyNames) -
buildInverseModelBuilder
Creates a new model builder inversing the the source and target of this builder.the result build will contains the inversed properties mapping of the original builder.
Other builder attributes are not used used
- Returns:
- the new model builder
-
addCollectionStrategy0
protected BinderModelBuilder<S,T> addCollectionStrategy0(java.lang.String propertyName, Binder.CollectionStrategy strategy, Binder binder) -
addProperty0
protected void addProperty0(java.lang.String sourceProperty, java.lang.String targetProperty) -
getModel
-
clear
protected void clear() -
loadDescriptors
protected static void loadDescriptors(java.lang.Class<?> type, java.util.Map<java.lang.String,java.beans.PropertyDescriptor> descriptors)
-