|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjava.util.AbstractMap
org.norther.tammi.acorn.util.ConcurrentAbstractMap
org.norther.tammi.acorn.util.ConcurrentReadMap
org.norther.tammi.acorn.util.OrderedHashMap
org.norther.tammi.core.config.Configuration
public class Configuration
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:
key = value, or
alternatively key: value.include = additional.propertieswill include the additional.properties file as if it was part of the original property file. The suffix of the include property, e.g. "include.resource", is used as a key for the path finder. The root folder is applied if the key is not specified.
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.
| 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.Entry |
| 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(int index,
Object key,
Object value)
Associates the specified value with the specified key to the specified index in this map if not already mapped. |
boolean |
add(Object key,
Object value)
Associates the specified value with the specified key in this map if not already mapped. |
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(int index,
String key,
String[] values)
Adds multivalued property values 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 |
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 |
getLastInitialized()
Gets the timestamp of the last initialization of the traced object. |
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. |
String |
getNull()
Gets the null value. |
static String |
getNullKey()
Gets the property key for a 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 |
loadFromXML(InputStream input)
Loads the properties represented by the XML document on the specified input stream into this configuration. |
void |
merge(Map map)
Merges the specified map to this configuration. |
Enumeration |
propertyNames()
Returns an enumeration of all property names including the defaults. |
Object |
put(int index,
Object key,
Object value)
Associates the specified value with the specified key to the specified index in this map. |
Object |
put(Object key,
Object value)
|
Object |
putIfAbsent(int index,
Object key,
Object value)
Associates the specified value with the specified key to the specified index in this map if not already mapped. |
Object |
putIfAbsent(Object key,
Object value)
|
Object |
remove(int index)
Removes the indexed element in this map. |
Object |
remove(Object key)
|
boolean |
remove(Object key,
Object value)
|
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(Object key,
Object value)
|
boolean |
replace(Object 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 separ)
Sets the item separator(s). |
void |
setKeyDelimiter(String delim)
Sets the key delimiter(s). |
void |
setLastModified(Object key,
long timestamp)
Sets the timestamp of the last modification of the specified resource. |
void |
setNull(String nl)
Sets the null value. |
static void |
setNullKey(String key)
Sets the property key for a 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 |
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. |
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. |
static Configuration |
toConfiguration(Properties p)
Converts a standard properties class into a configuration class. |
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 |
|---|
entryList, entrySet, get, getEntryAt, getKeyAt, indexOfKey, isModifiable, keyList, keySet, putAll, putInternal, putInternal, removeInternal, valueList, values |
| Methods inherited from class org.norther.tammi.acorn.util.ConcurrentReadMap |
|---|
capacity, containsKey, containsValue, getEntry, getInternal, getReadTable, getWriteTable, isEmpty, recordWrite, rehash, replaceInternal, setWriteTable, size |
| Methods inherited from class org.norther.tammi.acorn.util.ConcurrentAbstractMap |
|---|
capacity, contains, elements, get, hash, keys |
| 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, size |
| Constructor Detail |
|---|
public Configuration()
public Configuration(Configuration defs)
defs - the default configuration.
public Configuration(String path)
throws IOException
path - the pathname of the properties file.
IOException - on I/O errors.
public Configuration(String path,
String defaultPath)
throws IOException
path - the pathname of the properties file.defaultPath - the pathname of the defaults file.
IOException - on I/O errors.public Configuration(MBeanReference reference)
reference - the MBean reference.
public Configuration(MBeanReference reference,
Configuration defs)
reference - the MBean reference.defs - the default configuration.
public Configuration(MBeanReference reference,
String path)
throws IOException
reference - the MBean reference.path - the pathname of the properties file.
IOException - on I/O errors.
public Configuration(MBeanReference reference,
String path,
String defaultPath)
throws IOException
reference - the MBean reference.path - the pathname of the properties file.defaultPath - the pathname of the defaults file.
IOException - on I/O errors.| Method Detail |
|---|
public static String getNullKey()
public static void setNullKey(String key)
key - the null value property key.public static String getDelimiterKey()
public static void setDelimiterKey(String key)
key - the key delimiter property key.public static String getSeparatorKey()
public static void setSeparatorKey(String key)
key - the list separator property key.public static String getIncludeKey()
public static void setIncludeKey(String key)
key - the include property key.public static Configuration toConfiguration(Properties p)
p - properties object to convert into a Configuration object.
public Object clone()
clone in class OrderedHashMappublic void clear()
clear in interface Mapclear in class OrderedHashMap
public Object put(Object key,
Object value)
put in interface Mapput in class ConcurrentAbstractMappublic Object remove(Object key)
remove in interface Mapremove in class ConcurrentAbstractMap
public Object putIfAbsent(Object key,
Object value)
putIfAbsent in interface ConcurrentMapputIfAbsent in class ConcurrentAbstractMap
public boolean add(Object key,
Object value)
ConcurrentAbstractMap
add in interface OrderedMapadd in class ConcurrentAbstractMapkey - key with which the specified value is to be associated.value - value to be associated with the specified key.
public Object replace(Object key,
Object value)
replace in interface ConcurrentMapreplace in class ConcurrentAbstractMap
public boolean replace(Object key,
Object oldValue,
Object newValue)
replace in interface ConcurrentMapreplace in class ConcurrentAbstractMap
public boolean remove(Object key,
Object value)
remove in interface ConcurrentMapremove in class ConcurrentAbstractMap
public Object put(int index,
Object key,
Object value)
OrderedMap
put in interface OrderedMapput in class OrderedHashMapindex - the index.key - key with which the specified value is to be associated.value - value to be associated with the specified key.
public Object putIfAbsent(int index,
Object key,
Object value)
OrderedMap
putIfAbsent in interface OrderedMapputIfAbsent in class OrderedHashMapindex - the index.key - key with which the specified value is to be associated.value - value to be associated with the specified key.
public boolean add(int index,
Object key,
Object value)
OrderedMap
add in interface OrderedMapadd in class OrderedHashMapindex - the index.key - key with which the specified value is to be associated.value - value to be associated with the specified key.
public Object replace(int index,
Object value)
OrderedMap
replace in interface OrderedMapreplace in class OrderedHashMapindex - the index.value - the new value.
public Object remove(int index)
OrderedMap
remove in interface OrderedMapremove in class OrderedHashMapindex - the index.
public long getLastInitialized()
Traceable
getLastInitialized in interface Traceablepublic long getLastModified()
Traceable
getLastModified in interface Traceablepublic long getLastModified(Object key)
Traceable
getLastModified in interface Traceablekey - the key of the resource.
public void setLastModified(Object key,
long timestamp)
Traceable
setLastModified in interface Traceablekey - the key of the resource.timestamp - the modification timestamp.public void addTraceListener(TraceListener listener)
Traceable
addTraceListener in interface Traceablelistener - a listener to add.public void removeTraceListener(TraceListener listener)
Traceable
removeTraceListener in interface Traceablelistener - the listener to remove.public void clearTraceListeners()
Traceable
clearTraceListeners in interface Traceablepublic String getNull()
public void setNull(String nl)
nl - the null.public String getKeyDelimiter()
public void setKeyDelimiter(String delim)
delim - the delimiters(s).public String getItemSeparator()
public void setItemSeparator(String separ)
separ - the separator(s).
public void loadFromXML(InputStream input)
throws IOException,
InvalidPropertiesFormatException
The XML document must be compatible with the following DTD:
<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
input - the input stream.
IOException - on I/O errors.
InvalidPropertiesFormatException - for invalid data.
public void storeToXML(OutputStream output,
String header)
throws IOException
The defaults are not included in the document by this method.
output - the output stream.header - an optional header.
IOException - on I/O errors.
public void storeToXML(OutputStream output,
String header,
String encoding)
throws IOException
The defaults are not included in the document by this method.
output - the output stream.header - an optional header.encoding - the encoding.
IOException - on I/O errors.
public void load(InputStream input)
throws IOException
java.util.Properties.
input - the input stream.
IOException - on I/O errors.
public void load(InputStream input,
String encoding)
throws IOException