Package net.officefloor.spring
Class SpringSupplierSource
- java.lang.Object
-
- net.officefloor.compile.spi.supplier.source.impl.AbstractSupplierSource
-
- net.officefloor.spring.SpringSupplierSource
-
- All Implemented Interfaces:
SupplierSource
public class SpringSupplierSource extends AbstractSupplierSource
SpringSupplierSource
.- Author:
- Daniel Sagenschneider
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
SpringSupplierSource.SpringDependencyFactory
Factory for the creation of the Spring dependencies.static interface
SpringSupplierSource.SpringLoader<S,E extends java.lang.Throwable>
Provides the loading of Spring.-
Nested classes/interfaces inherited from class net.officefloor.compile.spi.supplier.source.impl.AbstractSupplierSource
AbstractSupplierSource.SpecificationContext
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
CONFIGURATION_CLASS_NAME
Name ofPropertyValue
for the Spring Boot configurationClass
.static java.lang.String
PROPERTY_ACTIVE_PROFILES
PropertyValue
to configure active Spring profiles.static java.lang.String
PROPERTY_UNLINK_CONTEXT_PROFILES
PropertyValue
to flag whether to unlink Spring profiles toOffice
profiles.
-
Constructor Summary
Constructors Constructor Description SpringSupplierSource()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static <S,E extends java.lang.Throwable>
ScaptureApplicationContext(java.util.function.Consumer<org.springframework.context.ConfigurableApplicationContext> capture, SpringSupplierSource.SpringLoader<S,E> loader)
Allows capturing theConfigurableApplicationContext
.static OfficeSupplier
configure(OfficeArchitect architect, java.lang.Class<?> configurationClass, java.lang.String... additionalPropertyNameValuePairs)
Convenience method for configuring Spring programmatically into anOffice
.static org.springframework.context.ConfigurableApplicationContext
forceStartSpring(AvailableType[] availableTypes)
Forces starting Spring.static <O> O
getManagedObject(java.lang.String qualifier, java.lang.Class<? extends O> objectType)
Obtains the bean fromOfficeFloor
.protected void
loadSpecification(AbstractSupplierSource.SpecificationContext context)
Loads theSupplierSourceSpecification
.static <S,E extends java.lang.Throwable>
SrunInContext(SpringSupplierSource.SpringLoader<S,E> loader, SpringSupplierSource.SpringDependencyFactory factory)
Runs theRunnable
in context for theSpringSupplierSource.SpringDependencyFactory
to create additional beans for Spring.void
supply(SupplierSourceContext context)
Supplies the necessaryManagedObjectSource
instances.void
terminate()
Terminates the supply contract.-
Methods inherited from class net.officefloor.compile.spi.supplier.source.impl.AbstractSupplierSource
getSpecification
-
-
-
-
Field Detail
-
PROPERTY_ACTIVE_PROFILES
public static final java.lang.String PROPERTY_ACTIVE_PROFILES
PropertyValue
to configure active Spring profiles.- See Also:
- Constant Field Values
-
PROPERTY_UNLINK_CONTEXT_PROFILES
public static final java.lang.String PROPERTY_UNLINK_CONTEXT_PROFILES
PropertyValue
to flag whether to unlink Spring profiles toOffice
profiles.- See Also:
- Constant Field Values
-
CONFIGURATION_CLASS_NAME
public static final java.lang.String CONFIGURATION_CLASS_NAME
Name ofPropertyValue
for the Spring Boot configurationClass
.- See Also:
- Constant Field Values
-
-
Method Detail
-
getManagedObject
public static <O> O getManagedObject(java.lang.String qualifier, java.lang.Class<? extends O> objectType)
Obtains the bean from
OfficeFloor
.This should be used as follows:
@Configuration public class SomeConfigurationOnScanPath { @Bean public DependencyType officeFloorDependency() { return SpringSupplierSource.getManagedObject("qualifier", DependencyType.class); } }
- Type Parameters:
O
- Object type.- Parameters:
qualifier
- Qualifier. May benull
.objectType
- Type of object required.- Returns:
- Object sourced from an
OfficeFloor
ManagedObject
.
-
captureApplicationContext
public static <S,E extends java.lang.Throwable> S captureApplicationContext(java.util.function.Consumer<org.springframework.context.ConfigurableApplicationContext> capture, SpringSupplierSource.SpringLoader<S,E> loader) throws E extends java.lang.Throwable
Allows capturing the
ConfigurableApplicationContext
.Typically this is for testing to enable using Spring beans.
- Parameters:
capture
-Consumer
to receive theConfigurableApplicationContext
.loader
-SpringSupplierSource.SpringLoader
.- Returns:
- Loaded context.
- Throws:
E
- Possible failure in loading.E extends java.lang.Throwable
-
runInContext
public static <S,E extends java.lang.Throwable> S runInContext(SpringSupplierSource.SpringLoader<S,E> loader, SpringSupplierSource.SpringDependencyFactory factory) throws E extends java.lang.Throwable
Runs theRunnable
in context for theSpringSupplierSource.SpringDependencyFactory
to create additional beans for Spring.- Type Parameters:
S
- Loaded context.E
- PossibleThrowable
from loading.- Parameters:
loader
-SpringSupplierSource.SpringLoader
.factory
-SpringSupplierSource.SpringDependencyFactory
to create the additional beans.- Returns:
- Loaded context.
- Throws:
E
- If fails to load.E extends java.lang.Throwable
-
configure
public static OfficeSupplier configure(OfficeArchitect architect, java.lang.Class<?> configurationClass, java.lang.String... additionalPropertyNameValuePairs)
Convenience method for configuring Spring programmatically into anOffice
.- Parameters:
architect
-OfficeArchitect
.configurationClass
- Spring Boot configurationClass
.additionalPropertyNameValuePairs
- AdditionalPropertyValue
name/value pairs.- Returns:
OfficeSupplier
for theSpringSupplierSource
.
-
forceStartSpring
public static org.springframework.context.ConfigurableApplicationContext forceStartSpring(AvailableType[] availableTypes) throws java.lang.Exception
Forces starting Spring.- Parameters:
availableTypes
-AvailableType
instances.- Returns:
ConfigurableApplicationContext
.null
if already started.- Throws:
java.lang.Exception
- If fails to start Spring.
-
loadSpecification
protected void loadSpecification(AbstractSupplierSource.SpecificationContext context)
Description copied from class:AbstractSupplierSource
Loads theSupplierSourceSpecification
.- Specified by:
loadSpecification
in classAbstractSupplierSource
- Parameters:
context
-AbstractSupplierSource.SpecificationContext
.
-
supply
public void supply(SupplierSourceContext context) throws java.lang.Exception
Description copied from interface:SupplierSource
Supplies the necessaryManagedObjectSource
instances.- Parameters:
context
-SupplierSourceContext
.- Throws:
java.lang.Exception
- If fails to provide supply ofManagedObjectSource
instances.
-
terminate
public void terminate()
Description copied from interface:SupplierSource
Terminates the supply contract.
This should release all resources required by the supplier.
-
-