org.nuiton.util.beans
Class BinderProvider

java.lang.Object
  extended by org.nuiton.util.beans.BinderProvider

public class BinderProvider
extends Object

Manage a cache of Binder objects.

You must first register some binders via the registerBinder api.

 Binder mybinder = ...;
 registerBinder(myNewBinder);
 
To use several binders of the the same types, you can moreover specify a context name of your binder :
 Binder mybinder = ...;
 registerBinder(myBinder, "One");
 

Then you can obtained them back via the api

 Binder mybinder =  getBinder(User.class,UserDTO);
 

or with a context name :

 Binder mybinder =  getBinder(User.class,UserDTO.class, "One");
 

Since:
1.1.5
Author:
tchemit
See Also:
Binder, BinderBuilder

Nested Class Summary
static class BinderProvider.BinderEntry
          Definition of an binder entry (source and target types + context name).
 
Field Summary
protected static Map<BinderProvider.BinderEntry,Binder> binders
          Cache of registred binders indexed by their unique entry
 
Constructor Summary
BinderProvider()
           
 
Method Summary
static void clear()
           
static
<S> Binder<S,S>
getBinder(Class<S> sourceType)
          Gets the registred mirror binder (source type = target type) with no context name specified.
static
<S,T> Binder<S,T>
getBinder(Class<S> sourceType, Class<T> targetType)
          Gets the registred binder given his types with no context name.
static
<S,T> Binder<S,T>
getBinder(Class<S> sourceType, Class<T> targetType, String name)
          Gets the registred binder given his types and his context's name.
static
<S> Binder<S,S>
getBinder(Class<S> sourceType, String name)
          Gets the registred mirror binder (source type = target type) with the given context name.
protected static Map<BinderProvider.BinderEntry,Binder> getBinders()
           
static void registerBinder(Binder<?,?> binder)
          Register a binder with no context name.
static void registerBinder(Binder<?,?> binder, String name)
          Register a binder with a context name.
static
<B extends Binder>
void
registerBinder(BinderBuilder builder)
          Register a binder with no context's name from a BinderBuilder.
static
<B extends Binder>
void
registerBinder(BinderBuilder builder, Class<B> binderType)
          Register a binder with no context's name from a BinderBuilder.
static
<B extends Binder>
void
registerBinder(BinderBuilder builder, Class<B> binderType, String name)
          Register a binder with a context's name from a BinderBuilder.
static
<B extends Binder>
void
registerBinder(BinderBuilder builder, String name)
          Register a binder with a context's name from a BinderBuilder.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

binders

protected static Map<BinderProvider.BinderEntry,Binder> binders
Cache of registred binders indexed by their unique entry

Constructor Detail

BinderProvider

public BinderProvider()
Method Detail

getBinder

public static <S> Binder<S,S> getBinder(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.

getBinder

public static <S> Binder<S,S> getBinder(Class<S> sourceType,
                                        String name)
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
name - the context's name of the searched binder
Returns:
the registred binder or null if not found.

getBinder

public static <S,T> Binder<S,T> getBinder(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.

getBinder

public static <S,T> Binder<S,T> getBinder(Class<S> sourceType,
                                          Class<T> targetType,
                                          String name)
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
name - the context's name of the searched binder
Returns:
the registred binder or null if not found.

registerBinder

public static void registerBinder(Binder<?,?> binder)
Register a binder with no context name.

Note: If a previous binder with same definition exists, it will be overriden by the new binder.

Parameters:
binder - the binder to register.

registerBinder

public static <B extends Binder> void registerBinder(BinderBuilder builder)
Register a binder with no context's name from a BinderBuilder.

Note: If a previous binder with same definition exists, it will be overriden by the new binder.

Parameters:
builder - the builder which contains builder model to use
See Also:
BinderBuilder.createBinder(Class)

registerBinder

public static <B extends Binder> void registerBinder(BinderBuilder builder,
                                                     Class<B> binderType)
Register a binder with no context's name from a BinderBuilder.

Note: If a previous binder with same definition exists, it will be overriden by the new binder.

Parameters:
builder - the builder which contains builder model to use
binderType - the type of binder to instanciate and register.
See Also:
BinderBuilder.createBinder(Class)

registerBinder

public static <B extends Binder> void registerBinder(BinderBuilder builder,
                                                     String name)
Register a binder with a context's name from a BinderBuilder.

Note: If a previous binder with same definition exists, it will be overriden by the new binder.

Parameters:
builder - the builder which contains builder model to use
name - the context's name
See Also:
BinderBuilder.createBinder(Class)

registerBinder

public static <B extends Binder> void registerBinder(BinderBuilder builder,
                                                     Class<B> binderType,
                                                     String name)
Register a binder with a context's name from a BinderBuilder.

Note: If a previous binder with same definition exists, it will be overriden by the new binder.

Parameters:
builder - the builder which contains builder model to use
binderType - the type of binder to instanciate and register.
name - the context's name
See Also:
BinderBuilder.createBinder(Class)

registerBinder

public static void registerBinder(Binder<?,?> binder,
                                  String name)
Register a binder with a context name.

Note: If a previous binder with same definition exists, it will be overriden by the new binder.

Parameters:
binder - the binder to register.
name - the context's name

getBinders

protected static Map<BinderProvider.BinderEntry,Binder> getBinders()

clear

public static void clear()


Copyright © 2004-2010 CodeLutin. All Rights Reserved.