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 interfaceSpringSupplierSource.SpringDependencyFactoryFactory for the creation of the Spring dependencies.static interfaceSpringSupplierSource.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.StringCONFIGURATION_CLASS_NAMEName ofPropertyValuefor the Spring Boot configurationClass.static java.lang.StringPROPERTY_ACTIVE_PROFILESPropertyValueto configure active Spring profiles.static java.lang.StringPROPERTY_UNLINK_CONTEXT_PROFILESPropertyValueto flag whether to unlink Spring profiles toOfficeprofiles.
-
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 OfficeSupplierconfigure(OfficeArchitect architect, java.lang.Class<?> configurationClass, java.lang.String... additionalPropertyNameValuePairs)Convenience method for configuring Spring programmatically into anOffice.static org.springframework.context.ConfigurableApplicationContextforceStartSpring(AvailableType[] availableTypes)Forces starting Spring.static <O> OgetManagedObject(java.lang.String qualifier, java.lang.Class<? extends O> objectType)Obtains the bean fromOfficeFloor.protected voidloadSpecification(AbstractSupplierSource.SpecificationContext context)Loads theSupplierSourceSpecification.static <S,E extends java.lang.Throwable>
SrunInContext(SpringSupplierSource.SpringLoader<S,E> loader, SpringSupplierSource.SpringDependencyFactory factory)Runs theRunnablein context for theSpringSupplierSource.SpringDependencyFactoryto create additional beans for Spring.voidsupply(SupplierSourceContext context)Supplies the necessaryManagedObjectSourceinstances.voidterminate()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
PropertyValueto configure active Spring profiles.- See Also:
- Constant Field Values
-
PROPERTY_UNLINK_CONTEXT_PROFILES
public static final java.lang.String PROPERTY_UNLINK_CONTEXT_PROFILES
PropertyValueto flag whether to unlink Spring profiles toOfficeprofiles.- See Also:
- Constant Field Values
-
CONFIGURATION_CLASS_NAME
public static final java.lang.String CONFIGURATION_CLASS_NAME
Name ofPropertyValuefor 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
OfficeFloorManagedObject.
-
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.ThrowableAllows capturing the
ConfigurableApplicationContext.Typically this is for testing to enable using Spring beans.
- Parameters:
capture-Consumerto 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 theRunnablein context for theSpringSupplierSource.SpringDependencyFactoryto create additional beans for Spring.- Type Parameters:
S- Loaded context.E- PossibleThrowablefrom loading.- Parameters:
loader-SpringSupplierSource.SpringLoader.factory-SpringSupplierSource.SpringDependencyFactoryto 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- AdditionalPropertyValuename/value pairs.- Returns:
OfficeSupplierfor theSpringSupplierSource.
-
forceStartSpring
public static org.springframework.context.ConfigurableApplicationContext forceStartSpring(AvailableType[] availableTypes) throws java.lang.Exception
Forces starting Spring.- Parameters:
availableTypes-AvailableTypeinstances.- Returns:
ConfigurableApplicationContext.nullif already started.- Throws:
java.lang.Exception- If fails to start Spring.
-
loadSpecification
protected void loadSpecification(AbstractSupplierSource.SpecificationContext context)
Description copied from class:AbstractSupplierSourceLoads theSupplierSourceSpecification.- Specified by:
loadSpecificationin classAbstractSupplierSource- Parameters:
context-AbstractSupplierSource.SpecificationContext.
-
supply
public void supply(SupplierSourceContext context) throws java.lang.Exception
Description copied from interface:SupplierSourceSupplies the necessaryManagedObjectSourceinstances.- Parameters:
context-SupplierSourceContext.- Throws:
java.lang.Exception- If fails to provide supply ofManagedObjectSourceinstances.
-
terminate
public void terminate()
Description copied from interface:SupplierSourceTerminates the supply contract.
This should release all resources required by the supplier.
-
-