org.norther.tammi.core.config
Class Configuration

java.lang.Object
  extended by java.util.AbstractMap<K,V>
      extended by org.norther.tammi.acorn.util.ConcurrentAbstractMap<K,V>
          extended by org.norther.tammi.acorn.util.ConcurrentReadMap<K,V>
              extended by org.norther.tammi.acorn.util.OrderedHashMap<String,Object>
                  extended by org.norther.tammi.core.config.Configuration
All Implemented Interfaces:
Serializable, Cloneable, ConcurrentMap<String,Object>, Map<String,Object>, Traceable, OrderedMap<String,Object>

public class Configuration
extends OrderedHashMap<String,Object>
implements Traceable, Serializable, Cloneable

An extension to java.util.Properties adding the possibility to use the same key many times concatenating the value strings instead of overwriting them.

The extended properties syntax is explained below:

Here is an example of a valid extended properties file:

 ##
 # Lines starting with # are comments.
 # This is the simplest property.
 key = value
 ##
 # A long property may be separated on multiple lines.
 longvalue = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa \
     aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 ##
 # This is a property with many tokens.
 tokens_on_a_line = first token, second token
 ##
 # This sequence generates exactly the same result.
 tokens_on_multiple_lines = first token
 tokens_on_multiple_lines = second token
 ##
 # Separators may be escaped in tokens.
 commas.excaped = Hi\, what'up? 
 

NOTE : this class has not been written for performance nor low memory usage. In fact, it's way slower than it could be and generates too much memory garbage. But since performance is not an issue during intialization (and there is not much time to improve it), I wrote it this way. If you don't like it, go ahead and tune it up!

Based on ExtendedProperties in the Apache Jakarta Commons project.

Version:
$Id: Configuration.java,v 1.43 2009/09/28 15:08:44 cvsimp Exp $
Author:
Stefano Mazzocchi, Jon S. Stevens, Dave Bryson, Jason van Zyl, Geir Magnusson Jr., Leon Messerschmidt, Kent Johnson, Daniel Rall, Ilkka Priha
See Also:
Serialized Form

Nested Class Summary
protected static class Configuration.PropertiesReader
          This class is used to read properties lines.
 
Nested classes/interfaces inherited from class org.norther.tammi.acorn.util.ConcurrentAbstractMap
ConcurrentAbstractMap.ConcurrentEntry<K,V>, ConcurrentAbstractMap.Modification
 
Nested classes/interfaces inherited from class java.util.AbstractMap
AbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K,V>
 
Nested classes/interfaces inherited from interface java.util.Map
Map.Entry<K,V>
 
Field Summary
 
Fields inherited from class org.norther.tammi.acorn.util.ConcurrentReadMap
DEFAULT_CAPACITY, MAXIMUM_CAPACITY, MINIMUM_CAPACITY
 
Fields inherited from class org.norther.tammi.acorn.util.ConcurrentAbstractMap
DEFAULT_LOAD_FACTOR
 
Constructor Summary
Configuration()
          Creates an empty extended properties instance.
Configuration(Configuration defs)
          Creates an empty extended properties instance with defaults.
Configuration(MBeanReference<?> reference)
          Creates an empty extended properties instance for the specified MBean.
Configuration(MBeanReference<?> reference, Configuration defs)
          Creates an empty extended properties instance for the specified MBean with defaults.
Configuration(MBeanReference<?> reference, String path)
          Creates and loads extended properties from the specified file for the specified MBean.
Configuration(MBeanReference<?> reference, String path, String defaultPath)
          Creates and loads extended properties from the specified file with default values from another file for the specified MBean.
Configuration(String path)
          Creates and loads extended properties from the specified file.
Configuration(String path, String defaultPath)
          Creates and loads extended properties from the specified file with default values from another file.
 
Method Summary
 boolean add(String key, Object value)
          Associates the specified value with the specified key in this map if not already mapped.
 boolean addAt(int index, String key, Object value)
          Associates the specified value with the specified key at the specified index in this map if not already mapped.
 void addProperties(int index, String key, String[] values)
          Adds multivalued property values at the specified index.
 void addProperties(int index, String key, String[] values, String separator)
          Adds multivalued property values at the specified index with the specified separator.
 void addProperties(String key, String[] values)
          Adds multivalued property values.
 void addProperty(int index, String key, String value)
          Adds a multivalued property value at the specified index.
 void addProperty(String key, String value)
          Adds a multivalued property value.
 void addTraceListener(TraceListener listener)
          Adds a listener if not already present.
 void clear()
           
 void clearLastModified()
          Clears the timestamp of the last modification of the traced object.
 void clearTraceListeners()
          Clears all listeners from this traceable.
 Object clone()
           
 boolean containsProperty(String key)
          Checks whether a property is available.
 boolean getBoolean(String key)
          Gets a boolean property value.
 boolean getBoolean(String key, boolean defaultValue)
          Gets a boolean property value with a default.
 Boolean getBoolean(String key, Boolean defaultValue)
          Gets a Boolean property value with a default.
 byte getByte(String key)
          Gets a byte property value.
 byte getByte(String key, byte defaultValue)
          Gets a byte property value with a default.
 Byte getByte(String key, Byte defaultValue)
          Gets a Byte property value with a default.
static String getDelimiterKey()
          Gets the property key for a key delimiter.
 double getDouble(String key)
          Gets a double property value.
 double getDouble(String key, double defaultValue)
          Gets a double property value with a default.
 Double getDouble(String key, Double defaultValue)
          Gets a Double property value with a default.
 float getFloat(String key)
          Gets a float property value.
 float getFloat(String key, float defaultValue)
          Gets a float property value with a default.
 Float getFloat(String key, Float defaultValue)
          Gets a Float property value with a default.
static String getIncludeKey()
          Gets the property key for including other properties files.
 int getInt(String key)
          Gets an int property value.
 int getInt(String key, int defaultValue)
          Gets an int property value with a default.
 Integer getInteger(String key, Integer defaultValue)
          Gets an Integer property value with a default.
 String getItemSeparator()
          Gets the item separator(s).
 String getKeyDelimiter()
          Gets the key delimiters(s).
 long getLastModified()
          Gets the timestamp of the last modification of the traced object.
 long getLastModified(Object key)
          Gets the timestamp of the last modification of the specified resource.
 long getLong(String key)
          Gets a long property value.
 long getLong(String key, long defaultValue)
          Gets a long property value with a default.
 Long getLong(String key, Long defaultValue)
          Gets a Long property value with a default.
static String getNullKey()
          Gets the property key for a null value.
 String getNullValue()
          Gets the null value.
 String[] getProperties(String key)
          Gets a multivalued property value.
 String[] getProperties(String key, String[] defaultValues)
          Gets multivalued property values with defaults.
 String getProperty(String key)
          Gets a property value.
 String getProperty(String key, String defaultValue)
          Gets a property value with a default.
static String getSeparatorKey()
          Gets the property key for a list separator.
 short getShort(String key)
          Gets a short property value.
 short getShort(String key, short defaultValue)
          Gets a short property value with a default.
 Short getShort(String key, Short defaultValue)
          Gets a Short property value with a default.
 int indexOfProperty(String key, String value)
          Returns the index of a multivalued property value.
 void load(InputStream input)
          Loads the properties from an input stream by applying the ISO-8859-1 encoding to be compatible with java.util.Properties.
 void load(InputStream input, String encoding)
          Loads the properties from an input stream using the specified encoding.
 void load(Properties props)
          Loads the properties from properties.
 void load(Reader reader)
          Loads the properties from a reader.
 void loadFromXML(InputStream input)
          Loads the properties represented by the XML document on the specified input stream into this configuration.
 void loadProperty(String key, String value)
          Loads a property by applying the same escaping rules as other load methods.
 void merge(Map<String,Object> map)
          Merges the specified map to this configuration.
 Enumeration<String> propertyNames()
          Returns an enumeration of all property names including the defaults.
 Object put(int index, String key, Object value)
          Associates the specified value with the specified key at the specified index in this map.
 Object put(String key, Object value)
           
 Object putIfAbsent(int index, String key, Object value)
          Associates the specified value with the specified key at the specified index in this map if not already mapped.
 Object putIfAbsent(String key, Object value)
           
 Object remove(Object key)
           
 boolean remove(Object key, Object value)
           
 Map.Entry<String,Object> removeAt(int index)
          Removes the indexed element in this map.
 boolean removeProperties(String key, String[] values)
          Removes multivalued property values.
 Object removeProperty(String key)
          Removes a property.
 boolean removeProperty(String key, String value)
          Removes a multivalued property value.
 void removeTraceListener(TraceListener listener)
          Removes a listener.
 Object replace(int index, Object value)
          Replaces the indexed element in this map.
 Object replace(String key, Object value)
           
 boolean replace(String key, Object oldValue, Object newValue)
           
static void setDelimiterKey(String key)
          Sets the property key for a key delimiter.
static void setIncludeKey(String key)
          Sets the property key for including other properties files.
 void setItemSeparator(String separator)
          Sets the item separator(s).
 void setKeyDelimiter(String delimiter)
          Sets the key delimiter(s).
 void setLastModified(Object key, long timestamp)
          Sets the timestamp of the last modification of the specified resource.
static void setNullKey(String key)
          Sets the property key for a null value.
 void setNullValue(String nul)
          Sets the null value.
 Object setProperties(String key, String[] values)
          Sets a multivalued property value.
 Object setProperty(String key, String value)
          Sets a property value.
static void setSeparatorKey(String key)
          Sets the property key for a list separator.
 void store(OutputStream output, String header)
          Stores the properties to the given output stream using uencoding.
 void store(OutputStream output, String header, String encoding)
          Stores the properties to the given output stream using the specified encoding.
 void store(Writer writer, String header)
          Stores the properties to the given writer.
 void storeToXML(OutputStream output, String header)
          Stores an XML document representing the properties contained in this configuration by applying the UTF-8 encoding.
 void storeToXML(OutputStream output, String header, String encoding)
          Stores an XML document representing the properties contained in this configuration by applying the specified encoding.
 Set<String> stringPropertyNames()
          Returns a set of all property names including the defaults.
 Configuration subset(String prefix)
          Returns a configuration that is a subset of this one.
 Configuration subset(String prefix, String suffix)
          Returns a configuration that is a subset of this one.
 Properties toProperties()
          Converts this configuration to properties.
 Properties toProperties(String prefix)
          Converts a subset of this configuration to properties.
 
Methods inherited from class org.norther.tammi.acorn.util.OrderedHashMap
elements, entryList, entrySet, get, getEntryAt, getKeyAt, indexOfKey, isModifiable, keyList, keys, keySet, putAll, putEntry, removeEntry, set, shift, valueList, values
 
Methods inherited from class org.norther.tammi.acorn.util.ConcurrentReadMap
capacity, containsValue, getEntry, getEntryTable, isEmpty, putAll, rehash, replaceEntry, setEntryTable, size
 
Methods inherited from class org.norther.tammi.acorn.util.ConcurrentAbstractMap
capacity, contains, containsKey, get
 
Methods inherited from class java.util.AbstractMap
equals, hashCode, toString
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Map
containsKey, containsValue, equals, get, hashCode, isEmpty, putAll, size
 

Constructor Detail

Configuration

public Configuration()
Creates an empty extended properties instance.


Configuration

public Configuration(Configuration defs)
Creates an empty extended properties instance with defaults.

Parameters:
defs - the default configuration.

Configuration

public Configuration(String path)
              throws IOException
Creates and loads extended properties from the specified file.

Parameters:
path - the pathname of the properties file.
Throws:
IOException - on I/O errors.

Configuration

public Configuration(String path,
                     String defaultPath)
              throws IOException
Creates and loads extended properties from the specified file with default values from another file.

Parameters:
path - the pathname of the properties file.
defaultPath - the pathname of the defaults file.
Throws:
IOException - on I/O errors.

Configuration

public Configuration(MBeanReference<?> reference)
Creates an empty extended properties instance for the specified MBean.

Parameters:
reference - the MBean reference.

Configuration

public Configuration(MBeanReference<?> reference,
                     Configuration defs)
Creates an empty extended properties instance for the specified MBean with defaults.

Parameters:
reference - the MBean reference.
defs - the default configuration.

Configuration

public Configuration(MBeanReference<?> reference,
                     String path)
              throws IOException
Creates and loads extended properties from the specified file for the specified MBean. The file is searched for from root folder of the path finder.

Parameters:
reference - the MBean reference.
path - the pathname of the properties file.
Throws:
IOException - on I/O errors.

Configuration

public Configuration(MBeanReference<?> reference,
                     String path,
                     String defaultPath)
              throws IOException
Creates and loads extended properties from the specified file with default values from another file for the specified MBean. The files are searched for from the root folder of the path finder.

Parameters:
reference - the MBean reference.
path - the pathname of the properties file.
defaultPath - the pathname of the defaults file.
Throws:
IOException - on I/O errors.
Method Detail

getNullKey

public static String getNullKey()
Gets the property key for a null value. By default it is "null".

Returns:
the null value property key.

setNullKey

public static void setNullKey(String key)
Sets the property key for a null value. By default it is "null".

Parameters:
key - the null value property key.

getDelimiterKey

public static String getDelimiterKey()
Gets the property key for a key delimiter. By default it is "delimiter".

Returns:
the key delimiter property key.

setDelimiterKey

public static void setDelimiterKey(String key)
Sets the property key for a key delimiter. By default it is "delimiter".

Parameters:
key - the key delimiter property key.

getSeparatorKey

public static String getSeparatorKey()
Gets the property key for a list separator. By default it is "separator".

Returns:
the list separator property key.

setSeparatorKey

public static void setSeparatorKey(String key)
Sets the property key for a list separator. By default it is "separator".

Parameters:
key - the list separator property key.

getIncludeKey

public static String getIncludeKey()
Gets the property key for including other properties files. By default it is "include".

Returns:
the include property key.

setIncludeKey

public static void setIncludeKey(String key)
Sets the property key for including other properties files. By default it is "include".

Parameters:
key - the include property key.

clone

public Object clone()
Overrides:
clone in class OrderedHashMap<String,Object>

clear

public void clear()
Specified by:
clear in interface Map<String,Object>
Overrides:
clear in class OrderedHashMap<String,Object>

put

public Object put(String key,
                  Object value)
Specified by:
put in interface Map<String,Object>
Overrides:
put in class ConcurrentAbstractMap<String,Object>

remove

public Object remove(Object key)
Specified by:
remove in interface Map<String,Object>
Overrides:
remove in class ConcurrentAbstractMap<String,Object>

putIfAbsent

public Object putIfAbsent(String key,
                          Object value)
Specified by:
putIfAbsent in interface ConcurrentMap<String,Object>
Overrides:
putIfAbsent in class ConcurrentAbstractMap<String,Object>

add

public boolean add(String key,
                   Object value)
Description copied from class: ConcurrentAbstractMap
Associates the specified value with the specified key in this map if not already mapped. This method may be applied in maps supporting nulls instead of the putIfAbsent method.

Specified by:
add in interface OrderedMap<String,Object>
Overrides:
add in class ConcurrentAbstractMap<String,Object>
Parameters:
key - key with which the specified value is to be associated.
value - value to be associated with the specified key.
Returns:
true if added, false otherwise.

replace

public Object replace(String key,
                      Object value)
Specified by:
replace in interface ConcurrentMap<String,Object>
Overrides:
replace in class ConcurrentAbstractMap<String,Object>

replace

public boolean replace(String key,
                       Object oldValue,
                       Object newValue)
Specified by:
replace in interface ConcurrentMap<String,Object>
Overrides:
replace in class ConcurrentAbstractMap<String,Object>

remove

public boolean remove(Object key,
                      Object value)
Specified by:
remove in interface ConcurrentMap<String,Object>
Overrides:
remove in class ConcurrentAbstractMap<String,Object>

put

public Object put(int index,
                  String key,
                  Object value)
Description copied from interface: OrderedMap
Associates the specified value with the specified key at the specified index in this map. An existing key is not moved.

Specified by:
put in interface OrderedMap<String,Object>
Overrides:
put in class OrderedHashMap<String,Object>
Parameters:
index - the index.
key - the key with which the specified value is to be associated.
value - the value to be associated with the specified key.
Returns:
the previous value associated with the specified key.

putIfAbsent

public Object putIfAbsent(int index,
                          String key,
                          Object value)
Description copied from interface: OrderedMap
Associates the specified value with the specified key at the specified index in this map if not already mapped.

Specified by:
putIfAbsent in interface OrderedMap<String,Object>
Overrides:
putIfAbsent in class OrderedHashMap<String,Object>
Parameters:
index - the index.
key - the key with which the specified value is to be associated.
value - the value to be associated with the specified key.
Returns:
the previous value associated with the specified key.

addAt

public boolean addAt(int index,
                     String key,
                     Object value)
Description copied from interface: OrderedMap
Associates the specified value with the specified key at the specified index in this map if not already mapped.

Specified by:
addAt in interface OrderedMap<String,Object>
Overrides:
addAt in class OrderedHashMap<String,Object>
Parameters:
index - the index.
key - the key with which the specified value is to be associated.
value - the value to be associated with the specified key.
Returns:
true if added, false otherwise.

replace

public Object replace(int index,
                      Object value)
Description copied from interface: OrderedMap
Replaces the indexed element in this map.

Specified by:
replace in interface OrderedMap<String,Object>
Overrides:
replace in class OrderedHashMap<String,Object>
Parameters:
index - the index.
value - the new value.
Returns:
the replaced value.

removeAt

public Map.Entry<String,Object> removeAt(int index)
Description copied from interface: OrderedMap
Removes the indexed element in this map.

Specified by:
removeAt in interface OrderedMap<String,Object>
Overrides:
removeAt in class OrderedHashMap<String,Object>
Parameters:
index - the index.
Returns:
the removed entry.

getLastModified

public long getLastModified()
Description copied from interface: Traceable
Gets the timestamp of the last modification of the traced object.

Specified by:
getLastModified in interface Traceable
Returns:
the modification timestamp.

getLastModified

public long getLastModified(Object key)
Description copied from interface: Traceable
Gets the timestamp of the last modification of the specified resource.

Specified by:
getLastModified in interface Traceable
Parameters:
key - the key of the resource.
Returns:
the modification timestamp.

setLastModified

public void setLastModified(Object key,
                            long timestamp)
Description copied from interface: Traceable
Sets the timestamp of the last modification of the specified resource. This is a clumsy way to maintain original timestamps of resources copied between objects, so implementors are encouraged to provide timestamped setters to be applied instead of this method.

Specified by:
setLastModified in interface Traceable
Parameters:
key - the key of the resource.
timestamp - the modification timestamp.

clearLastModified

public void clearLastModified()
Description copied from interface: Traceable
Clears the timestamp of the last modification of the traced object.

Specified by:
clearLastModified in interface Traceable

addTraceListener

public void addTraceListener(TraceListener listener)
Description copied from interface: Traceable
Adds a listener if not already present.

Specified by:
addTraceListener in interface Traceable
Parameters:
listener - a listener to add.

removeTraceListener

public void removeTraceListener(TraceListener listener)
Description copied from interface: Traceable
Removes a listener.

Specified by:
removeTraceListener in interface Traceable
Parameters:
listener - the listener to remove.

clearTraceListeners

public void clearTraceListeners()
Description copied from interface: Traceable
Clears all listeners from this traceable.

Specified by:
clearTraceListeners in interface Traceable

getNullValue

public String getNullValue()
Gets the null value.

Returns:
the null value.

setNullValue

public void setNullValue(String nul)
Sets the null value.

Parameters:
nul - the null.

getKeyDelimiter

public String getKeyDelimiter()
Gets the key delimiters(s).

Returns:
the separators(s).

setKeyDelimiter

public void setKeyDelimiter(String delimiter)
Sets the key delimiter(s). Null enables default delimiter(s).

Parameters:
delimiter - the delimiters(s).

getItemSeparator

public String getItemSeparator()
Gets the item separator(s).

Returns:
the separator(s).

setItemSeparator

public void setItemSeparator(String separator)
Sets the item separator(s). Null disables value arrays. An empty string enables value arrays given as separate properties.

Parameters:
separator - the separator(s).

loadFromXML

public void loadFromXML(InputStream input)
                 throws IOException,
                        InvalidPropertiesFormatException
Loads the properties represented by the XML document on the specified input stream into this configuration.

The XML document must be compatible with the following DTD:

 <!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
 

Parameters:
input - the input stream.
Throws:
IOException - on I/O errors.
InvalidPropertiesFormatException - for invalid data.

storeToXML

public void storeToXML(OutputStream output,
                       String header)
                throws IOException
Stores an XML document representing the properties contained in this configuration by applying the UTF-8 encoding.

The defaults are not included in the document by this method.

Parameters:
output - the output stream.
header - an optional header.
Throws:
IOException - on I/O errors.

storeToXML

public void storeToXML(OutputStream output,
                       String header,
                       String encoding)
                throws IOException
Stores an XML document representing the properties contained in this configuration by applying the specified encoding.

The defaults are not included in the document by this method.

Parameters:
output - the output stream.
header - an optional header.
encoding - the encoding.
Throws:
IOException - on I/O errors.

load

public void load(InputStream input)
          throws IOException
Loads the properties from an input stream by applying the ISO-8859-1 encoding to be compatible with java.util.Properties.

Parameters:
input - the input stream.
Throws:
IOException - on I/O errors.

load

public void load(InputStream input,
                 String encoding)
          throws IOException
Loads the properties from an input stream using the specified encoding. If encoding is not given, the platform default is applied.

Parameters:
input - the input stream.
encoding - the encoding.
Throws:
IOException - on I/O errors.

load

public void load(Reader reader)
          throws IOException
Loads the properties from a reader.

Parameters:
reader - the reader.
Throws:
IOException - on I/O errors.

store

public void store(OutputStream output,
                  String header)
           throws IOException
Stores the properties to the given output stream using uencoding.

The defaults are not stored by this method.

Parameters:
output - the output stream.
header - an optional header.
Throws:
IOException - on I/O errors.

store

public void store(OutputStream output,
                  String header,
                  String encoding)
           throws IOException
Stores the properties to the given output stream using the specified encoding.

The defaults are not stored by this method.

Parameters:
output - the output stream.
header - an optional header.
encoding - the encoding.
Throws:
IOException - on I/O errors.

store

public void store(Writer writer,
                  String header)
           throws IOException
Stores the properties to the given writer.

The defaults are not stored by this method.

Parameters:
writer - the writer.
header - an optional header.
Throws:
IOException - on I/O errors.

load

public void load(Properties props)
Loads the properties from properties.

Parameters:
props - the properties.

merge

public void merge(Map<String,Object> map)
Merges the specified map to this configuration. Multi-valued properties are inserted before existing values. If multi-valued properties are not supported, new values replace existing ones.

Parameters:
map - the map to merge.

subset

public Configuration subset(String prefix)
Returns a configuration that is a subset of this one. The selection key is matched as a prefix against the full property names of this configuration. The prefix is removed from the keys of the subset.

The corresponding subset of the defaults is included as the defaults of the subset, if any.

Parameters:
prefix - a selection prefix (may be null).
Returns:
the subset configuration.

subset

public Configuration subset(String prefix,
                            String suffix)
Returns a configuration that is a subset of this one. The selection key is matched as a prefix and/or as a suffix against the full property names of this configuration. The selection key part is removed from the keys of the subset.

The corresponding subset of the defaults is included as the defaults of the subset, if any.

Parameters:
prefix - a selection prefix (may be null).
suffix - a selection suffix (may be null).
Returns:
the subset configuration.

toProperties

public Properties toProperties()
Converts this configuration to properties. Multivalued properties are separated by the specified separator, if not null.

The corresponding subset of the defaults is included as the defaults of the subset, if any.

Returns:
the associated properties.

toProperties

public Properties toProperties(String prefix)
Converts a subset of this configuration to properties. Property names are maintained as they are. Multivalued properties are separated by the specified separator, if not null.

The corresponding subset of the defaults is included as the defaults of the subset, if any.

Parameters:
prefix - a property name prefix.
Returns:
the associated properties.

containsProperty

public boolean containsProperty(String key)
Checks whether a property is available.

Parameters:
key - the key of the property.
Returns:
true if available, false otherwise.

getProperty

public String getProperty(String key)
Gets a property value.

Parameters:
key - the key of the property.
Returns:
the value of the property or null.

getProperty

public String getProperty(String key,
                          String defaultValue)
Gets a property value with a default.

Parameters:
key - the key of the property.
defaultValue - the default value.
Returns:
the value of the property or null.

setProperty

public Object setProperty(String key,
                          String value)
Sets a property value.

Parameters:
key - the key of the property.
value - the value of the property.
Returns:
the previous value of the property.

getProperties

public String[] getProperties(String key)
Gets a multivalued property value.

Parameters:
key - the key of the property.
Returns:
the values of the property or null.

getProperties

public String[] getProperties(String key,
                              String[] defaultValues)
Gets multivalued property values with defaults.

Parameters:
key - the key of the property.
defaultValues - the default values.
Returns:
the values of the property or null.

setProperties

public Object setProperties(String key,
                            String[] values)
Sets a multivalued property value.

Parameters:
key - the key of the property.
values - the values of the property.
Returns:
the previous value of the property.

removeProperty

public Object removeProperty(String key)
Removes a property.

Parameters:
key - the key of the property.
Returns:
the value of the removed property.

indexOfProperty

public int indexOfProperty(String key,
                           String value)
Returns the index of a multivalued property value.

Parameters:
key - the key of the property.
value - the value of the property.
Returns:
the index of the value or -1.

addProperty

public void addProperty(String key,
                        String value)
Adds a multivalued property value.

Parameters:
key - the key of the property.
value - the value of the property.

addProperty

public void addProperty(int index,
                        String key,
                        String value)
Adds a multivalued property value at the specified index.

Parameters:
index - the index.
key - the key of the property.
value - the value of the property.

removeProperty

public boolean removeProperty(String key,
                              String value)
Removes a multivalued property value.

Parameters:
key - the key of the property.
value - the value of the property.
Returns:
true if removed, false otherwise.

addProperties

public void addProperties(String key,
                          String[] values)
Adds multivalued property values.

Parameters:
key - the key of the property.
values - the values of the property.

addProperties

public void addProperties(int index,
                          String key,
                          String[] values)
Adds multivalued property values at the specified index.

Parameters:
index - the index.
key - the key of the property.
values - the values of the property.

removeProperties

public boolean removeProperties(String key,
                                String[] values)
Removes multivalued property values.

Parameters:
key - the key of the property.
values - the values of the property.
Returns:
true if removed, false otherwise.

loadProperty

public void loadProperty(String key,
                         String value)
Loads a property by applying the same escaping rules as other load methods.

Parameters:
key - the key of the property.
value - the value of the property.

propertyNames

public Enumeration<String> propertyNames()
Returns an enumeration of all property names including the defaults.

Returns:
an enumeration of property names.

stringPropertyNames

public Set<String> stringPropertyNames()
Returns a set of all property names including the defaults.

Returns:
a set of property names.

getBoolean

public boolean getBoolean(String key)
Gets a boolean property value.

Parameters:
key - the key of the property.
Returns:
the value of the property.
Throws:
NoSuchElementException - if the key doesn't map to an existing object.
ClassCastException - if the key maps to an object that is not a Boolean.

getBoolean

public boolean getBoolean(String key,
                          boolean defaultValue)
Gets a boolean property value with a default.

Parameters:
key - the key of the property.
defaultValue - the default value.
Returns:
the value of the property or the default.
Throws:
ClassCastException - if the key maps to an object that is not a Boolean.

getBoolean

public Boolean getBoolean(String key,
                          Boolean defaultValue)
Gets a Boolean property value with a default.

Parameters:
key - the key of the property.
defaultValue - the default value.
Returns:
the value of the property or the default.
Throws:
ClassCastException - if the key maps to an object that is not a Boolean.

getByte

public byte getByte(String key)
Gets a byte property value.

Parameters:
key - the key of the property.
Returns:
the value of the property.
Throws:
NoSuchElementException - if the key doesn't map to an existing object.
ClassCastException - if the key maps to an object that is not a Byte.
NumberFormatException - if the value mapped by the key has not a valid number format.

getByte

public byte getByte(String key,
                    byte defaultValue)
Gets a byte property value with a default.

Parameters:
key - the key of the property.
defaultValue - the default value.
Returns:
the value of the property or the default.
Throws:
ClassCastException - if the key maps to an object that is not a Byte.
NumberFormatException - if the value mapped by the key has not a valid number format.

getByte

public Byte getByte(String key,
                    Byte defaultValue)
Gets a Byte property value with a default.

Parameters:
key - the key of the property.
defaultValue - the default value.
Returns:
the value of the property or the default.
Throws:
ClassCastException - if the key maps to an object that is not a Byte.
NumberFormatException - if the value mapped by the key has not a valid number format.

getShort

public short getShort(String key)
Gets a short property value.

Parameters:
key - the key of the property.
Returns:
the value of the property.
Throws:
NoSuchElementException - if the key doesn't map to an existing object.
ClassCastException - if the key maps to an object that is not a Short.
NumberFormatException - if the value mapped by the key has not a valid number format.

getShort

public short getShort(String key,
                      short defaultValue)
Gets a short property value with a default.

Parameters:
key - the key of the property.
defaultValue - the default value.
Returns:
the value of the property or the default.
Throws:
ClassCastException - if the key maps to an object that is not a Short.
NumberFormatException - if the value mapped by the key has not a valid number format.

getShort

public Short getShort(String key,
                      Short defaultValue)
Gets a Short property value with a default.

Parameters:
key - the key of the property.
defaultValue - the default value.
Returns:
the value of the property or the default.
Throws:
ClassCastException - if the key maps to an object that is not a Short.
NumberFormatException - if the value mapped by the key has not a valid number format.

getInt

public int getInt(String key)
Gets an int property value.

Parameters:
key - the key of the property.
Returns:
the value of the property.
Throws:
NoSuchElementException - if the key doesn't map to an existing object.
ClassCastException - if the key maps to an object that is not a Integer.
NumberFormatException - if the value mapped by the key has not a valid number format.

getInt

public int getInt(String key,
                  int defaultValue)
Gets an int property value with a default.

Parameters:
key - the key of the property.
defaultValue - the default value.
Returns:
the value of the property or the default.
Throws:
ClassCastException - if the key maps to an object that is not a Integer.
NumberFormatException - if the value mapped by the key has not a valid number format.

getInteger

public Integer getInteger(String key,
                          Integer defaultValue)
Gets an Integer property value with a default.

Parameters:
key - the key of the property.
defaultValue - the default value.
Returns:
the value of the property or the default.
Throws:
ClassCastException - if the key maps to an object that is not a Integer.
NumberFormatException - if the value mapped by the key has not a valid number format.

getLong

public long getLong(String key)
Gets a long property value.

Parameters:
key - the key of the property.
Returns:
the value of the property.
Throws:
NoSuchElementException - if the key doesn't map to an existing object.
ClassCastException - if the key maps to an object that is not a Long.
NumberFormatException - if the value mapped by the key has not a valid number format.

getLong

public long getLong(String key,
                    long defaultValue)
Gets a long property value with a default.

Parameters:
key - the key of the property.
defaultValue - the default value.
Returns:
the value of the property or the default.
Throws:
ClassCastException - if the key maps to an object that is not a Long.
NumberFormatException - if the value mapped by the key has not a valid number format.

getLong

public Long getLong(String key,
                    Long defaultValue)
Gets a Long property value with a default.

Parameters:
key - the key of the property.
defaultValue - the default value.
Returns:
the value of the property or the default.
Throws:
ClassCastException - if the key maps to an object that is not a Long.
NumberFormatException - if the value mapped by the key has not a valid number format.

getFloat

public float getFloat(String key)
Gets a float property value.

Parameters:
key - the key of the property.
Returns:
the value of the property.
Throws:
NoSuchElementException - if the key doesn't map to an existing object.
ClassCastException - if the key maps to an object that is not a Float.
NumberFormatException - if the value mapped by the key has not a valid number format.

getFloat

public float getFloat(String key,
                      float defaultValue)
Gets a float property value with a default.

Parameters:
key - the key of the property.
defaultValue - the default value.
Returns:
the value of the property or the default.
Throws:
ClassCastException - if the key maps to an object that is not a Float.
NumberFormatException - if the value mapped by the key has not a valid number format.

getFloat

public Float getFloat(String key,
                      Float defaultValue)
Gets a Float property value with a default.

Parameters:
key - the key of the property.
defaultValue - the default value.
Returns:
the value of the property or the deafult.
Throws:
ClassCastException - if the key maps to an object that is not a Float.
NumberFormatException - if the value mapped by the key has not a valid number format.

getDouble

public double getDouble(String key)
Gets a double property value.

Parameters:
key - the key of the property.
Returns:
the value of the property.
Throws:
NoSuchElementException - if the key doesn't map to an existing object.
ClassCastException - if the key maps to an object that is not a Double.
NumberFormatException - if the value mapped by the key has not a valid number format.

getDouble

public double getDouble(String key,
                        double defaultValue)
Gets a double property value with a default.

Parameters:
key - the key of the property.
defaultValue - the default value.
Returns:
the value of the property or the default.
Throws:
ClassCastException - if the key maps to an object that is not a Double.
NumberFormatException - if the value mapped by the key has not a valid number format.

getDouble

public Double getDouble(String key,
                        Double defaultValue)
Gets a Double property value with a default.

Parameters:
key - the key of the property.
defaultValue - the default value.
Returns:
the value of the property or the default.
Throws:
ClassCastException - if the key maps to an object that is not a double.
NumberFormatException - if the value mapped by the key has not a valid number format.

addProperties

public void addProperties(int index,
                          String key,
                          String[] values,
                          String separator)
Adds multivalued property values at the specified index with the specified separator.

Parameters:
index - the index (-1 = end).
key - the key of the property.
values - the values of the property.
separator - the item separator.


Copyright © 2004 The Norther Organization. All rights reserved.