|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.opensymphony.xwork2.inject.ContainerBuilder
public final class ContainerBuilder
Builds a dependency injection Container
. The combination of
dependency type and name uniquely identifies a dependency mapping; you can
use the same name for two different types. Not safe for concurrent use.
Adds the following factories by default:
Nested Class Summary | |
---|---|
static interface |
ContainerBuilder.Command
Implemented by classes which participate in building a container. |
Field Summary | |
---|---|
(package private) boolean |
allowDuplicates
|
private static InternalFactory<Container> |
CONTAINER_FACTORY
|
(package private) boolean |
created
|
(package private) Map<Key<?>,InternalFactory<?>> |
factories
|
private static InternalFactory<Logger> |
LOGGER_FACTORY
|
(package private) List<InternalFactory<?>> |
singletonFactories
|
(package private) List<Class<?>> |
staticInjections
|
Constructor Summary | |
---|---|
ContainerBuilder()
Constructs a new builder. |
Method Summary | ||
---|---|---|
|
alias(Class<T> type,
String alias)
Convenience method. Equivalent to alias(type, Container.DEFAULT_NAME,
type) . |
|
|
alias(Class<T> type,
String name,
String alias)
Maps an existing factory to a new name. |
|
private
|
alias(Key<T> key,
Key<T> aliasKey)
Maps an existing dependency. |
|
private void |
checkKey(Key<?> key)
Ensures a key isn't already mapped. |
|
private
|
constant(Class<T> type,
String name,
T value)
Maps a constant value to the given type and name. |
|
ContainerBuilder |
constant(String name,
boolean value)
Maps a constant value to the given name. |
|
ContainerBuilder |
constant(String name,
char value)
Maps a constant value to the given name. |
|
ContainerBuilder |
constant(String name,
Class value)
Maps a class to the given name. |
|
ContainerBuilder |
constant(String name,
double value)
Maps a constant value to the given name. |
|
|
constant(String name,
E value)
Maps an enum to the given name. |
|
ContainerBuilder |
constant(String name,
float value)
Maps a constant value to the given name. |
|
ContainerBuilder |
constant(String name,
int value)
Maps a constant value to the given name. |
|
ContainerBuilder |
constant(String name,
long value)
Maps a constant value to the given name. |
|
ContainerBuilder |
constant(String name,
short value)
Maps a constant value to the given name. |
|
ContainerBuilder |
constant(String name,
String value)
Maps a constant value to the given name. |
|
boolean |
contains(Class<?> type)
Convenience method. Equivalent to contains(type,
Container.DEFAULT_NAME) . |
|
boolean |
contains(Class<?> type,
String name)
Returns true if this builder contains a mapping for the given type and name. |
|
Container |
create(boolean loadSingletons)
Creates a Container instance. |
|
private void |
ensureNotCreated()
Currently we only support creating one Container instance per builder. |
|
|
factory(Class<T> type)
Convenience method. Equivalent to factory(type,
Container.DEFAULT_NAME, type) . |
|
|
factory(Class<T> type,
Class<? extends T> implementation)
Convenience method. Equivalent to factory(type,
Container.DEFAULT_NAME, implementation) . |
|
|
factory(Class<T> type,
Class<? extends T> implementation,
Scope scope)
Convenience method. Equivalent to factory(type,
Container.DEFAULT_NAME, implementation, scope) . |
|
|
factory(Class<T> type,
Factory<? extends T> factory)
Convenience method. Equivalent to factory(type,
Container.DEFAULT_NAME, factory, Scope.DEFAULT) . |
|
|
factory(Class<T> type,
Factory<? extends T> factory,
Scope scope)
Convenience method. Equivalent to factory(type,
Container.DEFAULT_NAME, factory, scope) . |
|
|
factory(Class<T> type,
Scope scope)
Convenience method. Equivalent to factory(type,
Container.DEFAULT_NAME, type, scope) . |
|
|
factory(Class<T> type,
String name)
Convenience method. Equivalent to factory(type, name, type) . |
|
|
factory(Class<T> type,
String name,
Class<? extends T> implementation)
Maps an implementation class to a given dependency type and name. |
|
|
factory(Class<T> type,
String name,
Class<? extends T> implementation,
Scope scope)
Maps an implementation class to a given dependency type and name. |
|
|
factory(Class<T> type,
String name,
Factory<? extends T> factory)
Convenience method. Equivalent to factory(type, name, factory,
Scope.DEFAULT) . |
|
|
factory(Class<T> type,
String name,
Factory<? extends T> factory,
Scope scope)
Maps a factory to a given dependency type and name. |
|
|
factory(Class<T> type,
String name,
Scope scope)
Convenience method. Equivalent to factory(type, name, type,
scope) . |
|
private
|
factory(Key<T> key,
InternalFactory<? extends T> factory,
Scope scope)
Maps a dependency. |
|
ContainerBuilder |
injectStatics(Class<?>... types)
Upon creation, the Container will inject static fields and methods
into the given classes. |
|
void |
setAllowDuplicates(boolean val)
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
final Map<Key<?>,InternalFactory<?>> factories
final List<InternalFactory<?>> singletonFactories
final List<Class<?>> staticInjections
boolean created
boolean allowDuplicates
private static final InternalFactory<Container> CONTAINER_FACTORY
private static final InternalFactory<Logger> LOGGER_FACTORY
Constructor Detail |
---|
public ContainerBuilder()
Method Detail |
---|
private <T> ContainerBuilder factory(Key<T> key, InternalFactory<? extends T> factory, Scope scope)
private void checkKey(Key<?> key)
public <T> ContainerBuilder factory(Class<T> type, String name, Factory<? extends T> factory, Scope scope)
type
- of dependencyname
- of dependencyfactory
- creates objects to injectscope
- scope of injected instances
public <T> ContainerBuilder factory(Class<T> type, Factory<? extends T> factory, Scope scope)
factory(type,
Container.DEFAULT_NAME, factory, scope)
.
factory(Class, String, Factory, Scope)
public <T> ContainerBuilder factory(Class<T> type, String name, Factory<? extends T> factory)
factory(type, name, factory,
Scope.DEFAULT)
.
factory(Class, String, Factory, Scope)
public <T> ContainerBuilder factory(Class<T> type, Factory<? extends T> factory)
factory(type,
Container.DEFAULT_NAME, factory, Scope.DEFAULT)
.
factory(Class, String, Factory, Scope)
public <T> ContainerBuilder factory(Class<T> type, String name, Class<? extends T> implementation, Scope scope)
type
- of dependencyname
- of dependencyimplementation
- classscope
- scope of injected instances
public <T> ContainerBuilder factory(Class<T> type, String name, Class<? extends T> implementation)
Sets scope to value from Scoped
annotation on the
implementation class. Defaults to Scope.DEFAULT
if no annotation
is found.
type
- of dependencyname
- of dependencyimplementation
- class
public <T> ContainerBuilder factory(Class<T> type, Class<? extends T> implementation)
factory(type,
Container.DEFAULT_NAME, implementation)
.
factory(Class, String, Class)
public <T> ContainerBuilder factory(Class<T> type)
factory(type,
Container.DEFAULT_NAME, type)
.
factory(Class, String, Class)
public <T> ContainerBuilder factory(Class<T> type, String name)
factory(type, name, type)
.
factory(Class, String, Class)
public <T> ContainerBuilder factory(Class<T> type, Class<? extends T> implementation, Scope scope)
factory(type,
Container.DEFAULT_NAME, implementation, scope)
.
factory(Class, String, Class, Scope)
public <T> ContainerBuilder factory(Class<T> type, Scope scope)
factory(type,
Container.DEFAULT_NAME, type, scope)
.
factory(Class, String, Class, Scope)
public <T> ContainerBuilder factory(Class<T> type, String name, Scope scope)
factory(type, name, type,
scope)
.
factory(Class, String, Class, Scope)
public <T> ContainerBuilder alias(Class<T> type, String alias)
alias(type, Container.DEFAULT_NAME,
type)
.
alias(Class, String, String)
public <T> ContainerBuilder alias(Class<T> type, String name, String alias)
type
- of dependencyname
- of dependencyalias
- of to the dependency
private <T> ContainerBuilder alias(Key<T> key, Key<T> aliasKey)
public ContainerBuilder constant(String name, String value)
public ContainerBuilder constant(String name, int value)
public ContainerBuilder constant(String name, long value)
public ContainerBuilder constant(String name, boolean value)
public ContainerBuilder constant(String name, double value)
public ContainerBuilder constant(String name, float value)
public ContainerBuilder constant(String name, short value)
public ContainerBuilder constant(String name, char value)
public ContainerBuilder constant(String name, Class value)
public <E extends Enum<E>> ContainerBuilder constant(String name, E value)
private <T> ContainerBuilder constant(Class<T> type, String name, T value)
public ContainerBuilder injectStatics(Class<?>... types)
Container
will inject static fields and methods
into the given classes.
types
- for which static members will be injectedpublic boolean contains(Class<?> type, String name)
public boolean contains(Class<?> type)
contains(type,
Container.DEFAULT_NAME)
.
public Container create(boolean loadSingletons)
Container
instance. Injects static members for classes
which were registered using injectStatics(Class...)
.
loadSingletons
- If true, the container will load all singletons
now. If false, the container will lazily load singletons. Eager loading
is appropriate for production use while lazy loading can speed
development.
IllegalStateException
- if called more than onceprivate void ensureNotCreated()
public void setAllowDuplicates(boolean val)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |