SolarMetric Kodo JDO 3.2.4 generated on January 7 2005

com.solarmetric.conf
Class ConfigurationImpl

java.lang.Object
  |
  +--com.solarmetric.conf.ConfigurationImpl
All Implemented Interfaces:
BeanInfo, com.solarmetric.util.Closeable, Configuration, Externalizable, Serializable
Direct Known Subclasses:
JDOConfigurationImpl

public class ConfigurationImpl
extends Object
implements Configuration, Externalizable

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:

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().
 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()
           
 PropertyChangeSupport getChangeSupport()
          Change support to listen for changes to any of the properties.
 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 a Value for a given property.
 Value[] getValues()
          Return the set of all Values.
 int hashCode()
          Computes hash code based on the properties returned from toProperties().
 boolean isCaching()
          Return whether Properties conversions are cached.
 boolean isFrozen()
          Return true if the 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 setCaching(boolean caching)
          Set whether to optimize Properties conversion by caching Value states.
 void setChangeSupport(PropertyChangeSupport changeSupport)
          Add change support to listen for changes to any of the properties.
 void setFrozen(boolean frozen)
          Following a call to this method, calls to assertNotFrozen() will throw an exception.
 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()
          Properties objects are cached once created so that calls to this method are relatively cheap (the properties object is still cloned for each call).
 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 writeExternal(ObjectOutput out)
          Implementation of the Externalizable interface to write the properties returned by toProperties().
 
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

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()

getValue

public Value getValue(String property)
Description copied from interface: Configuration
Return a Value for a given property.
Specified by:
getValue in interface Configuration

getValues

public Value[] getValues()
Description copied from interface: Configuration
Return the set of all Values.
Specified by:
getValues 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

close

public void close()
Description copied from interface: Configuration
Free the resources used by this object.
Specified by:
close in interface Configuration

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)

setCaching

public void setCaching(boolean caching)
Description copied from interface: Configuration
Set whether to optimize Properties conversion by caching Value states.
Specified by:
setCaching in interface Configuration

isCaching

public boolean isCaching()
Description copied from interface: Configuration
Return whether Properties conversions are cached.
Specified by:
isCaching in interface Configuration

setFrozen

public void setFrozen(boolean frozen)
Following a call to this method, calls to assertNotFrozen() will throw an exception. This method is meant to lock down the configuration; subclasses should therefore call assertNotFrozen() as the first line in all mutator methods.
Specified by:
setFrozen in interface Configuration

isFrozen

public boolean isFrozen()
Return true if the configuration has been frozen.
Specified by:
isFrozen in interface Configuration

toProperties

public Properties toProperties()
Properties objects are cached once created so that calls to this method are relatively cheap (the properties object is still cloned for each call). The cached instance is cleared on calls to assertNotFrozen(), because it precedes all state changes.
Specified by:
toProperties in interface Configuration
See Also:
Configuration.toProperties()

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). The cached instance is cleared on calls to assertNotFrozen(), because it precedes all state changes.
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()

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.

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

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().
Overrides:
equals in class Object

hashCode

public int hashCode()
Computes hash code based on the properties returned from toProperties().
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().
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.

setChangeSupport

public void setChangeSupport(PropertyChangeSupport changeSupport)
Add change support to listen for changes to any of the properties.

getChangeSupport

public PropertyChangeSupport getChangeSupport()
Change support to listen for changes to any of the properties.

addPropertyChangeListener

public void addPropertyChangeListener(PropertyChangeListener listener)
Description copied from interface: Configuration
Adds a listener for any property changes.
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

SolarMetric Kodo JDO 3.2.4 generated on January 7 2005

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