Overview | Package | Class | Tree | Deprecated | Index | Help
| SolarMetric Kodo JDO 3.3.5 generated on August 31 2005
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## com.solarmetric.conf
Class ConfigurationImpl

    java.lang.Object
      |
      +--com.solarmetric.conf.ConfigurationImpl

All Implemented Interfaces:
  BeanInfo, com.solarmetric.util.Closeable, Configuration, Externalizable, Serializable, ValueListener

Direct Known Subclasses:
  JDOConfigurationImpl

public class ConfigurationImpl
extends Object
implements Configuration, Externalizable, ValueListener

Default implementation of the `Configuration` interface. Subclasses can choose to obtain configuration information from JNDI, Properties, a Bean-builder, etc. This class provides base configuration functionality, including serialization, the `equals` and `hashCode` contracts, and default property loading.

On construction, the class will attempt to locate a default properties file called `solarmetric.properties` located at any top level token of the CLASSPATH. The name of the properties file can be overridden.

Subclasses should be sure to pass in `false` to the constructor when they call it, then call `loadDefaults()` themselves if they want to load default properties. Otherwise, their field initializations will overwrite the defaults that were loaded.

Property descriptors for `Value` instances are constructed from the `Localizer` for the package of the configuration class. The following localized strings will be used for describing a value, where name is the last token of the value's property string:

- name-name: The name that will be displayed for the option in a user interface; required.
- name-desc: A brief description of the option; required.
- name-type: The type or category name for this option; required.
- name-expert: True if this is an expert option, false otherwise; defaults to false.
- name-values: Set of expected or common values, excluding alias keys; optional.
- name-interface: The class name of an interface whose discoverable implementations should be included in the set of expected or common values; optional.
- name-cat: The hierarchical category for the property name, separated by ".".
- name-displayorder: The order in which the property should be displayer.

See Also:
  Serialized Form

Field Summary
`protected LogFactory` | `logFactory`

Fields inherited from interface com.solarmetric.conf.Configuration
`ATTRIBUTE_ALLOWED_VALUES, ATTRIBUTE_CATEGORY, ATTRIBUTE_ORDER, ATTRIBUTE_TYPE`

Fields inherited from interface java.beans.BeanInfo
`ICON_COLOR_16x16, ICON_COLOR_32x32, ICON_MONO_16x16, ICON_MONO_32x32`

Constructor Summary
`ConfigurationImpl()` Default constructor.
`ConfigurationImpl(boolean loadDefaults)` Constructor.

Method Summary
`protected BooleanValue` | `addBoolean(String property)` Add the given value to the set of configuration properties.
`protected DoubleValue` | `addDouble(String property)` Add the given value to the set of configuration properties.
`protected FileValue` | `addFile(String property)` Add the given value to the set of configuration properties.
`protected IntValue` | `addInt(String property)` Add the given value to the set of configuration properties.
`protected PluginValue` | `addPlugin(String property)` Add the given value to the set of configuration properties.
`protected PluginListValue` | `addPluginList(String property)` Add the given value to the set of configuration properties.
`void` | `addPropertyChangeListener(PropertyChangeListener listener)` Adds a listener for any property changes.
`protected StringValue` | `addString(String property)` Add the given value to the set of configuration properties.
`protected StringListValue` | `addStringList(String property)` Add the given value to the set of configuration properties.
`protected Value` | `addValue(Value val)` Add the given value to the set of configuration properties.
`protected void` | `assertNotFrozen()` Checks if the configuration has been frozen and if so throws a `IllegalStateException`, otherwise returns silently.
`void` | `close()` Free the resources used by this object.
`boolean` | `equals(Object other)` Performs an equality check based on the properties returned from `toProperties(boolean)`.
`void` | `fromProperties(Properties props)` Fill in values from the given properties instance.
`void` | `fromStream(InputStream in)` Fill in properties from the given properties input stream.
`BeanInfo[]` | `getAdditionalBeanInfo()`
`BeanDescriptor` | `getBeanDescriptor()`
`RuntimeException` | `getConfigurationException(String msg, Throwable cause)` Throws a standard or nestable runtime exception by default.
`Log` | `getConfigurationLog()` Reutrns the logging channel `com.solarmetric.Runtime` by default.
`int` | `getDefaultEventIndex()`
`int` | `getDefaultPropertyIndex()`
`EventSetDescriptor[]` | `getEventSetDescriptors()`
`Image` | `getIcon(int kind)`
`Log` | `getLog(String category)` Return the log for the given category.
`LogFactory` | `getLogFactory()` The log factory.
`MethodDescriptor[]` | `getMethodDescriptors()`
`protected String` | `getProductName()` Return the product name.
`PropertyDescriptor[]` | `getPropertyDescriptors()`
`Value` | `getValue(String property)` Return the `Value` for the given property, or null if none.
`Value[]` | `getValues()` Return the set of all `Value`s.
`int` | `hashCode()` Computes hash code based on the properties returned from `toProperties(boolean)`.
`boolean` | `hasJava5()` Return `true` if this VM has Java 5 features; otherwise returns `false`.
`boolean` | `isFrozen()` Return true if this Configuration has been frozen.
`protected boolean` | `isInvalidProperty(String propName)` Returns true if the specified property name should raise a warning if it is not found in the list of known properties.
`boolean` | `loadDefaults()` Invoke this method to load default values from properties.
`void` | `readExternal(ObjectInput in)` Implementation of the `Externalizable` interface to read from the properties written by `writeExternal(java.io.ObjectOutput)`.
`void` | `removePropertyChangeListener(PropertyChangeListener listener)` Removes a listener for any property changes.
`void` | `setFrozen(boolean frozen)` Lock down the configuration's state.
`void` | `setLogFactory(LogFactory logFactory)` log factory.
`void` | `setProperties(String resourceName)` This method loads the named resource as a properties file.
`void` | `setPropertiesFile(File file)` This method loads the named file as a properties file.
`Properties` | `toProperties(boolean storeDefaults)` Properties objects are cached once created so that calls to this method are relatively cheap (the properties object is still cloned for each call).
`void` | `valueChanged(Value val)` Callback used by `Value` objects to notify listener of change.
`void` | `writeExternal(ObjectOutput out)` Implementation of the `Externalizable` interface to write the properties returned by `toProperties(boolean)`.

Methods inherited from class java.lang.Object
`clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### logFactory

    protected LogFactory logFactory

Constructor Detail

### ConfigurationImpl

    public ConfigurationImpl()

  Default constructor. Attempts to load default properties from the `solarmetric.properties` resource. Override the `getProductName()` method to change the name of the default properties resource.

### ConfigurationImpl

    public ConfigurationImpl(boolean loadDefaults)

  Constructor.
  Parameters:
    `loadDefaults` - whether to attempt to load the default `solarmetric.properties` resource

Method Detail

### getProductName

    protected String getProductName()

  Return the product name. Defaults to `solarmetric`.
  See Also:
    `loadDefaults()`

### loadDefaults

    public boolean loadDefaults()

  Invoke this method to load default values from properties. The method will first check the `<product-name>.properties` system property for the location of a properties file to parse, where `product-name` is the return value of the `getProductName()` method. If no system property is defined, the default resource location of `<product-name>.properties` is used. If it exists, the resource is parsed as a properties file. All system properties are then added; they override any same-named properties in the resource. The combined properties are then loaded into this configuration.
  Returns:
    true if a properties resource was found, false otherwise
  See Also:
    `ClassLoader.getResource(java.lang.String)`

### setLogFactory

    public void setLogFactory(LogFactory logFactory)

  Description copied from interface: `Configuration`
  log factory.
  Specified by:
    `setLogFactory` in interface `Configuration`

### getLogFactory

    public LogFactory getLogFactory()

  Description copied from interface: `Configuration`
  The log factory. If no log factory has been set explicitly, this method will create one.
  Specified by:
    `getLogFactory` in interface `Configuration`

### getLog

    public Log getLog(String category)

  Description copied from interface: `Configuration`
  Return the log for the given category.
  Specified by:
    `getLog` in interface `Configuration`
  Following copied from interface: `com.solarmetric.conf.Configuration`
  See Also:
    `Configuration.getLogFactory()`

### getValues

    public Value[] getValues()

  Description copied from interface: `Configuration`
  Return the set of all `Value`s.
  Specified by:
    `getValues` in interface `Configuration`

### getValue

    public Value getValue(String property)

  Description copied from interface: `Configuration`
  Return the `Value` for the given property, or null if none.
  Specified by:
    `getValue` in interface `Configuration`

### setFrozen

    public void setFrozen(boolean frozen)

  Description copied from interface: `Configuration`
  Lock down the configuration's state. Attempting to set state after a configuration has been frozen results in a `IllegalStateException`.
  Specified by:
    `setFrozen` in interface `Configuration`

### isFrozen

    public boolean isFrozen()

  Description copied from interface: `Configuration`
  Return true if this Configuration has been frozen.
  Specified by:
    `isFrozen` in interface `Configuration`

### addPropertyChangeListener

    public void addPropertyChangeListener(PropertyChangeListener listener)

  Description copied from interface: `Configuration`
  Adds a listener for any property changes. The property events fired will not include the old value.
  Specified by:
    `addPropertyChangeListener` in interface `Configuration`
  Following copied from interface: `com.solarmetric.conf.Configuration`
  Parameters:
    `listener` - the listener to receive notification of property changes

### removePropertyChangeListener

    public void removePropertyChangeListener(PropertyChangeListener listener)

  Description copied from interface: `Configuration`
  Removes a listener for any property changes.
  Specified by:
    `removePropertyChangeListener` in interface `Configuration`
  Following copied from interface: `com.solarmetric.conf.Configuration`
  Parameters:
    `listener` - the listener to remove

### valueChanged

    public void valueChanged(Value val)

  Description copied from interface: `ValueListener`
  Callback used by `Value` objects to notify listener of change.
  Specified by:
    `valueChanged` in interface `ValueListener`

### close

    public void close()

  Description copied from interface: `Configuration`
  Free the resources used by this object.
  Specified by:
    `close` in interface `Configuration`

### getAdditionalBeanInfo

    public BeanInfo[] getAdditionalBeanInfo()

  Specified by:
    `getAdditionalBeanInfo` in interface `BeanInfo`

### getBeanDescriptor

    public BeanDescriptor getBeanDescriptor()

  Specified by:
    `getBeanDescriptor` in interface `BeanInfo`

### getDefaultEventIndex

    public int getDefaultEventIndex()

  Specified by:
    `getDefaultEventIndex` in interface `BeanInfo`

### getDefaultPropertyIndex

    public int getDefaultPropertyIndex()

  Specified by:
    `getDefaultPropertyIndex` in interface `BeanInfo`

### getEventSetDescriptors

    public EventSetDescriptor[] getEventSetDescriptors()

  Specified by:
    `getEventSetDescriptors` in interface `BeanInfo`

### getIcon

    public Image getIcon(int kind)

  Specified by:
    `getIcon` in interface `BeanInfo`

### getMethodDescriptors

    public MethodDescriptor[] getMethodDescriptors()

  Specified by:
    `getMethodDescriptors` in interface `BeanInfo`

### getPropertyDescriptors

    public PropertyDescriptor[] getPropertyDescriptors()

  Specified by:
    `getPropertyDescriptors` in interface `BeanInfo`

### toProperties

    public Properties toProperties(boolean storeDefaults)

  Properties objects are cached once created so that calls to this method are relatively cheap (the properties object is still cloned for each call).
  Specified by:
    `toProperties` in interface `Configuration`
  Parameters:
    `storeDefaults` - if false, then property values that are equal to the default value for a configuration will not be stored
  See Also:
    `Configuration.toProperties(boolean)`

### fromProperties

    public void fromProperties(Properties props)

  Fill in values from the given properties instance.
  Specified by:
    `fromProperties` in interface `Configuration`

### isInvalidProperty

    protected boolean isInvalidProperty(String propName)

  Returns true if the specified property name should raise a warning if it is not found in the list of known properties.

### fromStream

    public void fromStream(InputStream in)
                    throws IOException

  Fill in properties from the given properties input stream.

### setProperties

    public void setProperties(String resourceName)
                       throws IOException

  This method loads the named resource as a properties file. It is useful for auto-configuration tools so users can specify a `properties` value with the name of a resource.

### setPropertiesFile

    public void setPropertiesFile(File file)
                           throws IOException

  This method loads the named file as a properties file. It is useful for auto-configuration tools so users can specify a `propertiesFile` value with the name of a file.

### assertNotFrozen

    protected void assertNotFrozen()

  Checks if the configuration has been frozen and if so throws a `IllegalStateException`, otherwise returns silently. Implementations should call this method before setting any state.

### equals

    public boolean equals(Object other)

  Performs an equality check based on the properties returned from `toProperties(boolean)`.
  Overrides:
    `equals` in class `Object`

### hashCode

    public int hashCode()

  Computes hash code based on the properties returned from `toProperties(boolean)`.
  Overrides:
    `hashCode` in class `Object`

### readExternal

    public void readExternal(ObjectInput in)
                      throws IOException,
                             ClassNotFoundException

  Implementation of the `Externalizable` interface to read from the properties written by `writeExternal(java.io.ObjectOutput)`.
  Specified by:
    `readExternal` in interface `Externalizable`

### writeExternal

    public void writeExternal(ObjectOutput out)
                       throws IOException

  Implementation of the `Externalizable` interface to write the properties returned by `toProperties(boolean)`.
  Specified by:
    `writeExternal` in interface `Externalizable`

### addValue

    protected Value addValue(Value val)

  Add the given value to the set of configuration properties.

### addString

    protected StringValue addString(String property)

  Add the given value to the set of configuration properties.

### addFile

    protected FileValue addFile(String property)

  Add the given value to the set of configuration properties.

### addInt

    protected IntValue addInt(String property)

  Add the given value to the set of configuration properties.

### addDouble

    protected DoubleValue addDouble(String property)

  Add the given value to the set of configuration properties.

### addBoolean

    protected BooleanValue addBoolean(String property)

  Add the given value to the set of configuration properties.

### addStringList

    protected StringListValue addStringList(String property)

  Add the given value to the set of configuration properties.

### addPlugin

    protected PluginValue addPlugin(String property)

  Add the given value to the set of configuration properties.

### addPluginList

    protected PluginListValue addPluginList(String property)

  Add the given value to the set of configuration properties.

### getConfigurationLog

    public Log getConfigurationLog()

  Reutrns the logging channel `com.solarmetric.Runtime` by default.
  Specified by:
    `getConfigurationLog` in interface `Configuration`

### getConfigurationException

    public RuntimeException getConfigurationException(String msg,
                                                      Throwable cause)

  Throws a standard or nestable runtime exception by default.
  Specified by:
    `getConfigurationException` in interface `Configuration`

### hasJava5

    public boolean hasJava5()

  Description copied from interface: `Configuration`
  Return `true` if this VM has Java 5 features; otherwise returns `false`.
  Specified by:
    `hasJava5` in interface `Configuration`

Overview | Package | Class | Tree | Deprecated | Index | Help
| SolarMetric Kodo JDO 3.3.5 generated on August 31 2005
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright 2001,2002 SolarMetric, Inc. All Rights Reserved.