Top Description Constructors Methods
javax.enterprise.inject.se

public abstract Class SeContainerInitializer

extends Object
Class Inheritance
Imports
java.lang.annotation.Annotation, java.util.Iterator, .Map, .ServiceConfigurationError, .ServiceLoader, javax.enterprise.inject.spi.Extension

A CDI container initializer for Java SE. An instance may be obtained by calling SeContainerInitializer#newInstance() static method.

Typical usage looks like this:

SeContainer container = SeContainerInitializer.newInstance().initialize();
container.select(Foo.class).get();
container.close();

Since SeContainer interface implements AutoCloseable:

try (SeContainer container = SeContainerInitializer.newInstance().initialize()) {
    container.select(Foo.class).get();
}

By default, the discovery is enabled so that all beans from all discovered bean archives are considered. However, it's possible to define a "synthetic" bean archive, or the set of bean classes and enablement respectively:

SeContainer container = SeContainerInitializer.newInstance().addBeanClasses(Foo.class, Bar.class).selectAlternatives(Bar.class).initialize());

Moreover, it's also possible to disable the discovery completely so that only the "synthetic" bean archive is considered:

SeContainer container = SeContainerInitializer.newInstance().disableDiscovery().addBeanClasses(Foo.class, Bar.class).initialize());

In the same manner, it is possible to explicitly declare interceptors, decorators, extensions and implementation specific options using the builder.

SeContainerInitializer containerInitializer = SeContainerInitializer.newInstance()
        .disableDiscovery()
        .addPackages(Main.class, Utils.class)
        .enableInterceptors(TransactionalInterceptor.class)
        .addProperty("property", true);
SeContainer container = container.initialize();
Authors
Antoine Sabot-Durand, Martin Kouba, John D. Ament
Since
2.0

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public abstract SeContainerInitializer

Returns:

self
addBeanClasses
(Class<?>...
classes to add to the synthetic bean archive
classes
)

Add provided bean classes to the synthetic bean archive.

public abstract SeContainerInitializer

Returns:

self
addExtensions
(Extension...
extensions to use in the container
extensions
)

Add extensions to the set of extensions.

public abstract SeContainerInitializer

Returns:

self
addExtensions
(Class<? extends Extension>...
extensions class to use in the container
extensions
)

Add extensions to the set of extensions.

public abstract SeContainerInitializer

Returns:

self
addPackages
(Class<?>...
classes whose packages will be added to the synthetic bean archive
packageClasses
)

All classes from the packages of the specified classes will be added to the set of bean classes for the synthetic bean archive.

public abstract SeContainerInitializer

Returns:

self
addPackages
(boolean
should subpackages be scanned or not
scanRecursively
,
Class<?>...
classes whose packages will be scanned
packageClasses
)

Packages of the specified classes will be scanned and found classes will be added to the set of bean classes for the synthetic bean archive.*

Note that the scanning possibilities are limited.

public abstract SeContainerInitializer

Returns:

self
addPackages
(Package...
packages that will be added to the synthetic bean archive
packages
)

All classes from the specified packages will be added to the set of bean classes for the synthetic bean archive.

public abstract SeContainerInitializer

Returns:

self
addPackages
(boolean
should subpackages be scanned or not
scanRecursively
,
Package...
packages that will be added to the synthetic bean archive
packages
)

All classes from the specified packages will be added to the set of bean classes for the synthetic bean archive.

public abstract SeContainerInitializer

Returns:

self
addProperty
(String
property name
key
,
Object
property value
value
)

Add a configuration property to the container

public abstract SeContainerInitializer

Returns:

self
disableDiscovery
()

By default, the discovery is enabled.

public abstract SeContainerInitializer

Returns:

self
enableDecorators
(Class<?>...
classes of the decorators to enable.
decoratorClasses
)

Add decorator classes to the list of enabled decorators for the synthetic bean archive.

public abstract SeContainerInitializer

Returns:

self
enableInterceptors
(Class<?>...
classes of the interceptors to enable.
interceptorClasses
)

Add interceptor classes to the list of enabled interceptors for the synthetic bean archive.

private static SeContainerInitializer
public abstract SeContainer

Returns:

the SeContainer instance associated with the container.
initialize
()

Initializes a CDI SeContainerInitializer.

public static SeContainerInitializer

Returns:

a new SeContainerInitializer instance.
newInstance
()

Returns an instance of SeContainerInitializer Each call returns a new instance

public abstract SeContainerInitializer

Returns:

self
selectAlternatives
(Class<?>...
classes of the alternatives to select
alternativeClasses
)

Add alternatives classes to the list of selected alternatives for the synthetic bean archive.

public abstract SeContainerInitializer

Returns:

self
selectAlternativeStereotypes
(Class<? extends Annotation>...
alternatives stereotypes to select
alternativeStereotypeClasses
)

Add alternative stereotype classes to the list of selected alternative stereotypes for the synthetic bean archive.

public abstract SeContainerInitializer

Returns:

self
setClassLoader
(ClassLoader
the class loader to use
classLoader
)

Set a ClassLoader.

public abstract SeContainerInitializer

Returns:

self
setProperties
(Map<String, Object>
a map containing properties to add
properties
)

Set all the configuration properties.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

SeContainerInitializerback to summary
public SeContainerInitializer()

Method Detail

addBeanClassesback to summary
public abstract SeContainerInitializer addBeanClasses(Class<?>... classes)

Add provided bean classes to the synthetic bean archive.

Parameters
classes:Class<?>[]

classes to add to the synthetic bean archive

Returns:SeContainerInitializer

self

addExtensionsback to summary
public abstract SeContainerInitializer addExtensions(Extension... extensions)

Add extensions to the set of extensions.

Parameters
extensions:Extension[]

extensions to use in the container

Returns:SeContainerInitializer

self

addExtensionsback to summary
public abstract SeContainerInitializer addExtensions(Class<? extends Extension>... extensions)

Add extensions to the set of extensions.

Parameters
extensions:Class<? extends Extension>[]

extensions class to use in the container

Returns:SeContainerInitializer

self

Annotations
@SuppressWarnings:unchecked
addPackagesback to summary
public abstract SeContainerInitializer addPackages(Class<?>... packageClasses)

All classes from the packages of the specified classes will be added to the set of bean classes for the synthetic bean archive.

Note that the scanning possibilities are limited. Therefore, only directories and jar files from the filesystem are supported.

Scanning may also have negative impact on SE performance.

Parameters
packageClasses:Class<?>[]

classes whose packages will be added to the synthetic bean archive

Returns:SeContainerInitializer

self

addPackagesback to summary
public abstract SeContainerInitializer addPackages(boolean scanRecursively, Class<?>... packageClasses)

Packages of the specified classes will be scanned and found classes will be added to the set of bean classes for the synthetic bean archive.*

Note that the scanning possibilities are limited. Therefore, only directories and jar files from the filesystem are supported.

Scanning may also have negative impact on SE performance.

Parameters
scanRecursively:boolean

should subpackages be scanned or not

packageClasses:Class<?>[]

classes whose packages will be scanned

Returns:SeContainerInitializer

self

addPackagesback to summary
public abstract SeContainerInitializer addPackages(Package... packages)

All classes from the specified packages will be added to the set of bean classes for the synthetic bean archive.

Note that the scanning possibilities are limited. Therefore, only directories and jar files from the filesystem are supported.

Scanning may also have negative impact on SE performance.

Parameters
packages:Package[]

packages that will be added to the synthetic bean archive

Returns:SeContainerInitializer

self

addPackagesback to summary
public abstract SeContainerInitializer addPackages(boolean scanRecursively, Package... packages)

All classes from the specified packages will be added to the set of bean classes for the synthetic bean archive.

Note that the scanning possibilities are limited. Therefore, only directories and jar files from the filesystem are supported.

Scanning may also have negative impact on SE performance.

Parameters
scanRecursively:boolean

should subpackages be scanned or not

packages:Package[]

packages that will be added to the synthetic bean archive

Returns:SeContainerInitializer

self

addPropertyback to summary
public abstract SeContainerInitializer addProperty(String key, Object value)

Add a configuration property to the container

Parameters
key:String

property name

value:Object

property value

Returns:SeContainerInitializer

self

disableDiscoveryback to summary
public abstract SeContainerInitializer disableDiscovery()

By default, the discovery is enabled. However, it's possible to disable the discovery completely so that only the "synthetic" bean archive is considered.

Returns:SeContainerInitializer

self

enableDecoratorsback to summary
public abstract SeContainerInitializer enableDecorators(Class<?>... decoratorClasses)

Add decorator classes to the list of enabled decorators for the synthetic bean archive.

This method does not add any class to the set of bean classes of the synthetic bean archive.

Parameters
decoratorClasses:Class<?>[]

classes of the decorators to enable.

Returns:SeContainerInitializer

self

enableInterceptorsback to summary
public abstract SeContainerInitializer enableInterceptors(Class<?>... interceptorClasses)

Add interceptor classes to the list of enabled interceptors for the synthetic bean archive.

This method does not add any class to the set of bean classes of the synthetic bean archive.

Parameters
interceptorClasses:Class<?>[]

classes of the interceptors to enable.

Returns:SeContainerInitializer

self

findSeContainerInitializerback to summary
private static SeContainerInitializer findSeContainerInitializer()
initializeback to summary
public abstract SeContainer initialize()

Initializes a CDI SeContainerInitializer.

Cannot be called within an application server.

Returns:SeContainer

the SeContainer instance associated with the container.

Exceptions
UnsupportedOperationException:
if called within an application server
newInstanceback to summary
public static SeContainerInitializer newInstance()

Returns an instance of SeContainerInitializer Each call returns a new instance

Returns:SeContainerInitializer

a new SeContainerInitializer instance.

Exceptions
IllegalStateException:
if called in a Java EE container
selectAlternativesback to summary
public abstract SeContainerInitializer selectAlternatives(Class<?>... alternativeClasses)

Add alternatives classes to the list of selected alternatives for the synthetic bean archive.

This method does not add any class to the set of bean classes of the synthetic bean archive.

Parameters
alternativeClasses:Class<?>[]

classes of the alternatives to select

Returns:SeContainerInitializer

self

selectAlternativeStereotypesback to summary
public abstract SeContainerInitializer selectAlternativeStereotypes(Class<? extends Annotation>... alternativeStereotypeClasses)

Add alternative stereotype classes to the list of selected alternative stereotypes for the synthetic bean archive.

This method does not add any class to the set of bean classes of the synthetic bean archive.

Parameters
alternativeStereotypeClasses:Class<? extends Annotation>[]

alternatives stereotypes to select

Returns:SeContainerInitializer

self

Annotations
@SuppressWarnings:unchecked
setClassLoaderback to summary
public abstract SeContainerInitializer setClassLoader(ClassLoader classLoader)

Set a ClassLoader. The given ClassLoader will be scanned automatically for bean archives if scanning is enabled.

Parameters
classLoader:ClassLoader

the class loader to use

Returns:SeContainerInitializer

self

setPropertiesback to summary
public abstract SeContainerInitializer setProperties(Map<String, Object> properties)

Set all the configuration properties. Erase previous properties set

Parameters
properties:Map<String, Object>

a map containing properties to add

Returns:SeContainerInitializer

self