public abstract class AbstractConfiguration extends Object implements Configuration
Configuration
interface, used
to simplify writing implementations. This class checks the validity of
arguments to the getEntry
methods, checks that the result
matches the requested type, and wraps exceptions other than Error
or
ConfigurationException
in a
ConfigurationException
. Subclasses need to implement the getEntryInternal
method,
which supplies entry values, throws NoSuchEntryException
if no
matching entry is found, and performs any desired primitive conversions. The
getEntryInternal
method should return primitive values as
instances of AbstractConfiguration.Primitive
.Modifier and Type | Class and Description |
---|---|
static class |
AbstractConfiguration.Primitive
Represents the value of an entry with a primitive type.
|
NO_DATA, NO_DEFAULT
Modifier | Constructor and Description |
---|---|
protected |
AbstractConfiguration()
Creates an instance of this class.
|
Modifier and Type | Method and Description |
---|---|
Object |
getEntry(String component,
String name,
Class type)
Returns an object of the specified type created using the information in
the entry matching the specified component and name, which must be
found, and supplying no data.
|
Object |
getEntry(String component,
String name,
Class type,
Object defaultValue)
Returns an object of the specified type created using the information in
the entry matching the specified component and name, and supplying no
data, returning the default value if no matching entry is found and the
default value is not
Configuration.NO_DEFAULT . |
Object |
getEntry(String component,
String name,
Class type,
Object defaultValue,
Object data)
Returns an object of the specified type created using the information in
the entry matching the specified component and name, and using the
specified data (unless it is
Configuration.NO_DATA ), returning the default
value if no matching entry is found and the default value is not Configuration.NO_DEFAULT . |
protected abstract Object |
getEntryInternal(String component,
String name,
Class type,
Object data)
Returns an object created using the information in the entry matching
the specified component and name, and the specified data, for the
requested type.
|
protected static boolean |
validIdentifier(String name)
Checks if the argument is a valid Identifier, as defined in the
Java(TM) Language Specification.
|
protected static boolean |
validQualifiedIdentifier(String name)
Checks if the argument is a valid QualifiedIdentifier, as defined
in the Java Language Specification.
|
protected AbstractConfiguration()
public Object getEntry(String component, String name, Class type) throws ConfigurationException
type
is a primitive type,
then the result is returned as an instance of the associated wrapper
class. Repeated calls with the same arguments may or may not return the
identical object.
The default implementation checks that component
,
name
, and type
are not null
; that
component
is a valid qualified identifier; and that
name
is a valid identifier. It returns the result of
calling getEntryInternal
with the specified arguments, as well as Configuration.NO_DEFAULT
and Configuration.NO_DATA
, converting results of type AbstractConfiguration.Primitive
into the associated wrapper type. If the call throws an
exception other than an Error
or a ConfigurationException
, it throws a ConfigurationException
with the original exception as the cause.
getEntry
in interface Configuration
component
- the component being configuredname
- the name of the entry for the componenttype
- the type of the object to be returnedcomponent
and name
NoSuchEntryException
- if no matching entry is foundIllegalArgumentException
- if component
is not
null
and is not a valid QualifiedIdentifier, or if
name
is not null
and is not a valid
IdentifierNullPointerException
- if any argument is null
ConfigurationException
- if a matching entry is found but a
problem occurs creating the object for the entry, or if
type
is a reference type and the result for the matching
entry is not either null
or an instance of
type
, or if type
is a primitive type and the
result is not an instance of the associated wrapper class. Any
Error
thrown while creating the object is propagated to the
caller; it is not wrapped in a ConfigurationException
.Configuration.getEntry(String, String, Class, Object)
public Object getEntry(String component, String name, Class type, Object defaultValue) throws ConfigurationException
Configuration.NO_DEFAULT
. If type
is a
primitive type, then the result is returned as an instance of the
associated wrapper class. Repeated calls with the same arguments may or
may not return the identical object.
The default implementation checks that component
,
name
, and type
are not null
; that
component
is a valid qualified identifier; that
name
is a valid identifier; and that
defaultValue
is of the right type. It returns the result of
calling getEntryInternal
with the specified arguments, as well as Configuration.NO_DATA
, converting results of type AbstractConfiguration.Primitive
into the
associated wrapper type. If the call throws an exception other than an
Error
or a ConfigurationException
, it throws a
ConfigurationException
with the original exception as the
cause.
getEntry
in interface Configuration
component
- the component being configuredname
- the name of the entry for the componenttype
- the type of the object to be returneddefaultValue
- the object to return if no matching entry is found,
or NO_DEFAULT
to specify no defaultcomponent
and name
, or
defaultValue
if no matching entry is found and
defaultValue
is not NO_DEFAULT
NoSuchEntryException
- if no matching entry is found and
defaultValue
is NO_DEFAULT
IllegalArgumentException
- if component
is not
null
and is not a valid QualifiedIdentifier; or if
name
is not null
and is not a valid
Identifier; or if type
is a reference type and
defaultValue
is not NO_DEFAULT
,
null
, or an instance of type
; or if
type
is a primitive type and defaultValue
is
not NO_DEFAULT
or an instance of the associated wrapper
classNullPointerException
- if component
,
name
, or type
is null
ConfigurationException
- if a matching entry is found but a
problem occurs creating the object for the entry, or if
type
is a reference type and the result for the matching
entry is not either null
or an instance of
type
, or if type
is a primitive type and the
result is not an instance of the associated wrapper class. Any
Error
thrown while creating the object is propagated to the
caller; it is not wrapped in a ConfigurationException
.Configuration.getEntry(String, String, Class, Object, Object)
public Object getEntry(String component, String name, Class type, Object defaultValue, Object data) throws ConfigurationException
Configuration.NO_DATA
), returning the default
value if no matching entry is found and the default value is not Configuration.NO_DEFAULT
. If type
is a primitive type, then the result
is returned as an instance of the associated wrapper class. Repeated
calls with the same arguments may or may not return the identical
object.
The default implementation checks that component
,
name
, and type
are not null
; that
component
is a valid qualified identifier; that
name
is a valid identifier; and that
defaultValue
is of the right type. It returns the result of
calling getEntryInternal
with the specified arguments, converting results of
type AbstractConfiguration.Primitive
into the associated wrapper type. If the call
throws an exception other than an Error
or a ConfigurationException
, it throws a ConfigurationException
with the original exception as the cause.
getEntry
in interface Configuration
component
- the component being configuredname
- the name of the entry for the componenttype
- the type of the object to be returneddefaultValue
- the object to return if no matching entry is found,
or NO_DEFAULT
to specify no defaultdata
- an object to use when computing the value of the entry, or
NO_DATA
to specify no datacomponent
and name
, and using the value of
data
(unless it is NO_DATA
), or
defaultValue
if no matching entry is found and
defaultValue
is not NO_DEFAULT
NoSuchEntryException
- if no matching entry is found and
defaultValue
is NO_DEFAULT
IllegalArgumentException
- if component
is not
null
and is not a valid QualifiedIdentifier; or if
name
is not null
and is not a valid
Identifier; or if type
is a reference type and
defaultValue
is not NO_DEFAULT
,
null
, or an instance of type
; or if
type
is a primitive type and defaultValue
is
not NO_DEFAULT
or an instance of the associated wrapper
classNullPointerException
- if component
,
name
, or type
is null
ConfigurationException
- if a matching entry is found but a
problem occurs creating the object for the entry, or if
type
is a reference type and the result for the matching
entry is not either null
or an instance of
type
, or if type
is a primitive type and the
result is not an instance of the associated wrapper class. Any
Error
thrown while creating the object is propagated to the
caller; it is not wrapped in a ConfigurationException
.protected abstract Object getEntryInternal(String component, String name, Class type, Object data) throws ConfigurationException
AbstractConfiguration.Primitive
. Implementations may
use type
to perform conversions on primitive values, if
desired, but are not required to check if the object is of the requested
type. Repeated calls with the same arguments may or may not return the
identical object.
The default implementations of the getEntry
methods
delegate to this method; implementations can rely on the fact that calls
made to this method by those methods will have arguments that are not
null
and that have the correct syntax.
component
- the component being configuredname
- the name of the entry for the componenttype
- the type of object requesteddata
- an object to use when computing the value of the entry, or
Configuration.NO_DATA
to specify no datacomponent
and name
, and using the value of
data
(unless it is NO_DATA
)NoSuchEntryException
- if no matching entry is foundConfigurationException
- if a matching entry is found but a
problem occurs creating the object for the entryNullPointerException
- if component
,
name
, or type
is null
Configuration.getEntry
protected static boolean validIdentifier(String name)
name
- the name to checktrue
if name
is a valid
Identifier, else false
protected static boolean validQualifiedIdentifier(String name)
name
- the name to checktrue
if name
is a valid
QualifiedIdentifier, else false