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
public class SourceContextImpl
extends SourcePropertiesImpl
implements SourceContext, ServiceContext
SourceContext implementation.- Author:
- Daniel Sagenschneider
-
Constructor Summary
ConstructorsConstructorDescriptionSourceContextImpl(String sourceName, boolean isLoadingType, String[] profiles, ClassLoader classLoader, ClockFactory clockFactory, ResourceSource... resourceSources) Initiate the rawSourceContextto seed otherSourceContextinstances.SourceContextImpl(String sourceName, boolean isLoadingType, String[] additionalProfiles, SourceContext delegate, SourceProperties sourceProperties) Initiate specificSourceContextwith necessarySourceProperties. -
Method Summary
Modifier and TypeMethodDescriptionObtains theClassLoader.<T> Clock<T>Obtains theClock.Obtains theLogger.getName()Obtains the name of the item being sourced.getOptionalResource(String location) Attempts to obtain the resource at the specified location.Obtains the listing of active profiles.getResource(String location) Obtains the resource.booleanIndicates if just loading as a type.Class<?>Loads theClass.Class<?>loadOptionalClass(String name) Attempts to load the specifiedClass.<S,F extends ServiceFactory<S>>
SloadOptionalService(Class<F> serviceFactoryType) Optionally loads a single service.<S,F extends ServiceFactory<S>>
Iterable<S>loadOptionalServices(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(Class<F> serviceFactoryType, D defaultServiceFactory) Loads a single service.<S,F extends ServiceFactory<S>, D extends F>
Iterable<S>loadServices(Class<F> serviceFactoryType, D defaultServiceFactory) Loads multiple services.Methods inherited from class net.officefloor.frame.impl.construct.source.SourcePropertiesImpl
addProperty, getProperties, getProperty, getProperty, getPropertyNamesMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface net.officefloor.frame.api.source.SourceProperties
getProperties, getProperty, getProperty, getPropertyNames
-
Constructor Details
-
SourceContextImpl
public SourceContextImpl(String sourceName, boolean isLoadingType, String[] profiles, ClassLoader classLoader, ClockFactory clockFactory, ResourceSource... resourceSources) Initiate the rawSourceContextto seed otherSourceContextinstances.- Parameters:
sourceName- Name of source.isLoadingType- Indicates if loading type.profiles- Active profiles.classLoader-ClassLoader.clockFactory-ClockFactory.resourceSources-ResourceSourceinstances.
-
SourceContextImpl
public SourceContextImpl(String sourceName, boolean isLoadingType, String[] additionalProfiles, SourceContext delegate, SourceProperties sourceProperties) Initiate specificSourceContextwith necessarySourceProperties.- Parameters:
sourceName- Name of source.isLoadingType- Indicates if loading type.additionalProfiles- Additional profiles.delegate- DelegateSourceContext.sourceProperties-SourceProperties.
-
-
Method Details
-
getName
Description copied from interface:SourceContextObtains the name of the item being sourced.- Specified by:
getNamein interfaceSourceContext- Returns:
- Name of item being sourced.
-
isLoadingType
public boolean isLoadingType()Description copied from interface:SourceContextIndicates 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
trueorfalsethe resulting type should be the same.- Specified by:
isLoadingTypein interfaceSourceContext- Returns:
trueif loading as a type.
-
getProfiles
Description copied from interface:SourceContextObtains the listing of active profiles.- Specified by:
getProfilesin interfaceSourceContext- Returns:
- Active profiles.
-
loadOptionalClass
Description copied from interface:SourceContextAttempts to load the specifiedClass.- Specified by:
loadOptionalClassin interfaceSourceContext- Parameters:
name- Name of theClass.- Returns:
Classornullif theClasscan not be found.
-
loadClass
Description copied from interface:SourceContextLoads theClass.- Specified by:
loadClassin interfaceSourceContext- Parameters:
name- Name of theClass.- Returns:
Class.- Throws:
UnknownClassError- IfClassis not available. Let this propagate as OfficeFloor will handle it.
-
getOptionalResource
Description copied from interface:SourceContextAttempts to obtain the resource at the specified location.- Specified by:
getOptionalResourcein interfaceSourceContext- Parameters:
location- Location of the resource.- Returns:
InputStreamto the contents of the resource ornullif the resource can not be found.
-
getResource
Description copied from interface:SourceContextObtains the resource.- Specified by:
getResourcein interfaceSourceContext- Parameters:
location- Location of the resource.- Returns:
InputStreamto the contents of the resource.- Throws:
UnknownResourceError- If resource is not found. Let this propagate as OfficeFloor will handle it.
-
loadService
Description copied from interface:SourceContextLoads the specific service.- Specified by:
loadServicein interfaceSourceContext- Type Parameters:
S- Service typeF-ServiceFactorytype to create service.- Parameters:
serviceFactory-ServiceFactory.- Returns:
- Service.
- Throws:
LoadServiceError- If fails to load the service.
-
loadService
public <S,F extends ServiceFactory<S>, S loadServiceD extends F> (Class<F> serviceFactoryType, D defaultServiceFactory) throws UnknownServiceError, LoadServiceError Description copied from interface:SourceContextLoads a single service.- Specified by:
loadServicein interfaceSourceContext- Type Parameters:
S- Service typeF-ServiceFactorytype to create service.D- DefaultServiceFactorytype.- Parameters:
serviceFactoryType- Type ofServiceFactory.defaultServiceFactory- DefaultServiceFactoryimplementation. May benullto 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(Class<F> serviceFactoryType) throws LoadServiceError Description copied from interface:SourceContextOptionally loads a single service.- Specified by:
loadOptionalServicein interfaceSourceContext- Type Parameters:
S- Service typeF-ServiceFactorytype to create service.- Parameters:
serviceFactoryType- Type ofServiceFactory.- Returns:
- Service or
nullif no service configured. - Throws:
LoadServiceError- If fails to load the service orServiceLoaderfinds more than one service configured.
-
loadServices
public <S,F extends ServiceFactory<S>, Iterable<S> loadServicesD extends F> (Class<F> serviceFactoryType, D defaultServiceFactory) throws UnknownServiceError, LoadServiceError Description copied from interface:SourceContextLoads multiple services.- Specified by:
loadServicesin interfaceSourceContext- Type Parameters:
S- Service typeF-ServiceFactorytype to create service.D- DefaultServiceFactorytype.- Parameters:
serviceFactoryType- Type ofServiceFactory.defaultServiceFactory- DefaultServiceFactoryimplementation. May benullto indicate no default service.- Returns:
Iterableover the services. TheIterablemay also throwLoadServiceErrorif 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>> Iterable<S> loadOptionalServices(Class<F> serviceFactoryType) throws LoadServiceError Description copied from interface:SourceContextOptionally loads multiple services.- Specified by:
loadOptionalServicesin interfaceSourceContext- Type Parameters:
S- Service typeF-ServiceFactorytype to create service.- Parameters:
serviceFactoryType- Type ofServiceFactory.- Returns:
Iterableover the services. May be no entries available. TheIterablemay also throwLoadServiceErrorif fails to create next service.- Throws:
LoadServiceError- If fails to load a service.
-
getClock
Description copied from interface:SourceContextObtains theClock.- Specified by:
getClockin interfaceSourceContext- Type Parameters:
T- Type of time.- Parameters:
translator- Translate the seconds since Epoch to "time" returned from theClock.- Returns:
Clock.
-
getLogger
Description copied from interface:SourceContextObtains the
Logger.The
Loggeris named specific to the source. This is especially the case for re-use ofClasswithin sources, as would not be able to differentiate.- Specified by:
getLoggerin interfaceSourceContext- Returns:
Logger.
-
getClassLoader
Description copied from interface:SourceContextObtains the
ClassLoader.This is only provided in specific cases where a
ClassLoaderis required (such as creating aProxy). The other methods of this interface should be used in preference to the returnedClassLoader.- Specified by:
getClassLoaderin interfaceSourceContext- Returns:
ClassLoader.
-