Class PropertiesLoader<T>
- Type Parameters:
T
- the type of references to sources
The special system parameter DEFAULTS
is recognized. If it
is present, then the value is understood as the relative name of another
source from which to load default values. Values in the main source override
values from the default source. The parameter DEFAULTS
is
removed from the set.
How the relative source name is resolved depends on the kind of source. Default loading is recursive; it is an error to specify circular references.
- Since:
- 1.3
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final String
The name of the system parameter that refers to default properties. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract T
findDefaults
(T mainSource, String defaultsName) Finds a source for default properties for a relative name.static Properties
Loads properties from a file.static Properties
loadResource
(ClassLoader classLoader, String resourceName) Loads properties from a resource.loadSource
(T source) Loads properties from a source, resolving defaults if specified.protected abstract InputStream
openSource
(T source) Opens an input stream for a source.
-
Field Details
-
DEFAULTS_PARAMETER_NAME
The name of the system parameter that refers to default properties.
-
-
Constructor Details
-
PropertiesLoader
protected PropertiesLoader()Creates a new instance.
-
-
Method Details
-
openSource
Opens an input stream for a source.- Parameters:
source
- the source- Returns:
- an input stream providing the contents of the source
- Throws:
IOException
- if the source cannot be opened
-
findDefaults
Finds a source for default properties for a relative name.This method is concerned only with resolving the relative name with respect to the referencing source. It does not check whether the default source exists or is accessible.
- Parameters:
mainSource
- the main source containing the referencedefaultsName
- the relative name of the default source- Returns:
- the default source
-
loadSource
Loads properties from a source, resolving defaults if specified.- Parameters:
source
- the source- Returns:
- a map of properties containing explicit definitions and (recursively) inherited defaults
- Throws:
IOException
- if any required source cannot be read
-
loadFile
Loads properties from a file.A default name is understood as a file pathname relative to the parent directory of the referencing file.
- Parameters:
file
- the source file- Returns:
- a map of properties containing explicit definitions and (recursively) inherited defaults
- Throws:
IOException
- if any required source cannot be read
-
loadResource
public static Properties loadResource(ClassLoader classLoader, String resourceName) throws IOException Loads properties from a resource.A default name is understood as a qualified resource name relative to the given class loader.
- Parameters:
classLoader
- the class loader to query for the main resource and recursive defaultsresourceName
- the qualified resource name- Returns:
- a map of properties containing explicit definitions and (recursively) inherited defaults
- Throws:
IOException
- if any required source cannot be read
-