Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## com.opensymphony.xwork2.inject
Class ContainerBuilder

    java.lang.Object
      com.opensymphony.xwork2.inject.ContainerBuilder

    public final class ContainerBuilder

extends Object

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:

- Injects the current `Container`.
- Injects the `Logger` for the injected member's declaring class.

Author:
  crazybob@google.com (Bob Lee)

Nested Class Summary
`static interface` | `ContainerBuilder.Command` Implemented by classes which participate in building a container.

Constructor Summary
`ContainerBuilder()` Constructs a new builder.

Method Summary
`
`<T> ContainerBuilder`
` | `alias(Class<T> type, String alias)` Convenience method. Equivalent to `alias(type, Container.DEFAULT_NAME, type)`.
`
`<T> ContainerBuilder`
` | `alias(Class<T> type, String name, String alias)` Maps an existing factory to a new 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.
`
`<E extends Enum<E>> ContainerBuilder`
` | `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.
`
`<T> ContainerBuilder`
` | `factory(Class<T> type)` Convenience method. Equivalent to `factory(type, Container.DEFAULT_NAME, type)`.
`
`<T> ContainerBuilder`
` | `factory(Class<T> type, Class<? extends T> implementation)` Convenience method. Equivalent to `factory(type, Container.DEFAULT_NAME, implementation)`.
`
`<T> ContainerBuilder`
` | `factory(Class<T> type, Class<? extends T> implementation, Scope scope)` Convenience method. Equivalent to `factory(type, Container.DEFAULT_NAME, implementation, scope)`.
`
`<T> ContainerBuilder`
` | `factory(Class<T> type, Factory<? extends T> factory)` Convenience method. Equivalent to `factory(type, Container.DEFAULT_NAME, factory, Scope.DEFAULT)`.
`
`<T> ContainerBuilder`
` | `factory(Class<T> type, Factory<? extends T> factory, Scope scope)` Convenience method. Equivalent to `factory(type, Container.DEFAULT_NAME, factory, scope)`.
`
`<T> ContainerBuilder`
` | `factory(Class<T> type, Scope scope)` Convenience method. Equivalent to `factory(type, Container.DEFAULT_NAME, type, scope)`.
`
`<T> ContainerBuilder`
` | `factory(Class<T> type, String name)` Convenience method. Equivalent to `factory(type, name, type)`.
`
`<T> ContainerBuilder`
` | `factory(Class<T> type, String name, Class<? extends T> implementation)` Maps an implementation class to a given dependency type and name.
`
`<T> ContainerBuilder`
` | `factory(Class<T> type, String name, Class<? extends T> implementation, Scope scope)` Maps an implementation class to a given dependency type and name.
`
`<T> ContainerBuilder`
` | `factory(Class<T> type, String name, Factory<? extends T> factory)` Convenience method. Equivalent to `factory(type, name, factory, Scope.DEFAULT)`.
`
`<T> ContainerBuilder`
` | `factory(Class<T> type, String name, Factory<? extends T> factory, Scope scope)` Maps a factory to a given dependency type and name.
`
`<T> ContainerBuilder`
` | `factory(Class<T> type, String name, Scope scope)` Convenience method. Equivalent to `factory(type, name, type, scope)`.
`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`

Constructor Detail

### ContainerBuilder

    public ContainerBuilder()

  Constructs a new builder.

Method Detail

### factory

    public <T> ContainerBuilder factory(Class<T> type,
                                        String name,
                                        Factory<? extends T> factory,
                                        Scope scope)

  Maps a factory to a given dependency type and name.

  Parameters:
    `type` - of dependency
    `name` - of dependency
    `factory` - creates objects to inject
    `scope` - scope of injected instances
  Returns:
    this builder

### factory

    public <T> ContainerBuilder factory(Class<T> type,
                                        Factory<? extends T> factory,
                                        Scope scope)

  Convenience method. Equivalent to `factory(type, Container.DEFAULT_NAME, factory, scope)`.

  See Also:
    `factory(Class, String, Factory, Scope)`

### factory

    public <T> ContainerBuilder factory(Class<T> type,
                                        String name,
                                        Factory<? extends T> factory)

  Convenience method. Equivalent to `factory(type, name, factory, Scope.DEFAULT)`.

  See Also:
    `factory(Class, String, Factory, Scope)`

### factory

    public <T> ContainerBuilder factory(Class<T> type,
                                        Factory<? extends T> factory)

  Convenience method. Equivalent to `factory(type, Container.DEFAULT_NAME, factory, Scope.DEFAULT)`.

  See Also:
    `factory(Class, String, Factory, Scope)`

### factory

    public <T> ContainerBuilder factory(Class<T> type,
                                        String name,
                                        Class<? extends T> implementation,
                                        Scope scope)

  Maps an implementation class to a given dependency type and name. Creates instances using the container, recursively injecting dependencies.

  Parameters:
    `type` - of dependency
    `name` - of dependency
    `implementation` - class
    `scope` - scope of injected instances
  Returns:
    this builder

### factory

    public <T> ContainerBuilder factory(Class<T> type,
                                        String name,
                                        Class<? extends T> implementation)

  Maps an implementation class to a given dependency type and name. Creates instances using the container, recursively injecting dependencies.

  Sets scope to value from `Scoped` annotation on the implementation class. Defaults to `Scope.DEFAULT` if no annotation is found.

  Parameters:
    `type` - of dependency
    `name` - of dependency
    `implementation` - class
  Returns:
    this builder

### factory

    public <T> ContainerBuilder factory(Class<T> type,
                                        Class<? extends T> implementation)

  Convenience method. Equivalent to `factory(type, Container.DEFAULT_NAME, implementation)`.

  See Also:
    `factory(Class, String, Class)`

### factory

    public <T> ContainerBuilder factory(Class<T> type)

  Convenience method. Equivalent to `factory(type, Container.DEFAULT_NAME, type)`.

  See Also:
    `factory(Class, String, Class)`

### factory

    public <T> ContainerBuilder factory(Class<T> type,
                                        String name)

  Convenience method. Equivalent to `factory(type, name, type)`.

  See Also:
    `factory(Class, String, Class)`

### factory

    public <T> ContainerBuilder factory(Class<T> type,
                                        Class<? extends T> implementation,
                                        Scope scope)

  Convenience method. Equivalent to `factory(type, Container.DEFAULT_NAME, implementation, scope)`.

  See Also:
    `factory(Class, String, Class, Scope)`

### factory

    public <T> ContainerBuilder factory(Class<T> type,
                                        Scope scope)

  Convenience method. Equivalent to `factory(type, Container.DEFAULT_NAME, type, scope)`.

  See Also:
    `factory(Class, String, Class, Scope)`

### factory

    public <T> ContainerBuilder factory(Class<T> type,
                                        String name,
                                        Scope scope)

  Convenience method. Equivalent to `factory(type, name, type, scope)`.

  See Also:
    `factory(Class, String, Class, Scope)`

### alias

    public <T> ContainerBuilder alias(Class<T> type,
                                      String alias)

  Convenience method. Equivalent to `alias(type, Container.DEFAULT_NAME, type)`.

  See Also:
    `alias(Class, String, String)`

### alias

    public <T> ContainerBuilder alias(Class<T> type,
                                      String name,
                                      String alias)

  Maps an existing factory to a new name.

  Parameters:
    `type` - of dependency
    `name` - of dependency
    `alias` - of to the dependency
  Returns:
    this builder

### constant

    public ContainerBuilder constant(String name,
                                     String value)

  Maps a constant value to the given name.

### constant

    public ContainerBuilder constant(String name,
                                     int value)

  Maps a constant value to the given name.

### constant

    public ContainerBuilder constant(String name,
                                     long value)

  Maps a constant value to the given name.

### constant

    public ContainerBuilder constant(String name,
                                     boolean value)

  Maps a constant value to the given name.

### constant

    public ContainerBuilder constant(String name,
                                     double value)

  Maps a constant value to the given name.

### constant

    public ContainerBuilder constant(String name,
                                     float value)

  Maps a constant value to the given name.

### constant

    public ContainerBuilder constant(String name,
                                     short value)

  Maps a constant value to the given name.

### constant

    public ContainerBuilder constant(String name,
                                     char value)

  Maps a constant value to the given name.

### constant

    public ContainerBuilder constant(String name,
                                     Class value)

  Maps a class to the given name.

### constant

    public <E extends Enum<E>> ContainerBuilder constant(String name,
                                                         E value)

  Maps an enum to the given name.

### injectStatics

    public ContainerBuilder injectStatics(Class<?>... types)

  Upon creation, the `Container` will inject static fields and methods into the given classes.

  Parameters:
    `types` - for which static members will be injected

### contains

    public boolean contains(Class<?> type,
                            String name)

  Returns true if this builder contains a mapping for the given type and name.

### contains

    public boolean contains(Class<?> type)

  Convenience method. Equivalent to `contains(type, Container.DEFAULT_NAME)`.

### create

    public Container create(boolean loadSingletons)

  Creates a `Container` instance. Injects static members for classes which were registered using `injectStatics(Class...)`.

  Parameters:
    `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.
  Throws:
    `IllegalStateException` - if called more than once

### setAllowDuplicates

    public void setAllowDuplicates(boolean val)

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2000–2017 Apache Software Foundation. All rights reserved.