org.knime.core.node.config
Class Config

java.lang.Object
  extended by org.knime.core.node.config.base.AbstractConfigEntry
      extended by org.knime.core.node.config.base.ConfigBase
          extended by org.knime.core.node.config.Config
All Implemented Interfaces:
Serializable, Iterable<String>, TreeNode, ConfigBaseRO, ConfigBaseWO, ConfigRO, ConfigWO
Direct Known Subclasses:
ModelContent, NodeSettings

public abstract class Config
extends ConfigBase
implements ConfigRO, ConfigWO

Supports a mechanism to save settings by their type and a key. Furthermore, it provides a method to recursively add new sub Config objects to this Config object, which then results in a tree-like structure.

This class inherits all types from its super class ConfigBase and in addition DataCell, DataType, RowKey, and Config objects. For these supported elements, methods to add either a single or an array or retrieve them back by throwing an InvalidSettingsException or passing a default valid in advance have been implemented.

Author:
Thomas Gabriel, University of Konstanz
See Also:
Serialized Form

Nested Class Summary
(package private) static interface Config.DataCellEntry
          Interface for all registered DataCell objects.
 
Constructor Summary
protected Config(String key)
          Creates a new, empty config object with the given key.
 
Method Summary
protected  void addConfig(Config config)
          Appends the given Config to this Config which has to directly derived from this class.
 Config addConfig(String key)
          Creates a new Config with the given key and returns it.
 void addDataCell(String key, DataCell cell)
          Adds this DataCell object to the Config by the given key.
 void addDataCellArray(String key, DataCell... values)
          Adds an array of DataCell objects to this Config.
 void addDataType(String key, DataType type)
          Adds this DataType object value to the Config by the given key.
 void addDataTypeArray(String key, DataType... values)
          Adds an array of DataType objects to this Config.
 void addEntry(AbstractConfigEntry entry)
          Adds the given Config entry to this Config.
 void addRowKey(String key, RowKey rowKey)
          Adds this RowKey object to this Config by the given key.
 void addRowKeyArray(String key, RowKey... rowKey)
          Adds this RowKey array to this Config by the given key.
 Config getConfig(String key)
          Retrieves Config by key.
 DataCell getDataCell(String key)
          Return DataCell for key.
 DataCell getDataCell(String key, DataCell def)
          Return a DataCell which can be null, or the default value if the key is not available.
 DataCell[] getDataCellArray(String key)
          Return DataCell array.
 DataCell[] getDataCellArray(String key, DataCell... def)
          Return DataCell array which can be null for key, or the default array if the key is not available.
 DataType getDataType(String key)
          Return DataType for key.
 DataType getDataType(String key, DataType def)
          Return a DataType elements or null for key, or the default value if not available.
 DataType[] getDataTypeArray(String key)
          Returns an array of DataType objects which can be null.
 DataType[] getDataTypeArray(String key, DataType... v)
          Returns the array of DataType objects for the given key or if not available the given array.
abstract  Config getInstance(String key)
          Creates a new Config of this type.
 RowKey getRowKey(String key)
          Return RowKey for key.
 RowKey getRowKey(String key, RowKey def)
          Return a RowKey which can be null, or the default value if the key is not available.
 RowKey[] getRowKeyArray(String key)
          Return RowKey array for the given key.
 RowKey[] getRowKeyArray(String key, RowKey... def)
          Return a RowKey array which can be null, or the default value if the key is not available.
 void load(InputStream is)
          Read config entries from an XML file into this object.
protected static Config loadFromXML(Config config, InputStream in)
          Reads Config from XML into a new Config object.
protected static Config readFromFile(ObjectInputStream ois)
          Creates new Config from the given file using the serialized object stream.
 String toString()
          String summary of this object including key, type, and value.
 
Methods inherited from class org.knime.core.node.config.base.ConfigBase
addBoolean, addBooleanArray, addByte, addByteArray, addChar, addCharArray, addConfigBase, addConfigBase, addDouble, addDoubleArray, addFloat, addFloatArray, addInt, addIntArray, addLong, addLongArray, addShort, addShortArray, addString, addStringArray, children, containsKey, copyTo, get, getBoolean, getBoolean, getBooleanArray, getBooleanArray, getByte, getByte, getByteArray, getByteArray, getChar, getChar, getCharArray, getCharArray, getChildAt, getChildCount, getConfigBase, getDouble, getDouble, getDoubleArray, getDoubleArray, getEntry, getFloat, getFloat, getFloatArray, getFloatArray, getIndex, getInt, getInt, getIntArray, getIntArray, getLong, getLong, getLongArray, getLongArray, getShort, getShort, getShortArray, getShortArray, getString, getString, getStringArray, getStringArray, hasIdenticalValue, isLeaf, iterator, keySet, loadFromXML, put, saveToXML, toString, toStringValue, writeToFile
 
Methods inherited from class org.knime.core.node.config.base.AbstractConfigEntry
equals, getAllowsChildren, getKey, getParent, getType, hashCode, isIdentical, setParent
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.knime.core.node.config.ConfigRO
iterator
 
Methods inherited from interface org.knime.core.node.config.base.ConfigBaseRO
containsKey, copyTo, getBoolean, getBoolean, getBooleanArray, getBooleanArray, getByte, getByte, getByteArray, getByteArray, getChar, getChar, getCharArray, getCharArray, getConfigBase, getDouble, getDouble, getDoubleArray, getDoubleArray, getFloat, getFloat, getFloatArray, getFloatArray, getInt, getInt, getIntArray, getIntArray, getKey, getLong, getLong, getLongArray, getLongArray, getShort, getShort, getShortArray, getShortArray, getString, getString, getStringArray, getStringArray, keySet, saveToXML
 
Methods inherited from interface javax.swing.tree.TreeNode
children, getAllowsChildren, getChildAt, getChildCount, getIndex, getParent, isLeaf
 
Methods inherited from interface org.knime.core.node.config.base.ConfigBaseWO
addBoolean, addBooleanArray, addByte, addByteArray, addChar, addCharArray, addConfigBase, addDouble, addDoubleArray, addFloat, addFloatArray, addInt, addIntArray, addLong, addLongArray, addShort, addShortArray, addString, addStringArray, getKey
 

Constructor Detail

Config

protected Config(String key)
Creates a new, empty config object with the given key.

Parameters:
key - The key for this Config.
Method Detail

getInstance

public abstract Config getInstance(String key)
Creates a new Config of this type.

Specified by:
getInstance in class ConfigBase
Parameters:
key - The new Config's key.
Returns:
A new instance of this Config.

addConfig

public final Config addConfig(String key)
Creates a new Config with the given key and returns it.

Specified by:
addConfig in interface ConfigWO
Parameters:
key - An identifier.
Returns:
A new Config object.

addConfig

protected final void addConfig(Config config)
Appends the given Config to this Config which has to directly derived from this class.

Parameters:
config - The Config to append.
Throws:
NullPointerException - If config is null.
IllegalArgumentException - If config is not instance of this class.

getConfig

public final Config getConfig(String key)
                       throws InvalidSettingsException
Retrieves Config by key.

Specified by:
getConfig in interface ConfigRO
Parameters:
key - The key.
Returns:
A Config object.
Throws:
InvalidSettingsException - If the key is not available.

addDataCell

public void addDataCell(String key,
                        DataCell cell)
Adds this DataCell object to the Config by the given key. The cell can be null.

Specified by:
addDataCell in interface ConfigWO
Parameters:
key - The key.
cell - The DataCell to add.

addDataType

public void addDataType(String key,
                        DataType type)
Adds this DataType object value to the Config by the given key. The type can be null.

Specified by:
addDataType in interface ConfigWO
Parameters:
key - The key.
type - The DataType object to add.

getDataCell

public DataCell getDataCell(String key)
                     throws InvalidSettingsException
Return DataCell for key.

Specified by:
getDataCell in interface ConfigRO
Parameters:
key - The key.
Returns:
A DataCell.
Throws:
InvalidSettingsException - If the key is not available.

getDataType

public DataType getDataType(String key)
                     throws InvalidSettingsException
Return DataType for key.

Specified by:
getDataType in interface ConfigRO
Parameters:
key - The key.
Returns:
A DataType.
Throws:
InvalidSettingsException - If the key is not available.

getDataCell

public DataCell getDataCell(String key,
                            DataCell def)
Return a DataCell which can be null, or the default value if the key is not available.

Specified by:
getDataCell in interface ConfigRO
Parameters:
key - The key.
def - The default value, returned id the key is not available.
Returns:
A DataCell object.

getDataType

public DataType getDataType(String key,
                            DataType def)
Return a DataType elements or null for key, or the default value if not available.

Specified by:
getDataType in interface ConfigRO
Parameters:
key - The key.
def - Returned if no value available for the given key.
Returns:
A DataType object or null, or the def value. generic boolean.

getDataCellArray

public DataCell[] getDataCellArray(String key)
                            throws InvalidSettingsException
Return DataCell array. The array an the elements can be null.

Specified by:
getDataCellArray in interface ConfigRO
Parameters:
key - The key.
Returns:
A DataCell array.
Throws:
InvalidSettingsException - If the the key is not available.

getDataCellArray

public DataCell[] getDataCellArray(String key,
                                   DataCell... def)
Return DataCell array which can be null for key, or the default array if the key is not available.

Specified by:
getDataCellArray in interface ConfigRO
Parameters:
key - The key.
def - The default array returned if the key is not available.
Returns:
A char array.

getRowKey

public RowKey getRowKey(String key)
                 throws InvalidSettingsException
Return RowKey for key.

Specified by:
getRowKey in interface ConfigRO
Parameters:
key - the identifier used to store the RowKey before
Returns:
the store RowKey
Throws:
InvalidSettingsException - if the key is not available

getRowKey

public RowKey getRowKey(String key,
                        RowKey def)
Return a RowKey which can be null, or the default value if the key is not available.

Specified by:
getRowKey in interface ConfigRO
Parameters:
key - identifier used to store the RowKey before
def - default value, returned if the key is not available
Returns:
the stored RowKey

addRowKey

public void addRowKey(String key,
                      RowKey rowKey)
Adds this RowKey object to this Config by the given key. The row key can be null.

Specified by:
addRowKey in interface ConfigWO
Parameters:
key - identifier used to store and the load the RowKey
rowKey - value to store

getRowKeyArray

public RowKey[] getRowKeyArray(String key)
                        throws InvalidSettingsException
Return RowKey array for the given key.

Specified by:
getRowKeyArray in interface ConfigRO
Parameters:
key - the identifier used to store the RowKey array before
Returns:
the store RowKey array
Throws:
InvalidSettingsException - if the key is not available

getRowKeyArray

public RowKey[] getRowKeyArray(String key,
                               RowKey... def)
Return a RowKey array which can be null, or the default value if the key is not available.

Specified by:
getRowKeyArray in interface ConfigRO
Parameters:
key - identifier used to store the RowKey array before
def - default value, returned if the key is not available
Returns:
the stored RowKey array

addRowKeyArray

public void addRowKeyArray(String key,
                           RowKey... rowKey)
Adds this RowKey array to this Config by the given key. The row key array can be null.

Specified by:
addRowKeyArray in interface ConfigWO
Parameters:
key - identifier used to store and the load the RowKey array
rowKey - array to store

getDataTypeArray

public DataType[] getDataTypeArray(String key)
                            throws InvalidSettingsException
Returns an array of DataType objects which can be null.

Specified by:
getDataTypeArray in interface ConfigRO
Parameters:
key - The key.
Returns:
An array of DataType objects.
Throws:
InvalidSettingsException - The the object is not available for the given key.

getDataTypeArray

public DataType[] getDataTypeArray(String key,
                                   DataType... v)
Returns the array of DataType objects for the given key or if not available the given array.

Specified by:
getDataTypeArray in interface ConfigRO
Parameters:
key - The key.
v - The default array, returned if no entry available for the key.
Returns:
An array of DataType objects.

addDataCellArray

public void addDataCellArray(String key,
                             DataCell... values)
Adds an array of DataCell objects to this Config. The array and all elements can be null.

Specified by:
addDataCellArray in interface ConfigWO
Parameters:
key - The key.
values - The data cells, elements can be null.

addDataTypeArray

public void addDataTypeArray(String key,
                             DataType... values)
Adds an array of DataType objects to this Config. The array and all elements can be null.

Specified by:
addDataTypeArray in interface ConfigWO
Parameters:
key - The key.
values - The data types, elements can be null.

addEntry

public void addEntry(AbstractConfigEntry entry)
Adds the given Config entry to this Config.

Overrides:
addEntry in class ConfigBase
Parameters:
entry - The Config entry to add.

toString

public String toString()
String summary of this object including key, type, and value.

Overrides:
toString in class ConfigBase
Returns:
key + type + value
See Also:
Object.toString()

readFromFile

protected static Config readFromFile(ObjectInputStream ois)
                              throws IOException
Creates new Config from the given file using the serialized object stream.

Parameters:
ois - Read Config from this stream.
Returns:
The new Config.
Throws:
IOException - Problem opening the file or content is not a Config.

loadFromXML

protected static Config loadFromXML(Config config,
                                    InputStream in)
                             throws IOException
Reads Config from XML into a new Config object. The stream will be closed by this call.

Parameters:
config - Depending on the readRoot, we write into this Config and return it.
in - The stream to read XML Config from.
Returns:
A new Config filled with the content read from XML.
Throws:
IOException - If the Config could not be load from stream.

load

public void load(InputStream is)
          throws IOException
Read config entries from an XML file into this object.

Overrides:
load in class ConfigBase
Parameters:
is - The XML inputstream storing the configuration to read
Throws:
IOException - If the stream could not be read.


Copyright, 2003 - 2012. All rights reserved.
University of Konstanz, Germany.
Chair for Bioinformatics and Information Mining, Prof. Dr. Michael R. Berthold.
You may not modify, publish, transmit, transfer or sell, reproduce, create derivative works from, distribute, perform, display, or in any way exploit any of the content, in whole or in part, except as otherwise expressly permitted in writing by the copyright owner or as specified in the license file distributed with this product.