|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.emarsys.ecommon.builder.Builders
public final class Builders
The central "registry" for Builder
s.
Builders
defines which Builder
is responsible to
create a new default instance of a specific type.
Builder
s 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.
Field Summary | |
---|---|
static java.util.Map<java.lang.String,java.lang.String> |
defaultBuilders
The default Builder s. |
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
|
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
|
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 |
---|
public static final java.util.Map<java.lang.String,java.lang.String> defaultBuilders
Builder
s.
public static final java.lang.String PROP_TESTMODE_ENABLED
System property
key that indicates
whether the Builders
are in testing mode, i.e. resettable.
public static final boolean isTestModeEnabled
Builders
are in testing mode
or not, i.e. whether the registry is resettable or not.
Constructor Detail |
---|
public Builders()
Method Detail |
---|
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.
T
- clazz
- - the buildee's classbuilder
- - the builder which should be responsible
for creating clazz instances
BuilderException
- -
if the passed Class
is already associated
with an existing Builder
java.lang.IllegalArgumentException
- -
if the passed Class
or Builder
is
null
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.
T
- - the concrete type of the buildee classclazz
- - the class of the instances that are to be built by
the requested builder
Builder
instance for the passed
buildee Class
, never null
.public static boolean contain(java.lang.Class<?> clazz)
clazz
- public static void reset() throws BuilderException
Builders
to its apriori state after the
class has been loaded.
This is only possible if
BuilderException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |