Class AbstractConfiguration

java.lang.Object
net.jini.config.AbstractConfiguration
All Implemented Interfaces:
Configuration
Direct Known Subclasses:
ConfigurationFile, EmptyConfiguration, PlainConfiguration

public abstract class AbstractConfiguration extends Object implements Configuration
A skeletal implementation of the 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 Logger named net.jini.config to log information at the following logging levels:

net.jini.config
Level Description
FINE problems getting entries, including getting entries that are not found
FINE returning default values
FINER getting existing entries
Author:
Sun Microsystems, Inc.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static final class 
    Represents 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

    Constructors
    Modifier
    Constructor
    Description
    protected
    Creates an instance of this class.
  • Method Summary

    Modifier and Type
    Method
    Description
    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.
    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.
    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
    Checks if the argument is a valid Identifier, as defined in the Java(TM) Language Specification.
    protected static boolean
    Checks if the argument is a valid QualifiedIdentifier, as defined in the Java Language Specification.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • AbstractConfiguration

      protected AbstractConfiguration()
      Creates an instance of this class.
  • Method Details

    • getEntry

      public Object getEntry(String component, String name, Class type) throws ConfigurationException
      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. 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; 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.

      Specified by:
      getEntry in interface Configuration
      Parameters:
      component - the component being configured
      name - the name of the entry for the component
      type - the type of the object to be returned
      Returns:
      an object created using the information in the entry matching component and name
      Throws:
      NoSuchEntryException - if no matching entry is found
      IllegalArgumentException - if component is not null and is not a valid QualifiedIdentifier, or if name is not null and is not a valid Identifier
      NullPointerException - 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.
      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 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, 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.

      Specified by:
      getEntry in interface Configuration
      Parameters:
      component - the component being configured
      name - the name of the entry for the component
      type - the type of the object to be returned
      defaultValue - the object to return if no matching entry is found, or NO_DEFAULT to specify no default
      Returns:
      an object created using the information in the entry matching component and name, or defaultValue if no matching entry is found and defaultValue is not NO_DEFAULT
      Throws:
      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 class
      NullPointerException - 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.
      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 is 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.

      Specified by:
      getEntry in interface Configuration
      Parameters:
      component - the component being configured
      name - the name of the entry for the component
      type - the type of the object to be returned
      defaultValue - the object to return if no matching entry is found, or NO_DEFAULT to specify no default
      data - an object to use when computing the value of the entry, or NO_DATA to specify no data
      Returns:
      an object created using the information in the entry matching component 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
      Throws:
      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 class
      NullPointerException - 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.
    • 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 of 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.

      Parameters:
      component - the component being configured
      name - the name of the entry for the component
      type - the type of object requested
      data - an object to use when computing the value of the entry, or Configuration.NO_DATA to specify no data
      Returns:
      an object created using the information in the entry matching component and name, and using the value of data (unless it is NO_DATA)
      Throws:
      NoSuchEntryException - if no matching entry is found
      ConfigurationException - if a matching entry is found but a problem occurs creating the object for the entry
      NullPointerException - if component, name, or type is null
      See Also:
    • validIdentifier

      protected static boolean validIdentifier(String name)
      Checks if the argument is a valid Identifier, as defined in the Java(TM) Language Specification.
      Parameters:
      name - the name to check
      Returns:
      true if name is a valid Identifier, else false
    • validQualifiedIdentifier

      protected static boolean validQualifiedIdentifier(String name)
      Checks if the argument is a valid QualifiedIdentifier, as defined in the Java Language Specification.
      Parameters:
      name - the name to check
      Returns:
      true if name is a valid QualifiedIdentifier, else false