|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.continuent.tungsten.common.config.TungstenProperties
public class TungstenProperties
Defines a simple HashMap wrapper that can be used to store and retrieve properties using typed getters and setters. There is support for serializing to and from Java properties format, setting variables, merging properties, and other niceties.
| Field Summary | |
|---|---|
static java.lang.String |
ENDOFLINE_TAG
|
static java.lang.String |
ENDOFPROPERTIES_TAG
|
protected java.util.Map<java.lang.String,java.lang.Object> |
properties
|
| Constructor Summary | |
|---|---|
TungstenProperties()
Creates a new instance. |
|
TungstenProperties(boolean sorted)
Creates a new instance with sorting. |
|
TungstenProperties(java.util.Map<java.lang.String,java.lang.String> map)
Creates a new instance from an existing map. |
|
| Method Summary | |
|---|---|
void |
add(java.io.InputStream is)
Loads values from Java properties file format with variable substitutions. |
void |
add(java.io.InputStream is,
boolean doSubstitutions)
Adds values from Java properties file format. |
void |
add(java.util.Properties props)
Load values from a Properties instance. |
java.util.Map<java.lang.String,java.lang.Object> |
any()
|
void |
applyProperties(java.lang.Object o)
Applies the current properties to the given object, stopping and throwing errors if a property has no matching setter in the given object. |
void |
applyProperties(java.lang.Object o,
boolean ignoreIfMissing)
Applies the properties in the TungstenProperties object to corresponding properties on a Java object by matching property names to setter methods on the object. |
void |
clear()
Clears all property values so that the underlying map is empty. |
boolean |
containsKey(java.lang.String key)
Returns true if the indicated property key exists. |
static TungstenProperties |
createFromStream(java.io.BufferedReader in)
Receives properties from given stream. This function uses a in-house protocol consisting in having, for each key/value pair, 1 line for key, 1 line for the class name and 1 for value. |
boolean |
equals(java.lang.Object o)
Returns true if the argument contains exactly the same property values as this properties instance. |
void |
extractProperties(java.lang.Object o,
boolean ignoreIfUnsupported)
Create a set of initialized properties from the set of fields in a specific object instance. |
static java.lang.String |
formatProperties(java.lang.String name,
TungstenProperties props,
java.lang.String header)
|
java.lang.String |
get(java.lang.String key)
|
boolean |
getBoolean(java.lang.String key)
|
boolean |
getBoolean(java.lang.String key,
java.lang.String defaultValue,
boolean required)
|
java.util.Map<java.lang.String,java.util.Map<java.lang.String,TungstenProperties>> |
getClusterMap()
Retrieves a cluster map as stored by setClusterMap(Map) |
java.util.Map<java.lang.String,TungstenProperties> |
getDataSourceMap()
Retrieves a data source map as stored by setDataSourceMap(Map) |
java.util.Date |
getDate(java.lang.String key)
|
java.util.Date |
getDate(java.lang.String key,
java.lang.String defaultValue,
boolean required)
|
double |
getDouble(java.lang.String key)
|
double |
getDouble(java.lang.String key,
java.lang.String defaultValue,
boolean required)
|
java.io.File |
getFile(java.lang.String key)
|
java.io.File |
getFile(java.lang.String key,
java.lang.String defaultValue,
boolean required)
|
float |
getFloat(java.lang.String key)
|
float |
getFloat(java.lang.String key,
java.lang.String defaultValue,
boolean required)
|
int |
getInt(java.lang.String key)
|
int |
getInt(java.lang.String key,
java.lang.String defaultValue,
boolean required)
|
Interval |
getInterval(java.lang.String key)
Returns an interval value. |
Interval |
getInterval(java.lang.String key,
java.lang.String defaultValue,
boolean required)
Returns an interval or the default value. |
long |
getLong(java.lang.String key)
|
long |
getLong(java.lang.String key,
java.lang.String defaultValue,
boolean required)
|
java.lang.Object |
getObject(java.lang.String key)
|
java.lang.Object |
getObject(java.lang.String key,
java.lang.Object defaultValue,
boolean required)
Given a key, gets the object |
java.util.Properties |
getProperties()
Get an instances of Properties that is populated by the current values of the instance on which it's called. |
java.lang.String |
getProperty(java.lang.String key)
|
java.lang.String |
getProperty(java.lang.String key,
java.lang.String defaultValue)
|
java.lang.String |
getString(java.lang.String key)
|
java.lang.String |
getString(java.lang.String key,
java.lang.String defaultValue,
boolean required)
Returns the value as a String with an optional default value and checking to ensure value is present if required |
java.util.List<java.lang.String> |
getStringList(java.lang.String key)
Returns a list of strings from a value containing a list of string values separated by commas or whitespace characters. |
TungstenProperties |
getTungstenProperties(java.lang.String key)
Returns a TungstenProperties value. |
java.util.HashMap<java.lang.String,java.lang.String> |
hashMap()
Returns a shallow copy of the underlying map as a HashMap. |
boolean |
isBean(java.lang.Class<?> clazz)
Returns true if the class in question is supports JavaBean conventions by having a default constructor and setters/getters for properties. |
boolean |
isBeanSupportEnabled()
Returns true if this instance supports extracting/setting bean properties. |
boolean |
isEmpty()
Returns true if properties map is empty. |
java.util.Set<java.lang.String> |
keyNames()
Returns keys of all properties currently stored in this instance. |
java.util.Set<java.lang.String> |
keyNames(java.lang.String prefix)
Returns keys of all properties where the key name matches the provided prefix. |
static java.lang.String |
listToString(java.util.List<java.lang.String> list)
TODO: listToString definition. |
void |
load(java.io.InputStream is)
Loads values from Java properties file format with variable substitutions. |
void |
load(java.io.InputStream is,
boolean doSubstitutions)
Loads values from Java properties file format. |
void |
load(java.util.Properties props)
Load values from a Properties instance. |
void |
load(java.lang.String nameValuePairs,
boolean doSubstitutions)
Loads values from a string of name-value pairs of the form a=1;b=2;...;z=N. |
static TungstenProperties |
loadFromJSON(java.lang.String json)
Load values from a JSON serialized string |
java.util.Map<java.lang.String,java.lang.String> |
map()
Returns a shallow copy of the underlying map as a generic Map. |
void |
put(java.lang.Object key,
java.lang.Object value)
|
void |
put(java.lang.String key,
java.lang.String value)
Utility method to help with compatibility with Properties |
void |
putAll(TungstenProperties props)
Merges the properties provided as an argument with these properties, overriding current values wherever there are overlaps. |
void |
putAllWithPrefix(TungstenProperties props,
java.lang.String prefix)
Prefixes all the given properties with the given string and merges this new set with the actual ones, overriding current values with same keys if any |
java.lang.String |
remove(java.lang.String key)
Removes the property indicated by the key, if it exists, and returns the value. |
void |
send(java.io.PrintWriter out)
Sends this object's set of properties on the given stream. |
void |
set(java.lang.String name,
java.lang.Object value)
|
void |
setBeanSupportEnabled(boolean beanSupportEnabled)
If set to true this instance will support extracting/setting bean properties. |
void |
setBoolean(java.lang.String key,
boolean value)
|
void |
setClusterMap(java.util.Map<java.lang.String,java.util.Map<java.lang.String,TungstenProperties>> map)
Stores a Map which keys are strings and values are Maps of String/TungstenProperties. |
void |
setDataSourceMap(java.util.Map<java.lang.String,TungstenProperties> map)
Stores a Map which keys are strings and values are TungstenProperties. |
void |
setDate(java.lang.String key,
java.util.Date value)
Date type is stored as a long representing the number of milliseconds since January 1, 1970, 00:00:00 GMT as retrieved by Date.getTime() |
void |
setDouble(java.lang.String key,
double value)
|
void |
setFile(java.lang.String key,
java.io.File value)
|
void |
setFloat(java.lang.String key,
float value)
|
void |
setInt(java.lang.String key,
int value)
|
void |
setInterval(java.lang.String key,
Interval value)
Stores a time interval provided as an object by converting to an interval instance. |
void |
setInterval(java.lang.String key,
java.lang.Long value)
Stores a time interval provided in milliseconds, which is the base representation. |
void |
setLong(java.lang.String key,
long value)
|
void |
setObject(java.lang.String key,
java.lang.Object value)
Sets the property value from an object using its toString() method. |
void |
setProperty(java.lang.String key,
java.lang.String value)
Utility method to help with compatibility with Properties |
void |
setString(java.lang.String key,
java.lang.String value)
Sets the value as a string. |
void |
setStringList(java.lang.String key,
java.util.List<java.lang.String> list)
Sets a value from a String list. |
void |
setTungstenProperties(java.lang.String key,
TungstenProperties tungstenProperties)
Stores a TungstenProperties as a property |
int |
size()
Returns the number of properties in this instance. |
void |
store(java.io.OutputStream os)
Stores values in Java properties file format. |
TungstenProperties |
subset(java.lang.String prefix,
boolean removePrefix)
Returns a TungstenProperties instance consisting of the property names that match the given prefix |
TungstenProperties |
subset(java.lang.String prefix,
boolean removePrefix,
boolean removeProps)
Returns a TungstenProperties instance consisting of the property names that match the given prefix |
static int |
substituteSystemValues(java.util.Properties props)
Scan Properties instance values replacing any expression of the form ${name} where 'name' is a key in System.properties *or* a local property in the same file, where local property substitutions take priority over system property names. |
static int |
substituteSystemValues(java.util.Properties props,
int iterations)
Substitute system values up to a certain number of times. |
java.lang.String |
toJSON()
|
java.lang.String |
toJSON(boolean prettyPrint)
Serialize the TungstenProperties into a JSON String |
java.lang.String |
toNameValuePairs()
Returns values as a string of name/value pairs that can be loaded using load(String, boolean). |
java.lang.String |
toString()
Returns toString of underlying properties rather than wrapper. |
void |
trim()
Trims all property values to remove leading and trailing whitespace. |
| Methods inherited from class java.lang.Object |
|---|
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
public static final java.lang.String ENDOFPROPERTIES_TAG
public static final java.lang.String ENDOFLINE_TAG
protected java.util.Map<java.lang.String,java.lang.Object> properties
| Constructor Detail |
|---|
public TungstenProperties()
public TungstenProperties(java.util.Map<java.lang.String,java.lang.String> map)
public TungstenProperties(boolean sorted)
| Method Detail |
|---|
public java.util.Map<java.lang.String,java.lang.Object> any()
public void set(java.lang.String name,
java.lang.Object value)
public boolean isBeanSupportEnabled()
public void setBeanSupportEnabled(boolean beanSupportEnabled)
beanSupportEnabled -
public void load(java.io.InputStream is)
throws java.io.IOException
java.io.IOException
public void load(java.io.InputStream is,
boolean doSubstitutions)
throws java.io.IOException
is - InputStream containing properties.doSubstitutions - If true perform variable substitutions
java.io.IOException
public void load(java.lang.String nameValuePairs,
boolean doSubstitutions)
public static TungstenProperties loadFromJSON(java.lang.String json)
throws org.codehaus.jackson.JsonParseException,
org.codehaus.jackson.map.JsonMappingException,
java.io.IOException
json - The JSON serialized string
org.codehaus.jackson.JsonParseException
org.codehaus.jackson.map.JsonMappingException
java.io.IOExceptionpublic java.util.Properties getProperties()
public void load(java.util.Properties props)
public static int substituteSystemValues(java.util.Properties props,
int iterations)
public static int substituteSystemValues(java.util.Properties props)
public void store(java.io.OutputStream os)
throws java.io.IOException
java.io.IOExceptionpublic void applyProperties(java.lang.Object o)
applyProperties(o, false)
o - instance on which to set properties
public void applyProperties(java.lang.Object o,
boolean ignoreIfMissing)
o - Instance for which we are to set propertiesignoreIfMissing - whether or not stop and throw an error if a
property has no matching setting in the given object instance
PropertyException - Thrown if we cannot find a setter for a
property or if invocation of the setter fails
public void extractProperties(java.lang.Object o,
boolean ignoreIfUnsupported)
o - ignoreIfUnsupported - public void trim()
public java.lang.String remove(java.lang.String key)
public void clear()
public boolean isEmpty()
public java.util.Set<java.lang.String> keyNames()
public java.util.Set<java.lang.String> keyNames(java.lang.String prefix)
public boolean containsKey(java.lang.String key)
public int size()
public void putAll(TungstenProperties props)
public void putAllWithPrefix(TungstenProperties props,
java.lang.String prefix)
public void setString(java.lang.String key,
java.lang.String value)
public void setProperty(java.lang.String key,
java.lang.String value)
key - value -
public void put(java.lang.Object key,
java.lang.Object value)
public void put(java.lang.String key,
java.lang.String value)
key - value -
public void setObject(java.lang.String key,
java.lang.Object value)
public void setInt(java.lang.String key,
int value)
public void setLong(java.lang.String key,
long value)
public void setFloat(java.lang.String key,
float value)
public void setDouble(java.lang.String key,
double value)
public void setBoolean(java.lang.String key,
boolean value)
public void setFile(java.lang.String key,
java.io.File value)
public void setDate(java.lang.String key,
java.util.Date value)
Date.getTime()
key - unique identifier for this propertyvalue - the date to store
public void setStringList(java.lang.String key,
java.util.List<java.lang.String> list)
getStringList(String).
public void setInterval(java.lang.String key,
java.lang.Long value)
public void setInterval(java.lang.String key,
Interval value)
public void setTungstenProperties(java.lang.String key,
TungstenProperties tungstenProperties)
key - the key to identify the propertytungstenProperties - the TungstenProperties to storepublic void setDataSourceMap(java.util.Map<java.lang.String,TungstenProperties> map)
Each TungstenProperties entry in the given map will be stored in this object with its keys prefixed by the corresponding map key + its own key, separated by MAP_KEY_SEPARATOR
Note that none of the TungstenProperties in the given map can be null
map - the map to storepublic void setClusterMap(java.util.Map<java.lang.String,java.util.Map<java.lang.String,TungstenProperties>> map)
Each entry in the given map will be stored in this object with its keys prefixed by the corresponding map key + MAP_KEY_SEPARATOR + its own key + MAP_KEY_SEPARATOR + its Tungsten properties key.
Note that none of the TungstenProperties in the given map can be null
map - the map to store
public java.lang.Object getObject(java.lang.String key,
java.lang.Object defaultValue,
boolean required)
key - defaultValue - required -
public java.lang.String getString(java.lang.String key,
java.lang.String defaultValue,
boolean required)
key - The name of the propertydefaultValue - An optional default valuerequired - If true, a value or default must be present
PropertyException - if the value is required but does not existpublic java.lang.String getString(java.lang.String key)
public java.lang.String getProperty(java.lang.String key,
java.lang.String defaultValue)
public java.lang.String getProperty(java.lang.String key)
public java.lang.String get(java.lang.String key)
public java.lang.Object getObject(java.lang.String key)
public int getInt(java.lang.String key)
public int getInt(java.lang.String key,
java.lang.String defaultValue,
boolean required)
public long getLong(java.lang.String key)
public long getLong(java.lang.String key,
java.lang.String defaultValue,
boolean required)
public float getFloat(java.lang.String key)
public float getFloat(java.lang.String key,
java.lang.String defaultValue,
boolean required)
public double getDouble(java.lang.String key)
public double getDouble(java.lang.String key,
java.lang.String defaultValue,
boolean required)
public boolean getBoolean(java.lang.String key)
public boolean getBoolean(java.lang.String key,
java.lang.String defaultValue,
boolean required)
public java.io.File getFile(java.lang.String key)
public java.io.File getFile(java.lang.String key,
java.lang.String defaultValue,
boolean required)
public java.util.Date getDate(java.lang.String key,
java.lang.String defaultValue,
boolean required)
public java.util.Date getDate(java.lang.String key)
public java.util.List<java.lang.String> getStringList(java.lang.String key)
public Interval getInterval(java.lang.String key,
java.lang.String defaultValue,
boolean required)
public Interval getInterval(java.lang.String key)
public TungstenProperties getTungstenProperties(java.lang.String key)
key - identifying the property
public java.util.Map<java.lang.String,TungstenProperties> getDataSourceMap()
setDataSourceMap(Map)
public java.util.Map<java.lang.String,java.util.Map<java.lang.String,TungstenProperties>> getClusterMap()
setClusterMap(Map)
public java.util.Map<java.lang.String,java.lang.String> map()
public java.util.HashMap<java.lang.String,java.lang.String> hashMap()
public java.lang.String toNameValuePairs()
load(String, boolean).
public TungstenProperties subset(java.lang.String prefix,
boolean removePrefix)
prefix - Return only those properties that match the prefixremovePrefix - If true remove the prefix from each property name
public TungstenProperties subset(java.lang.String prefix,
boolean removePrefix,
boolean removeProps)
prefix - Return only those properties that match the prefixremovePrefix - If true remove the prefix from each property nameremoveProps - If true remove the matching key/value pairs from these
propertiespublic boolean equals(java.lang.Object o)
equals in class java.lang.Objectpublic java.lang.String toString()
toString in class java.lang.Object
public java.lang.String toJSON()
throws org.codehaus.jackson.JsonGenerationException,
org.codehaus.jackson.map.JsonMappingException,
java.io.IOException
org.codehaus.jackson.JsonGenerationException
org.codehaus.jackson.map.JsonMappingException
java.io.IOException
public java.lang.String toJSON(boolean prettyPrint)
throws org.codehaus.jackson.JsonGenerationException,
org.codehaus.jackson.map.JsonMappingException,
java.io.IOException
prettyPrint - Set to true to have the JSON output formatted for
easier read
org.codehaus.jackson.JsonGenerationException
org.codehaus.jackson.map.JsonMappingException
java.io.IOException
public static java.lang.String formatProperties(java.lang.String name,
TungstenProperties props,
java.lang.String header)
public static TungstenProperties createFromStream(java.io.BufferedReader in)
throws java.io.IOException
in - a ready-to-be-read buffered reader from which to get properties
java.io.IOException - upon error while reading on the given input stream,
or if no data can be read at all
java.lang.ClassNotFoundException
java.lang.NoSuchMethodException
java.lang.SecurityException
java.lang.reflect.InvocationTargetException
java.lang.IllegalAccessException
java.lang.InstantiationException
java.lang.IllegalArgumentExceptionsend(PrintWriter)public void send(java.io.PrintWriter out)
out - a prepared PrintWriter output stream on which to send
propertiescreateFromStream(BufferedReader)public boolean isBean(java.lang.Class<?> clazz)
public static java.lang.String listToString(java.util.List<java.lang.String> list)
public void add(java.io.InputStream is)
throws java.io.IOException
java.io.IOException
public void add(java.io.InputStream is,
boolean doSubstitutions)
throws java.io.IOException
is - InputStream containing properties.doSubstitutions - If true perform variable substitutions
java.io.IOExceptionpublic void add(java.util.Properties props)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||