Class AbstractConfiguration
- All Implemented Interfaces:
Configuration
- Direct Known Subclasses:
ConfigurationFile,EmptyConfiguration,PlainConfiguration
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.- Since:
- 2.0
This implementation uses the
Loggernamednet.jini.configto log information at the following logging levels:net.jini.configLevel Description FINEproblems getting entries, including getting entries that are not found FINEreturning default values FINERgetting existing entries - Author:
- Sun Microsystems, Inc.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classRepresents the value of an entry with a primitive type. -
Field Summary
Fields inherited from interface net.jini.config.Configuration
NO_DATA, NO_DEFAULT -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedCreates an instance of this class. -
Method Summary
Modifier and TypeMethodDescriptionReturns 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.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 notConfiguration.NO_DEFAULT.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 isConfiguration.NO_DATA), returning the default value if no matching entry is found and the default value is notConfiguration.NO_DEFAULT.protected abstract ObjectgetEntryInternal(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 booleanvalidIdentifier(String name) Checks if the argument is a valid Identifier, as defined in the Java(TM) Language Specification.protected static booleanChecks if the argument is a valid QualifiedIdentifier, as defined in the Java Language Specification.
-
Constructor Details
-
AbstractConfiguration
protected AbstractConfiguration()Creates an instance of this class.
-
-
Method Details
-
getEntry
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. Iftypeis 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, andtypeare notnull; thatcomponentis a valid qualified identifier; and thatnameis a valid identifier. It returns the result of callinggetEntryInternalwith the specified arguments, as well asConfiguration.NO_DEFAULTandConfiguration.NO_DATA, converting results of typeAbstractConfiguration.Primitiveinto the associated wrapper type. If the call throws an exception other than anErroror aConfigurationException, it throws aConfigurationExceptionwith the original exception as the cause.- Specified by:
getEntryin interfaceConfiguration- Parameters:
component- the component being configuredname- the name of the entry for the componenttype- the type of the object to be returned- Returns:
- an object created using the information in the entry matching
componentandname - Throws:
NoSuchEntryException- if no matching entry is foundIllegalArgumentException- ifcomponentis notnulland is not a valid QualifiedIdentifier, or ifnameis notnulland is not a valid IdentifierNullPointerException- if any argument isnullConfigurationException- if a matching entry is found but a problem occurs creating the object for the entry, or iftypeis a reference type and the result for the matching entry is not eithernullor an instance oftype, or iftypeis a primitive type and the result is not an instance of the associated wrapper class. AnyErrorthrown while creating the object is propagated to the caller; it is not wrapped in aConfigurationException.- See Also:
-
getEntry
public Object getEntry(String component, String name, Class type, Object defaultValue) throws ConfigurationException 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 notConfiguration.NO_DEFAULT. Iftypeis 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, andtypeare notnull; thatcomponentis a valid qualified identifier; thatnameis a valid identifier; and thatdefaultValueis of the right type. It returns the result of callinggetEntryInternalwith the specified arguments, as well asConfiguration.NO_DATA, converting results of typeAbstractConfiguration.Primitiveinto the associated wrapper type. If the call throws an exception other than anErroror aConfigurationException, it throws aConfigurationExceptionwith the original exception as the cause.- Specified by:
getEntryin interfaceConfiguration- Parameters:
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, orNO_DEFAULTto specify no default- Returns:
- an object created using the information in the entry matching
componentandname, ordefaultValueif no matching entry is found anddefaultValueis notNO_DEFAULT - Throws:
NoSuchEntryException- if no matching entry is found anddefaultValueisNO_DEFAULTIllegalArgumentException- ifcomponentis notnulland is not a valid QualifiedIdentifier; or ifnameis notnulland is not a valid Identifier; or iftypeis a reference type anddefaultValueis notNO_DEFAULT,null, or an instance oftype; or iftypeis a primitive type anddefaultValueis notNO_DEFAULTor an instance of the associated wrapper classNullPointerException- ifcomponent,name, ortypeisnullConfigurationException- if a matching entry is found but a problem occurs creating the object for the entry, or iftypeis a reference type and the result for the matching entry is not eithernullor an instance oftype, or iftypeis a primitive type and the result is not an instance of the associated wrapper class. AnyErrorthrown while creating the object is propagated to the caller; it is not wrapped in aConfigurationException.- See Also:
-
getEntry
public Object getEntry(String component, String name, Class type, Object defaultValue, Object data) throws ConfigurationException 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 isConfiguration.NO_DATA), returning the default value if no matching entry is found and the default value is notConfiguration.NO_DEFAULT. Iftypeis 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, andtypeare notnull; thatcomponentis a valid qualified identifier; thatnameis a valid identifier; and thatdefaultValueis of the right type. It returns the result of callinggetEntryInternalwith the specified arguments, converting results of typeAbstractConfiguration.Primitiveinto the associated wrapper type. If the call throws an exception other than anErroror aConfigurationException, it throws aConfigurationExceptionwith the original exception as the cause.- Specified by:
getEntryin interfaceConfiguration- Parameters:
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, orNO_DEFAULTto specify no defaultdata- an object to use when computing the value of the entry, orNO_DATAto specify no data- Returns:
- an object created using the information in the entry matching
componentandname, and using the value ofdata(unless it isNO_DATA), ordefaultValueif no matching entry is found anddefaultValueis notNO_DEFAULT - Throws:
NoSuchEntryException- if no matching entry is found anddefaultValueisNO_DEFAULTIllegalArgumentException- ifcomponentis notnulland is not a valid QualifiedIdentifier; or ifnameis notnulland is not a valid Identifier; or iftypeis a reference type anddefaultValueis notNO_DEFAULT,null, or an instance oftype; or iftypeis a primitive type anddefaultValueis notNO_DEFAULTor an instance of the associated wrapper classNullPointerException- ifcomponent,name, ortypeisnullConfigurationException- if a matching entry is found but a problem occurs creating the object for the entry, or iftypeis a reference type and the result for the matching entry is not eithernullor an instance oftype, or iftypeis a primitive type and the result is not an instance of the associated wrapper class. AnyErrorthrown while creating the object is propagated to the caller; it is not wrapped in aConfigurationException.
-
getEntryInternal
protected abstract Object getEntryInternal(String component, String name, Class type, Object data) throws ConfigurationException Returns an object created using the information in the entry matching the specified component and name, and the specified data, for the requested type. If the entry value is a primitive, then the object returned should be an instance ofAbstractConfiguration.Primitive. Implementations may usetypeto 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
getEntrymethods delegate to this method; implementations can rely on the fact that calls made to this method by those methods will have arguments that are notnulland that have the correct syntax.- Parameters:
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, orConfiguration.NO_DATAto specify no data- Returns:
- an object created using the information in the entry matching
componentandname, and using the value ofdata(unless it isNO_DATA) - Throws:
NoSuchEntryException- if no matching entry is foundConfigurationException- if a matching entry is found but a problem occurs creating the object for the entryNullPointerException- ifcomponent,name, ortypeisnull- See Also:
-
validIdentifier
Checks if the argument is a valid Identifier, as defined in the Java(TM) Language Specification.- Parameters:
name- the name to check- Returns:
trueifnameis a valid Identifier, elsefalse
-
validQualifiedIdentifier
Checks if the argument is a valid QualifiedIdentifier, as defined in the Java Language Specification.- Parameters:
name- the name to check- Returns:
trueifnameis a valid QualifiedIdentifier, elsefalse
-