Configuration
, Parameters
AbstractStringConfiguration
public abstract class BaseConfiguration extends AbstractConfiguration
An implementing subclass must override getOptionalStringImpl(String)
for local raw string retrieval.
This class provides a facility normalizeKey(String)
for modifying the requested key if necessary before ultimate retrieval via
getOptionalStringImpl(String)
. Most implementations will not need this facility, and will use the default implementation which uses the requested
key unmodified. In any case, the implementation must use the original key, not the normalized key, when delegating to the parent configuration, if any.
Constructor | Description |
---|---|
BaseConfiguration(Optional<Configuration> parentConfiguration) |
Parent configuration constructor.
|
Modifier and Type | Method | Description |
---|---|---|
protected String |
dereferenceString(String string) |
Evaluates and replaces any references in the given string.
|
protected Optional<String> |
getOptionalDereferencedString(String key) |
Implementation for ultimately retrieving a string parameter.
|
Optional<String> |
getOptionalString(String key) |
Retrieves a string parameter that may not be present.
|
protected abstract Optional<String> |
getOptionalStringImpl(String key) |
Implementation for ultimately retrieving a raw string parameter.
|
protected String |
normalizeKey(String key) |
Normalizes a requested key if required by this implementation.
|
getParentConfiguration, or
hasParameter
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getBoolean, getDouble, getInt, getLong, getOptionalBoolean, getOptionalDouble, getOptionalInt, getOptionalLong, getOptionalParameter, getOptionalPath, getOptionalUri, getParameter, getPath, getString, getUri, requireParameter, resolvePath
public BaseConfiguration(@Nonnull Optional<Configuration> parentConfiguration)
parentConfiguration
- The parent configuration for fallback lookup.NullPointerException
- if the given parent configuration is null
.public final Optional<String> getOptionalString(String key) throws ConfigurationException
TODO discuss dereferencing
This implementation normalizes the key usingnormalizeKey(String)
.key
- The parameter key.ConfigurationException
- if there is a parameter value stored in an invalid format.Format.format(Object)
protected final Optional<String> getOptionalDereferencedString(String key) throws ConfigurationException
This method must not fall back to parent configuration; only local strings must be returned.
This implementation delegates to getOptionalStringImpl(String)
.
key
- The parameter key.NullPointerException
- if the given key is null
.SecurityException
- If a security manager exists and it doesn't allow access to the specified parameter.ConfigurationException
- if an expression is not in the correct format, or if no parameter is associated with a key in an expression.protected String normalizeKey(@Nonnull String key)
null
.key
- The parameter key.protected abstract Optional<String> getOptionalStringImpl(String key) throws ConfigurationException
This method should usually be implemented but not called directly by other classes. Callers must invoke dereferenceString(String)
on the returned
string value.
The given parameter key is assumed to already be normalized, and should not be modified.
This method must not fall back to parent configuration; only local strings must be returned.
key
- The exact parameter key.NullPointerException
- if the given key is null
.SecurityException
- If a security manager exists and it doesn't allow access to the specified parameter.ConfigurationException
- if an expression is not in the correct format, or if no parameter is associated with a key in an expression.@Nonnull protected String dereferenceString(@Nonnull String string)
This method does not need to be called if the underlying configuration implementation already supports expression replacement.
string
- The string for which expressions should be evaluated.NullPointerException
- if the given string is null
.ConfigurationException
- if an expression is not in the correct format, or if no parameter is associated with a key in an expression.Copyright © 2018 GlobalMentor, Inc.. All rights reserved.