Class SourceContextImpl
- java.lang.Object
-
- net.officefloor.frame.impl.construct.source.SourcePropertiesImpl
-
- net.officefloor.frame.impl.construct.source.SourceContextImpl
-
- All Implemented Interfaces:
ServiceContext
,SourceContext
,SourceProperties
- Direct Known Subclasses:
ConfigurationSourceContextImpl
,ExecutiveContextImpl
,ExecutiveSourceContextImpl
,ManagedFunctionSourceContextImpl
,ManagedObjectPoolSourceContextImpl
,ManagedObjectSourceContextImpl
,SupplierSourceContextImpl
,TeamSourceContextWrapper
,WoofTemplateChangeContextImpl
,WoofTemplateExtensionChangeContextImpl
public class SourceContextImpl extends SourcePropertiesImpl implements SourceContext, ServiceContext
SourceContext
implementation.- Author:
- Daniel Sagenschneider
-
-
Constructor Summary
Constructors Constructor Description SourceContextImpl(java.lang.String sourceName, boolean isLoadingType, java.lang.String[] profiles, java.lang.ClassLoader classLoader, ClockFactory clockFactory, ResourceSource... resourceSources)
Initiate the rawSourceContext
to seed otherSourceContext
instances.SourceContextImpl(java.lang.String sourceName, boolean isLoadingType, java.lang.String[] additionalProfiles, SourceContext delegate, SourceProperties sourceProperties)
Initiate specificSourceContext
with necessarySourceProperties
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.ClassLoader
getClassLoader()
Obtains theClassLoader
.<T> Clock<T>
getClock(java.util.function.Function<java.lang.Long,T> translator)
Obtains theClock
.java.util.logging.Logger
getLogger()
Obtains theLogger
.java.lang.String
getName()
Obtains the name of the item being sourced.java.io.InputStream
getOptionalResource(java.lang.String location)
Attempts to obtain the resource at the specified location.java.util.List<java.lang.String>
getProfiles()
Obtains the listing of active profiles.java.io.InputStream
getResource(java.lang.String location)
Obtains the resource.boolean
isLoadingType()
Indicates if just loading as a type.java.lang.Class<?>
loadClass(java.lang.String name)
Loads theClass
.java.lang.Class<?>
loadOptionalClass(java.lang.String name)
Attempts to load the specifiedClass
.<S,F extends ServiceFactory<S>>
SloadOptionalService(java.lang.Class<F> serviceFactoryType)
Optionally loads a single service.<S,F extends ServiceFactory<S>>
java.lang.Iterable<S>loadOptionalServices(java.lang.Class<F> serviceFactoryType)
Optionally loads multiple services.<S,F extends ServiceFactory<S>>
SloadService(F serviceFactory)
Loads the specific service.<S,F extends ServiceFactory<S>,D extends F>
SloadService(java.lang.Class<F> serviceFactoryType, D defaultServiceFactory)
Loads a single service.<S,F extends ServiceFactory<S>,D extends F>
java.lang.Iterable<S>loadServices(java.lang.Class<F> serviceFactoryType, D defaultServiceFactory)
Loads multiple services.-
Methods inherited from class net.officefloor.frame.impl.construct.source.SourcePropertiesImpl
addProperty, getProperties, getProperty, getProperty, getPropertyNames
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface net.officefloor.frame.api.source.SourceProperties
getProperties, getProperty, getProperty, getPropertyNames
-
-
-
-
Constructor Detail
-
SourceContextImpl
public SourceContextImpl(java.lang.String sourceName, boolean isLoadingType, java.lang.String[] profiles, java.lang.ClassLoader classLoader, ClockFactory clockFactory, ResourceSource... resourceSources)
Initiate the rawSourceContext
to seed otherSourceContext
instances.- Parameters:
sourceName
- Name of source.isLoadingType
- Indicates if loading type.profiles
- Active profiles.classLoader
-ClassLoader
.clockFactory
-ClockFactory
.resourceSources
-ResourceSource
instances.
-
SourceContextImpl
public SourceContextImpl(java.lang.String sourceName, boolean isLoadingType, java.lang.String[] additionalProfiles, SourceContext delegate, SourceProperties sourceProperties)
Initiate specificSourceContext
with necessarySourceProperties
.- Parameters:
sourceName
- Name of source.isLoadingType
- Indicates if loading type.additionalProfiles
- Additional profiles.delegate
- DelegateSourceContext
.sourceProperties
-SourceProperties
.
-
-
Method Detail
-
getName
public java.lang.String getName()
Description copied from interface:SourceContext
Obtains the name of the item being sourced.- Specified by:
getName
in interfaceSourceContext
- Returns:
- Name of item being sourced.
-
isLoadingType
public boolean isLoadingType()
Description copied from interface:SourceContext
Indicates if just loading as a type.
When loading as a type the configuration provided is disregarded. This allows sources to know when to load singleton configuration that will take effect.
Whether this is
true
orfalse
the resulting type should be the same.- Specified by:
isLoadingType
in interfaceSourceContext
- Returns:
true
if loading as a type.
-
getProfiles
public java.util.List<java.lang.String> getProfiles()
Description copied from interface:SourceContext
Obtains the listing of active profiles.- Specified by:
getProfiles
in interfaceSourceContext
- Returns:
- Active profiles.
-
loadOptionalClass
public java.lang.Class<?> loadOptionalClass(java.lang.String name)
Description copied from interface:SourceContext
Attempts to load the specifiedClass
.- Specified by:
loadOptionalClass
in interfaceSourceContext
- Parameters:
name
- Name of theClass
.- Returns:
Class
ornull
if theClass
can not be found.
-
loadClass
public java.lang.Class<?> loadClass(java.lang.String name) throws UnknownClassError
Description copied from interface:SourceContext
Loads theClass
.- Specified by:
loadClass
in interfaceSourceContext
- Parameters:
name
- Name of theClass
.- Returns:
Class
.- Throws:
UnknownClassError
- IfClass
is not available. Let this propagate as OfficeFloor will handle it.
-
getOptionalResource
public java.io.InputStream getOptionalResource(java.lang.String location)
Description copied from interface:SourceContext
Attempts to obtain the resource at the specified location.- Specified by:
getOptionalResource
in interfaceSourceContext
- Parameters:
location
- Location of the resource.- Returns:
InputStream
to the contents of the resource ornull
if the resource can not be found.
-
getResource
public java.io.InputStream getResource(java.lang.String location) throws UnknownResourceError
Description copied from interface:SourceContext
Obtains the resource.- Specified by:
getResource
in interfaceSourceContext
- Parameters:
location
- Location of the resource.- Returns:
InputStream
to the contents of the resource.- Throws:
UnknownResourceError
- If resource is not found. Let this propagate as OfficeFloor will handle it.
-
loadService
public <S,F extends ServiceFactory<S>> S loadService(F serviceFactory) throws LoadServiceError
Description copied from interface:SourceContext
Loads the specific service.- Specified by:
loadService
in interfaceSourceContext
- Type Parameters:
S
- Service typeF
-ServiceFactory
type to create service.- Parameters:
serviceFactory
-ServiceFactory
.- Returns:
- Service.
- Throws:
LoadServiceError
- If fails to load the service.
-
loadService
public <S,F extends ServiceFactory<S>,D extends F> S loadService(java.lang.Class<F> serviceFactoryType, D defaultServiceFactory) throws UnknownServiceError, LoadServiceError
Description copied from interface:SourceContext
Loads a single service.- Specified by:
loadService
in interfaceSourceContext
- Type Parameters:
S
- Service typeF
-ServiceFactory
type to create service.D
- DefaultServiceFactory
type.- Parameters:
serviceFactoryType
- Type ofServiceFactory
.defaultServiceFactory
- DefaultServiceFactory
implementation. May benull
to indicate no default service (one must be configured).- Returns:
- Service.
- Throws:
UnknownServiceError
- If service is not configured and no default provided. Will also be thrown if more than one service is configured.LoadServiceError
- If fails to load the service.
-
loadOptionalService
public <S,F extends ServiceFactory<S>> S loadOptionalService(java.lang.Class<F> serviceFactoryType) throws LoadServiceError
Description copied from interface:SourceContext
Optionally loads a single service.- Specified by:
loadOptionalService
in interfaceSourceContext
- Type Parameters:
S
- Service typeF
-ServiceFactory
type to create service.- Parameters:
serviceFactoryType
- Type ofServiceFactory
.- Returns:
- Service or
null
if no service configured. - Throws:
LoadServiceError
- If fails to load the service orServiceLoader
finds more than one service configured.
-
loadServices
public <S,F extends ServiceFactory<S>,D extends F> java.lang.Iterable<S> loadServices(java.lang.Class<F> serviceFactoryType, D defaultServiceFactory) throws UnknownServiceError, LoadServiceError
Description copied from interface:SourceContext
Loads multiple services.- Specified by:
loadServices
in interfaceSourceContext
- Type Parameters:
S
- Service typeF
-ServiceFactory
type to create service.D
- DefaultServiceFactory
type.- Parameters:
serviceFactoryType
- Type ofServiceFactory
.defaultServiceFactory
- DefaultServiceFactory
implementation. May benull
to indicate no default service.- Returns:
Iterable
over the services. TheIterable
may also throwLoadServiceError
if fails to create next service.- Throws:
UnknownServiceError
- If no services are configured and no default provided.LoadServiceError
- If fails to load a service.
-
loadOptionalServices
public <S,F extends ServiceFactory<S>> java.lang.Iterable<S> loadOptionalServices(java.lang.Class<F> serviceFactoryType) throws LoadServiceError
Description copied from interface:SourceContext
Optionally loads multiple services.- Specified by:
loadOptionalServices
in interfaceSourceContext
- Type Parameters:
S
- Service typeF
-ServiceFactory
type to create service.- Parameters:
serviceFactoryType
- Type ofServiceFactory
.- Returns:
Iterable
over the services. May be no entries available. TheIterable
may also throwLoadServiceError
if fails to create next service.- Throws:
LoadServiceError
- If fails to load a service.
-
getClock
public <T> Clock<T> getClock(java.util.function.Function<java.lang.Long,T> translator)
Description copied from interface:SourceContext
Obtains theClock
.- Specified by:
getClock
in interfaceSourceContext
- Parameters:
translator
- Translate the seconds since Epoch to "time" returned from theClock
.- Returns:
Clock
.
-
getLogger
public java.util.logging.Logger getLogger()
Description copied from interface:SourceContext
Obtains the
Logger
.The
Logger
is named specific to the source. This is especially the case for re-use ofClass
within sources, as would not be able to differentiate.- Specified by:
getLogger
in interfaceSourceContext
- Returns:
Logger
.
-
getClassLoader
public java.lang.ClassLoader getClassLoader()
Description copied from interface:SourceContext
Obtains the
ClassLoader
.This is only provided in specific cases where a
ClassLoader
is required (such as creating aProxy
). The other methods of this interface should be used in preference to the returnedClassLoader
.- Specified by:
getClassLoader
in interfaceSourceContext
- Returns:
ClassLoader
.
-
-