public class DefaultBootstrapContext extends Object implements ConfigurableBootstrapContext
ConfigurableBootstrapContext
implementation.BootstrapRegistry.InstanceSupplier<T>, BootstrapRegistry.Scope
Constructor and Description |
---|
DefaultBootstrapContext() |
Modifier and Type | Method and Description |
---|---|
void |
addCloseListener(ApplicationListener<BootstrapContextClosedEvent> listener)
Add an
ApplicationListener that will be called with a
BootstrapContextClosedEvent when the BootstrapContext is closed and
the ApplicationContext has been prepared. |
void |
close(ConfigurableApplicationContext applicationContext)
Method to be called when
BootstrapContext is closed and the
ApplicationContext is prepared. |
<T> T |
get(Class<T> type)
Return an instance from the context if the type has been registered.
|
<T> T |
getOrElse(Class<T> type,
T other)
Return an instance from the context if the type has been registered.
|
<T> T |
getOrElseSupply(Class<T> type,
Supplier<T> other)
Return an instance from the context if the type has been registered.
|
<T,X extends Throwable> |
getOrElseThrow(Class<T> type,
Supplier<? extends X> exceptionSupplier)
Return an instance from the context if the type has been registered.
|
<T> BootstrapRegistry.InstanceSupplier<T> |
getRegisteredInstanceSupplier(Class<T> type)
Return any existing
BootstrapRegistry.InstanceSupplier for the given type. |
<T> boolean |
isRegistered(Class<T> type)
Return if a registration exists for the given type.
|
<T> void |
register(Class<T> type,
BootstrapRegistry.InstanceSupplier<T> instanceSupplier)
Register a specific type with the registry.
|
<T> void |
registerIfAbsent(Class<T> type,
BootstrapRegistry.InstanceSupplier<T> instanceSupplier)
Register a specific type with the registry if one is not already present.
|
public <T> void register(Class<T> type, BootstrapRegistry.InstanceSupplier<T> instanceSupplier)
BootstrapRegistry
singleton
, it
will be replaced.register
in interface BootstrapRegistry
T
- the instance typetype
- the instance typeinstanceSupplier
- the instance supplierpublic <T> void registerIfAbsent(Class<T> type, BootstrapRegistry.InstanceSupplier<T> instanceSupplier)
BootstrapRegistry
registerIfAbsent
in interface BootstrapRegistry
T
- the instance typetype
- the instance typeinstanceSupplier
- the instance supplierpublic <T> boolean isRegistered(Class<T> type)
BootstrapRegistry
isRegistered
in interface BootstrapContext
isRegistered
in interface BootstrapRegistry
T
- the instance typetype
- the instance typetrue
if the type has already been registeredpublic <T> BootstrapRegistry.InstanceSupplier<T> getRegisteredInstanceSupplier(Class<T> type)
BootstrapRegistry
BootstrapRegistry.InstanceSupplier
for the given type.getRegisteredInstanceSupplier
in interface BootstrapRegistry
T
- the instance typetype
- the instance typeBootstrapRegistry.InstanceSupplier
or null
public void addCloseListener(ApplicationListener<BootstrapContextClosedEvent> listener)
BootstrapRegistry
ApplicationListener
that will be called with a
BootstrapContextClosedEvent
when the BootstrapContext
is closed and
the ApplicationContext
has been prepared.addCloseListener
in interface BootstrapRegistry
listener
- the listener to addpublic <T> T get(Class<T> type) throws IllegalStateException
BootstrapContext
get
in interface BootstrapContext
T
- the instance typetype
- the instance typeIllegalStateException
- if the type has not been registeredpublic <T> T getOrElse(Class<T> type, T other)
BootstrapContext
getOrElse
in interface BootstrapContext
T
- the instance typetype
- the instance typeother
- the instance to use if the type has not been registeredpublic <T> T getOrElseSupply(Class<T> type, Supplier<T> other)
BootstrapContext
getOrElseSupply
in interface BootstrapContext
T
- the instance typetype
- the instance typeother
- a supplier for the instance to use if the type has not been registeredpublic <T,X extends Throwable> T getOrElseThrow(Class<T> type, Supplier<? extends X> exceptionSupplier) throws X extends Throwable
BootstrapContext
getOrElseThrow
in interface BootstrapContext
T
- the instance typeX
- the exception to throw if the type is not registeredtype
- the instance typeexceptionSupplier
- the supplier which will return the exception to be thrownX
- if the type has not been registeredX extends Throwable
public void close(ConfigurableApplicationContext applicationContext)
BootstrapContext
is closed and the
ApplicationContext
is prepared.applicationContext
- the prepared context