com.emarsys.ecommon.builder
Class Builders

java.lang.Object
  extended by com.emarsys.ecommon.builder.Builders

public final class Builders
extends java.lang.Object

The central "registry" for Builders.

Builders defines which Builder is responsible to create a new default instance of a specific type.
Builders are registered with their correspoding types by using set(Class, Builder) and queried with get(Class).
There should be a default Builder defined in defaultBuilders for every type that is to be created with the Builders framework.
Changes to the default config can be done 'manually' in the code by calling set(Class, Builder) or by setting the appropriate System-Properties, namely: <buildee-class-name>.builder=<builder-class-name>

Note that Builders are not intended to provide yet another dependency injection mechanism but in the first line are an attempt to fix some of the shortcomings of third party classes such as those in the JDK without introducing to many depencies on applications or systems based on the ecommon library.

Author:
Michael "kULO" Kulovits


Field Summary
static java.util.Map<java.lang.String,java.lang.String> defaultBuilders
          The default Builders.
static boolean isTestModeEnabled
          Indicates whether the Builders are in testing mode or not, i.e.
static java.lang.String PROP_TESTMODE_ENABLED
          System property key that indicates whether the Builders are in testing mode, i.e.
 
Constructor Summary
Builders()
           
 
Method Summary
static boolean contain(java.lang.Class<?> clazz)
           
static
<T> Builder<T>
get(java.lang.Class<T> clazz)
           Retrieves the Builder associated with the passed buildee Class.
static void reset()
          Resets the Builders to its apriori state after the class has been loaded.
static
<T> void
set(java.lang.Class<T> clazz, Builder<T> builder)
           Registers a new Builder for the passed Class.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

defaultBuilders

public static final java.util.Map<java.lang.String,java.lang.String> defaultBuilders
The default Builders.


PROP_TESTMODE_ENABLED

public static final java.lang.String PROP_TESTMODE_ENABLED
System property key that indicates whether the Builders are in testing mode, i.e. resettable.

See Also:
Constant Field Values

isTestModeEnabled

public static final boolean isTestModeEnabled
Indicates whether the Builders are in testing mode or not, i.e. whether the registry is resettable or not.

Constructor Detail

Builders

public Builders()
Method Detail

set

public static <T> void set(java.lang.Class<T> clazz,
                           Builder<T> builder)
                throws BuilderException,
                       java.lang.IllegalArgumentException

Registers a new Builder for the passed Class.

If the buildee Class is already associated with a Builder instance then a BuilderException will be raised.
Note that this will also happen if the passed Builder is equal or identical to the already existing one in order to strongly discourage the setting of builders outside of the "controlled" boot process of the application/system.

Type Parameters:
T -
Parameters:
clazz - - the buildee's class
builder - - the builder which should be responsible for creating clazz instances
Throws:
BuilderException - - if the passed Class is already associated with an existing Builder
java.lang.IllegalArgumentException - - if the passed Class or Builder is null

get

public static <T> Builder<T> get(java.lang.Class<T> clazz)

Retrieves the Builder associated with the passed buildee Class.

If no Builder is registered with the passed buildee Class in the registry then the defaultBuilders will be queried and if present the default builder will be registered with the passed class immediately.
If no builder at all was for the passed class then a NoSuchBuilderException will be raised.

Type Parameters:
T - - the concrete type of the buildee class
Parameters:
clazz - - the class of the instances that are to be built by the requested builder
Returns:
always a valid Builder instance for the passed buildee Class, never null.

contain

public static boolean contain(java.lang.Class<?> clazz)
Parameters:
clazz -

reset

public static void reset()
                  throws BuilderException
Resets the Builders to its apriori state after the class has been loaded. This is only possible if

Throws:
BuilderException


Copyright © 2010 emarsys AG. All Rights Reserved.