com.tomgibara.pronto.config.source
Class PreferencesConfigSource

java.lang.Object
  extended by com.tomgibara.pronto.config.source.PreferencesConfigSource
All Implemented Interfaces:
ConfigSource

public class PreferencesConfigSource
extends java.lang.Object
implements ConfigSource

A configuration source which draws its properties from a Preferences node. As per the ConfigSource interface, all properties are exposed as strings. The properties of descendant preference nodes are represented in the property map under the dot delimited combination of the descendant node names and the property name. If the startListening() method is called, the source will monitor the preferences for changes until the stopListening() method is called. Note that, as per the Preference API specification, changes to preferences will typically need to be flushed before events that this object can observe will be reported. This source is safe for multithreaded use.

Author:
Tom Gibara

Constructor Summary
PreferencesConfigSource(java.util.prefs.Preferences preferences)
          Create a configuration source which draws its properties from the supplied preferences node.
 
Method Summary
 java.util.prefs.Preferences getPreferences()
          The preferences which are used to generate the properties for this source.
 java.util.Map<java.lang.String,java.lang.String> getProperties()
          The properties obtained from the preferences node.
 long lastModified()
          The time at which the properties returned by this property source, were last known to have changed.
 void startListening()
          Causes this source to start listening for property changes and node changes to the preference node.
 void stopListening()
          Causes this source to stop listening for changes to the property values.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PreferencesConfigSource

public PreferencesConfigSource(java.util.prefs.Preferences preferences)
Create a configuration source which draws its properties from the supplied preferences node.

Parameters:
preferences - a node containing configuration information, not null
Method Detail

lastModified

public long lastModified()
                  throws ProntoConfigException
The time at which the properties returned by this property source, were last known to have changed. This will be constant if this source is not listening to changes in the preferences.

Specified by:
lastModified in interface ConfigSource
Returns:
the time at which the node's properties, descendent nodes, or their properties were last known to have changed
Throws:
ProntoConfigException - if an exception occurs accessing the preferences backing store.

getProperties

public java.util.Map<java.lang.String,java.lang.String> getProperties()
                                                               throws ProntoConfigException
The properties obtained from the preferences node. This includes the properties of descendant nodes as described in the class documentation.

Specified by:
getProperties in interface ConfigSource
Returns:
the properties obtained from the preferences node
Throws:
ProntoConfigException - if an exception occurs accessing the preferences backing store.

getPreferences

public java.util.prefs.Preferences getPreferences()
The preferences which are used to generate the properties for this source.

Returns:
the preferences node with which this object was constructed

startListening

public void startListening()
                    throws ProntoConfigException
Causes this source to start listening for property changes and node changes to the preference node. If this source is already listening for such changes, then this method does nothing.

Throws:
ProntoConfigException - if an exception occurs accessing the preferences backing store.

stopListening

public void stopListening()
                   throws ProntoConfigException
Causes this source to stop listening for changes to the property values. If this source is not listening for changes, then no action is performed.

Throws:
ProntoConfigException - if an exception occurs accessing the preferences backing store.


Copyright © 2006-2007 Tom Gibara. All Rights Reserved.