net.sf.jeters.configuration
Class Configuration

java.lang.Object
  extended by net.sf.jeters.configuration.Configuration
All Implemented Interfaces:
java.lang.Cloneable, java.lang.Iterable<net.sf.jeters.configuration.entries.ConfigEntry>

public class Configuration
extends java.lang.Object
implements java.lang.Iterable<net.sf.jeters.configuration.entries.ConfigEntry>, java.lang.Cloneable

This class represents configurations of JETERS components.
Configuration objects are the preferred way for JETERS components to offer customization options to the user and to store information for future sessions. A component that wants to use configurations must implement the interface Configurable.
When JETERS discovers an unknown component with this interface, the first thing it will do is to call its getConfiguration method to retrieve the default configuration. That will be used to create a config file for the component and to provide a grapical interface to the user that allows to make changes to the configuration. Once a component is known to JETERS (which means there is a config file for it), settings from the config file will overwrite default values. If no value is specified for an entry present in the default configuration, this entry remains unchanged.
Before a configurable component is actually used, its setConfiguration method is called. This allows the object to modify its behavior according to the configuration values.
After component usage, the getConfiguration method is called by JETERS. The result will be used to modify the configuration file. This allows components to change some options during execution, for example by providing "do not ask me this again"-checkboxes. However, it is also possible to simply return the unchanged configuration object that came with setConfiguration.

Author:
Tobias Knerr

Constructor Summary
Configuration()
           
 
Method Summary
 void add(net.sf.jeters.configuration.entries.ConfigEntry entry)
          adds an entry to the configuration
 void add(net.sf.jeters.configuration.entries.ConfigEntry[] entries)
          adds all entries from an array to the configuration
 void addEntriesFrom(Configuration other, boolean overwrite)
          adds entries from another configuration to this.
 Configuration clone()
           
 net.sf.jeters.configuration.entries.ConfigEntry get(java.lang.String name)
          returns the entry with the given name
<T> T
getValue(java.lang.String name)
          finds the entry with the given name and returns the result of its getValue method.
 java.util.Iterator<net.sf.jeters.configuration.entries.ConfigEntry> iterator()
          returns an iterator that will iterate over all configuration over all entries in this configuration.
 void remove(java.lang.String name)
          removes the entry with the given name from the configuration
 int size()
          returns the number of entries in this configuration
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Configuration

public Configuration()
Method Detail

get

public net.sf.jeters.configuration.entries.ConfigEntry get(java.lang.String name)
returns the entry with the given name

Parameters:
name - name of entry that is to be returned
Returns:
entry with the given name or null if no entry with the name exists

getValue

public <T> T getValue(java.lang.String name)
finds the entry with the given name and returns the result of its getValue method. This is a convenience method, its only purpose is to make the user's code shorter and more readable.


add

public void add(net.sf.jeters.configuration.entries.ConfigEntry entry)
adds an entry to the configuration

Parameters:
entry - entry to add

add

public void add(net.sf.jeters.configuration.entries.ConfigEntry[] entries)
adds all entries from an array to the configuration

Parameters:
entries - array of entries, must not be null, elements must not be null

remove

public void remove(java.lang.String name)
removes the entry with the given name from the configuration

Parameters:
name - name of entry that should be removed

size

public int size()
returns the number of entries in this configuration

Returns:
number of entries

iterator

public java.util.Iterator<net.sf.jeters.configuration.entries.ConfigEntry> iterator()
returns an iterator that will iterate over all configuration over all entries in this configuration. The order of the entries is not specified.

Specified by:
iterator in interface java.lang.Iterable<net.sf.jeters.configuration.entries.ConfigEntry>
Returns:
configuration entry iterator

addEntriesFrom

public void addEntriesFrom(Configuration other,
                           boolean overwrite)
adds entries from another configuration to this. If an entry already exists here, it will only be added if it has the same type (getClass() results are equal) and the overwrite parameter is true; it will then replace the old entry. Old entries whose value is null will always be overwritten by new entries with the same name and type.

Parameters:
other - a configuration whose entries will be added to this config, can be null (=> no entries added)
overwrite - determines whether existing entries will be overwritten

clone

public Configuration clone()
Overrides:
clone in class java.lang.Object