org.nuiton.util.beans
Class BinderFactory

java.lang.Object
  extended by 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 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 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:
tchemit

Nested Class Summary
static class BinderFactory.BindelModelEntryMap
           
static class BinderFactory.BinderModelEntry
          Definition of an binder model entry (source and target types + context name).
 
Field Summary
protected static BinderFactory.BindelModelEntryMap binderModels
          Cache of registred binders indexed by their unique entry
 
Constructor Summary
BinderFactory()
           
 
Method Summary
static void clear()
          Clear the cache of registred binder models.
protected static BinderFactory.BindelModelEntryMap getBinderModels()
           
static
<S,T> Binder.BinderModel<S,T>
getCachedBinderModel(Class<S> sourceType, Class<T> targetType, String contextName)
          Obtain a cached binder model.
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.
static
<S> Binder<S,S>
newBinder(Class<S> sourceType)
          Gets the registred mirror binder (source type = target type) with no context name specified.
static
<S,T> Binder<S,T>
newBinder(Class<S> sourceType, Class<T> targetType)
          Gets the registred binder given his types with no context name.
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.
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.
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.
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.
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, 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, 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, String contextName)
           
protected static String toString(Binder.BinderModel<?,?> model, String contextName)
           
protected static String toString(Class<?> sourceType, Class<?> targetType, String contextName)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

binderModels

protected static BinderFactory.BindelModelEntryMap binderModels
Cache of registred binders indexed by their unique entry

Constructor Detail

BinderFactory

public BinderFactory()
Method Detail

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
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

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
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.


Copyright © 2004-2010 CodeLutin. All Rights Reserved.