Class ConfigurationService
- java.lang.Object
-
- org.opensaml.core.config.ConfigurationService
-
public class ConfigurationService extends Object
A service which provides for the registration, retrieval and deregistration of objects related to library module configuration.The service uses an internally-managed instance of
Configurationto handle the registration, retrieval and deregistration of the configuration objects under its management.The service first attempts to use the Java Services API to resolve the instance of Configuration to use. If multiple implementations of Configuration are registered via the Services API mechanism, the first one returned by the
ServiceLoaderiterator is used. If no Configuration implementation is declared or resolvable using the Services API, then it uses the default implementationMapBasedConfiguration.The Configuration instance to use may also be set externally via
setConfiguration(Configuration). This may be useful where an application-specific means such as Spring is used to configure the environment. This overrides the resolution process described above.
-
-
Field Summary
Fields Modifier and Type Field Description private static ServiceLoader<ConfigurationPropertiesSource>configPropertiesLoaderThe service loader used to locate registered implementations of ConfigurationPropertiesSource.private static ConfigurationconfigurationThe configuration instance to use.static StringDEFAULT_PARTITION_NAMEThe default storage partition name, if none is specified using configuration properties.static StringPROPERTY_PARTITION_NAMEThe configuration property name for the storage partition name to use.
-
Constructor Summary
Constructors Modifier Constructor Description protectedConfigurationService()Constructor.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> Tderegister(Class<T> configClass)Deregister a configuration instance.static <T> Tget(Class<T> configClass)Obtain the registered configuration instance.protected static ConfigurationgetConfiguration()Get theConfigurationinstance to use.static PropertiesgetConfigurationProperties()Get the set of configuration meta-properties, which determines the configuration of the configuration service itself.private static org.slf4j.LoggergetLogger()Get a logger.protected static StringgetPartitionName()Return the partition name which will be used for storage of configuration objects.static <T,I extends T>
voidregister(Class<T> configClass, I configInstance)Register a configuration instance.static voidsetConfiguration(Configuration newConfiguration)Set theConfigurationinstance to use.
-
-
-
Field Detail
-
DEFAULT_PARTITION_NAME
@Nonnull public static final String DEFAULT_PARTITION_NAME
The default storage partition name, if none is specified using configuration properties.- See Also:
- Constant Field Values
-
PROPERTY_PARTITION_NAME
@Nonnull public static final String PROPERTY_PARTITION_NAME
The configuration property name for the storage partition name to use.- See Also:
- Constant Field Values
-
configPropertiesLoader
private static ServiceLoader<ConfigurationPropertiesSource> configPropertiesLoader
The service loader used to locate registered implementations of ConfigurationPropertiesSource.
-
configuration
private static Configuration configuration
The configuration instance to use.
-
-
Method Detail
-
get
public static <T> T get(@Nonnull Class<T> configClass)Obtain the registered configuration instance.- Type Parameters:
T- the type of configuration being retrieved- Parameters:
configClass- the configuration class identifier- Returns:
- the instance of the registered configuration object, or null
-
register
public static <T,I extends T> void register(@Nonnull Class<T> configClass, @Nonnull I configInstance)Register a configuration instance.- Type Parameters:
T- the type of configuration being registeredI- the configuration object instance type being registered, which must be an instance ofT- Parameters:
configClass- the type of configuration being registeredconfigInstance- the configuration object instance being registered
-
deregister
public static <T> T deregister(@Nonnull Class<T> configClass)Deregister a configuration instance.- Type Parameters:
T- the type of configuration being deregistered- Parameters:
configClass- the type of configuration class being deregistered- Returns:
- the configuration object instance which was deregistered, or null
-
getConfigurationProperties
@Nullable public static Properties getConfigurationProperties()
Get the set of configuration meta-properties, which determines the configuration of the configuration service itself.The properties set is obtained from the first registered instance of
ConfigurationPropertiesSourcewhich returns a non-null properties set. The implementations of properties sources to use are obtained via the Java Services API.Properties made available in this meta-properties set may also be used by
Initializerimplementations.- Returns:
- the set of configuration meta-properties
-
setConfiguration
public static void setConfiguration(@Nonnull Configuration newConfiguration)Set theConfigurationinstance to use.The configuration instance to use is normally resolved via the Java Services API, or is defaulted. However, this method is provided to allow the configuration instance to be supplied externally, perhaps using an application-specific means such as Spring dependency injection.
- Parameters:
newConfiguration- the Configuration instance to use
-
getPartitionName
@Nonnull @NotEmpty protected static String getPartitionName()
Return the partition name which will be used for storage of configuration objects.This partition name is obtained from the configuration meta-properties. If a value is not supplied via that mechanism, then an internal default value is used.
- Returns:
- the partition name
-
getConfiguration
@Nonnull protected static Configuration getConfiguration()
Get theConfigurationinstance to use.The implementation to return is first resolved using the Java Services API. If this produces no implementation, then an instance of the default implementation of
MapBasedConfigurationis used.- Returns:
- the Configuration implementation instance
-
getLogger
@Nonnull private static org.slf4j.Logger getLogger()
Get a logger.- Returns:
- an SLF4J logger instance
-
-