org.nuiton.util.beans
Class BinderModelBuilder<S,T>

java.lang.Object
  extended by org.nuiton.util.beans.BinderModelBuilder<S,T>

public class BinderModelBuilder<S,T>
extends Object

Class to create a new 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 :

Then you can use folowing methods to specify what to put in the copy model : Note : You can chain thoses methods since all of them always return the current instance of the builder :
 builder.addSimpleProperties(...).addProperty(...).addBinder(...)
 

Here is an example of how to use the BinderModelBuilder :

 BinderModelBuilder builder = new BinderModelBuilder(Bean.class);
 builder.addSimpleProperties("name", "surname");
 BinderFactory.registerBinderModel(builder);
 Binder binder = BinderFactory.getBinder(BeanA.class);

 

Once the binder is registred into the BinderFactory, you can get it each time you need it :

 Binder binder = BinderFactory.getBinder(Bean.class);
 

Since:
1.5.3
Author:
tchemit
See Also:
Binder.BinderModel, Binder

Field Summary
protected  Binder.BinderModel<S,T> model
          current model used to build the binder
protected  Map<String,PropertyDescriptor> sourceDescriptors
          source properties descriptors
protected  Map<String,PropertyDescriptor> targetDescriptors
          target properties descriptors
 
Constructor Summary
protected BinderModelBuilder(Class<S> sourceType, Class<T> targetType)
          Creates a binder for the given types.
 
Method Summary
 BinderModelBuilder<S,T> addBinder(String propertyName, Binder<?,?> binder)
           
 BinderModelBuilder<S,T> addCollectionStrategy(Binder.CollectionStrategy strategy, String... propertyNames)
           
 BinderModelBuilder<S,T> addProperties(String... sourceAndTargetProperties)
          Add to the binder model some properties.
 BinderModelBuilder<S,T> addProperty(String sourceProperty, String targetProperty)
          Add to the binder model some simple properties (says source property name = target property name).
protected  void addProperty0(String sourceProperty, String targetProperty)
           
 BinderModelBuilder<S,T> addSimpleProperties(String... properties)
          Add to the binder model some simple properties (says source property name = target property name).
protected  void clear()
           
protected  Binder.BinderModel<S,T> getModel()
           
protected static void loadDescriptors(Class<?> type, Map<String,PropertyDescriptor> descriptors)
           
static
<S> BinderModelBuilder<S,S>
newDefaultBuilder(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(Class<S> sourceType, 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> BinderModelBuilder<S,S>
newEmptyBuilder(Class<S> type)
          Creates a new mirrored and empty model binder for the given type.
static
<S,T> BinderModelBuilder<S,T>
newEmptyBuilder(Class<S> sourceType, Class<T> targetType)
          Creates a new empty model binder for the given types.
 Binder<S,T> toBinder()
          Convinient method to create directly a Binder using the underlying model the builder contains.
<B extends Binder<S,T>>
B
toBinder(Class<B> binderType)
          Convinient method to create directly a Binder using the underlying model the builder contains.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

model

protected Binder.BinderModel<S,T> model
current model used to build the binder


sourceDescriptors

protected Map<String,PropertyDescriptor> sourceDescriptors
source properties descriptors


targetDescriptors

protected Map<String,PropertyDescriptor> targetDescriptors
target properties descriptors

Constructor Detail

BinderModelBuilder

protected BinderModelBuilder(Class<S> sourceType,
                             Class<T> targetType)
Creates a binder for the given types.

Parameters:
sourceType - type of the source of the binder
targetType - type of the target of the binder
Method Detail

newEmptyBuilder

public static <S> BinderModelBuilder<S,S> newEmptyBuilder(Class<S> type)
Creates a new mirrored and empty model binder for the given type.

Parameters:
type - the type of mirrored binder
Returns:
the new instanciated builder

newEmptyBuilder

public static <S,T> BinderModelBuilder<S,T> newEmptyBuilder(Class<S> sourceType,
                                                            Class<T> targetType)
Creates a new empty model binder for the given types.

Parameters:
sourceType - type of the source of the binder
targetType - type of the target of the binder
Returns:
the new instanciated builder

newDefaultBuilder

public static <S> BinderModelBuilder<S,S> newDefaultBuilder(Class<S> sourceType)
Creates a new mirrored model builder and fill the model with all matching and available property from the given type.

Type Parameters:
S - 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(Class<S> sourceType,
                                                              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 create
T - the target type of the binder model to create
Parameters:
sourceType - the source type of the model to create
targetType - the target type of the model to create
Returns:
the new instanciated model builder fully filled

toBinder

public Binder<S,T> toBinder()
Convinient method to create directly a Binder using the underlying model the 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

public <B extends Binder<S,T>> B toBinder(Class<B> binderType)
Convinient method to create directly a Binder using the underlying model the 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)

addSimpleProperties

public BinderModelBuilder<S,T> addSimpleProperties(String... properties)
                                            throws IllegalStateException,
                                                   NullPointerException
Add 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:
IllegalStateException - if no model was previously created
NullPointerException - if a property is null

addProperty

public BinderModelBuilder<S,T> addProperty(String sourceProperty,
                                           String targetProperty)
                                    throws IllegalStateException,
                                           NullPointerException
Add 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 bind
targetProperty - the name of the target property to bind
Returns:
the instance of the builder
Throws:
IllegalStateException - if no model was previously created
NullPointerException - if a parameter is null

addProperties

public BinderModelBuilder<S,T> addProperties(String... sourceAndTargetProperties)
                                      throws IllegalStateException,
                                             IllegalArgumentException,
                                             NullPointerException
Add to the binder model some properties.

Parameter sourceAndTargetProperties must be a array of couple of sourceProperty, 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:
IllegalStateException - if no model was previously created
IllegalArgumentException - if there is not the same number of source and target properties
NullPointerException - if a parameter is null

addBinder

public BinderModelBuilder<S,T> addBinder(String propertyName,
                                         Binder<?,?> binder)

addCollectionStrategy

public BinderModelBuilder<S,T> addCollectionStrategy(Binder.CollectionStrategy strategy,
                                                     String... propertyNames)

addProperty0

protected void addProperty0(String sourceProperty,
                            String targetProperty)

getModel

protected Binder.BinderModel<S,T> getModel()

clear

protected void clear()

loadDescriptors

protected static void loadDescriptors(Class<?> type,
                                      Map<String,PropertyDescriptor> descriptors)


Copyright © 2004-2011 CodeLutin. All Rights Reserved.