org.crosswire.common.config
Class Config

java.lang.Object
  extended by org.crosswire.common.config.Config
All Implemented Interfaces:
Iterable<Choice>

public class Config
extends Object
implements Iterable<Choice>

Config is the core part of the configuration system; it is simply a Collection of Choices. Config does the following things:

Config does not attempt to make permanent copies of the config data because different applications may wish to store the data in different ways. Possible storage mechanisms include: The Config class stored the current Choices, and moves the data between the various places that it is stored. There are 4 storage areas:

Author:
Joe Walker
See Also:
The GNU Lesser General Public License for details.

Field Summary
protected  PropertyChangeSupport changeListeners
          The set of property change listeners.
protected  List<String> keys
          The array that stores the keys
protected  List<ConfigListener> listeners
          The list of listeners
protected  PropertyMap local
          The set of local values
private static org.slf4j.Logger LOGGER
          The log stream
protected  List<Choice> models
          The array that stores the models
protected  String title
          The name for dialog boxes and properties files
 
Constructor Summary
Config(String title)
          Config ctor
 
Method Summary
 void add(Choice model)
          Add a key/model pairing
 void add(org.jdom2.Document xmlconfig, ResourceBundle configResources)
          Add the set of configuration options specified in the xml file.
 void addConfigListener(ConfigListener li)
          Add an Exception listener to the list of things wanting to know whenever we capture an Exception.
 void addPropertyChangeListener(PropertyChangeListener listener)
          Add a PropertyChangeListener to the listener list.
 void addPropertyChangeListener(String propertyName, PropertyChangeListener listener)
          Add a PropertyChangeListener for a specific property.
 void applicationToLocal()
          Take the data in the application and copy it to the local storage area.
protected  void fireChoiceAdded(String key, Choice model)
          A Choice got added.
protected  void fireChoiceRemoved(String key, Choice model)
          A Choice got removed.
 Choice getChoice(String key)
          Get the Choice for a given key
static String getLeaf(String key)
          What is the last part of the Path of this key.
 String getLocal(String name)
          Get a configuration Choice (by name).
static String getPath(String key)
          What is the Path of this key
 PropertyMap getProperties()
          Take the data in the local storage area and store it permanently.
 String getTitle()
          The name for the dialog boxes and properties files.
 Iterator<Choice> iterator()
          The set of Choice that we are controlling
 void localToApplication()
          Take the data in the local storage area and copy it to the application.
 void localToPermanent(URI uri)
          Take the data in the local storage area and store it permanently, using the configured storage area.
 void permanentToLocal(URI uri)
          Take the data stored permanently and copy it to the local storage area, using the configured storage area
 void remove(String key)
          Remove a key/model pairing
 void removeConfigListener(ConfigListener li)
          Remove an Exception listener from the list of things wanting to know whenever we capture an Exception
 void removePropertyChangeListener(PropertyChangeListener listener)
          Remove a PropertyChangeListener from the listener list.
 void removePropertyChangeListener(String propertyName, PropertyChangeListener listener)
          Remove a PropertyChangeListener for a specific property.
 void setLocal(String name, String value)
          Set a configuration Choice (by name) to a new value.
 void setProperties(PropertyMap prop)
          Take the data stored permanently and copy it to the local storage area, using the specified stream.
 int size()
          The number of Choices
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

title

protected String title
The name for dialog boxes and properties files


keys

protected List<String> keys
The array that stores the keys


models

protected List<Choice> models
The array that stores the models


local

protected PropertyMap local
The set of local values


changeListeners

protected PropertyChangeSupport changeListeners
The set of property change listeners.


listeners

protected List<ConfigListener> listeners
The list of listeners


LOGGER

private static final org.slf4j.Logger LOGGER
The log stream

Constructor Detail

Config

public Config(String title)
Config ctor

Parameters:
title - The name for dialog boxes and properties files
Method Detail

getTitle

public String getTitle()
The name for the dialog boxes and properties files.

Returns:
the title for this config

add

public void add(Choice model)
Add a key/model pairing

Parameters:
model - The Choice model to map to its key

add

public void add(org.jdom2.Document xmlconfig,
                ResourceBundle configResources)
Add the set of configuration options specified in the xml file.

Parameters:
xmlconfig - The JDOM document to read.
configResources - contains the user level text for this config

remove

public void remove(String key)
Remove a key/model pairing

Parameters:
key - The name to kill

iterator

public Iterator<Choice> iterator()
The set of Choice that we are controlling

Specified by:
iterator in interface Iterable<Choice>
Returns:
An iterator over the choices

getChoice

public Choice getChoice(String key)
Get the Choice for a given key

Parameters:
key - the key for the choice
Returns:
the requested choice

size

public int size()
The number of Choices

Returns:
The number of Choices

setLocal

public void setLocal(String name,
                     String value)
Set a configuration Choice (by name) to a new value. This method is only of use to classes displaying config information.

Parameters:
name - the key for the choice
value - the value for the choice

getLocal

public String getLocal(String name)
Get a configuration Choice (by name). This method is only of use to classes displaying config information.

Parameters:
name - the key for the choice
Returns:
the value for the choice.

applicationToLocal

public void applicationToLocal()
Take the data in the application and copy it to the local storage area.


localToApplication

public void localToApplication()
Take the data in the local storage area and copy it to the application.


setProperties

public void setProperties(PropertyMap prop)
Take the data stored permanently and copy it to the local storage area, using the specified stream.

Parameters:
prop - the set of properties to save

getProperties

public PropertyMap getProperties()
Take the data in the local storage area and store it permanently.

Returns:
the collection of properties

permanentToLocal

public void permanentToLocal(URI uri)
                      throws IOException
Take the data stored permanently and copy it to the local storage area, using the configured storage area

Parameters:
uri - the location of the permanent storage
Throws:
IOException - if there was a problem getting the permanent config info

localToPermanent

public void localToPermanent(URI uri)
                      throws IOException
Take the data in the local storage area and store it permanently, using the configured storage area.

Parameters:
uri - the location of the permanent storage
Throws:
IOException - if there was a problem storing the permanent config info

getPath

public static String getPath(String key)
What is the Path of this key

Parameters:
key - the key of the property
Returns:
the path of the key

getLeaf

public static String getLeaf(String key)
What is the last part of the Path of this key.

Parameters:
key - the key of the property
Returns:
the part of the path after the last dot, '.'

addPropertyChangeListener

public void addPropertyChangeListener(PropertyChangeListener listener)
Add a PropertyChangeListener to the listener list. The listener is registered for all properties.

Parameters:
listener - The PropertyChangeListener to be added

removePropertyChangeListener

public void removePropertyChangeListener(PropertyChangeListener listener)
Remove a PropertyChangeListener from the listener list. This removes a PropertyChangeListener that was registered for all properties.

Parameters:
listener - The PropertyChangeListener to be removed

addPropertyChangeListener

public void addPropertyChangeListener(String propertyName,
                                      PropertyChangeListener listener)
Add a PropertyChangeListener for a specific property. The listener will be invoked only when a call on firePropertyChange names that specific property.

Parameters:
propertyName - The name of the property to listen on.
listener - The PropertyChangeListener to be added

removePropertyChangeListener

public void removePropertyChangeListener(String propertyName,
                                         PropertyChangeListener listener)
Remove a PropertyChangeListener for a specific property.

Parameters:
propertyName - The name of the property that was listened on.
listener - The PropertyChangeListener to be removed

addConfigListener

public void addConfigListener(ConfigListener li)
Add an Exception listener to the list of things wanting to know whenever we capture an Exception.

Parameters:
li - The ConfigListener to be added

removeConfigListener

public void removeConfigListener(ConfigListener li)
Remove an Exception listener from the list of things wanting to know whenever we capture an Exception

Parameters:
li - The ConfigListener to be removed

fireChoiceAdded

protected void fireChoiceAdded(String key,
                               Choice model)
A Choice got added.

Parameters:
key - the key of the choice that has been added
model - the choice that was added

fireChoiceRemoved

protected void fireChoiceRemoved(String key,
                                 Choice model)
A Choice got removed.

Parameters:
key - the key of the choice that has been removed
model - the choice that was removed

Copyright ยจ 2003-2015