|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object java.util.Dictionary<K,V> java.util.Hashtable<String,String> com.jalios.util.JProperties
public class JProperties
This class, based on Properties
manage properties file in UTF-8 encoding.
Its save updateAndSave(File)
methods keep layout of previous properties file.
Field Summary | |
---|---|
protected Set<JPropertiesListener> |
listenerSet
|
protected boolean |
propertyNameAsDefaultValue
|
static String |
REVISION
|
Constructor Summary | |
---|---|
JProperties()
|
Method Summary | |
---|---|
void |
addProperties(JProperties prop)
Add every property of the given JProperties to
this JProperties . |
void |
addProperties(Properties prop)
Add every property of the given Properties to
this JProperties . |
void |
addPropertiesListener(JPropertiesListener l)
Adds a listener for any change of this JProperties. |
protected static String[] |
buildArrayFromString(String value,
String[] defaultValue)
Convert a string to a String[] using the following formats: "@ |
void |
clearProperties()
Clear all properties. |
boolean |
containsProperty(String name)
Tests if this JProperties contains the given property key/name. |
void |
firePropertiesChange()
Triggers a propertie change to notify all listener of this JProperties. |
boolean |
getBooleanProperty(String name,
boolean defaultValue)
Gets the value of a property as a boolean given its key/name. |
double |
getDoubleProperty(String name,
double defaultValue)
Gets the value of a property as a double value given its key/name. |
float |
getFloatProperty(String name,
float defaultValue)
Gets the value of a property as a float value given its key/name. |
int[] |
getIntArrayProperty(String name,
int[] defaultValue)
Gets the value of a property as a int array. |
int |
getIntegerProperty(String name,
int defaultValue)
Gets the value of a property as an int value given its key/name. |
protected Set<JPropertiesListener> |
getListenerSet()
Retrieve set of all listeners for this JProperties. |
long |
getLongProperty(String name,
long defaultValue)
Gets the value of a property as a long value given its key/name. |
JProperties |
getProperties(String prefix)
Returns a new property set of properties with key matching a given prefix. |
String |
getProperty(String name)
Gets value of a property. |
String |
getProperty(String name,
String defaultValue)
Gets the value of a property given its key/name. |
String[] |
getStringArrayProperty(String name,
String[] defaultValue)
Gets the value of a property as a String array. |
Map<String,Object> |
getSubProperties(String prefix)
Returns a map of properties built from those properties and having a given prefix. Example: prop: foo.bar.case1.x: value of x for case1 foo.bar.case1.y: value of y for case1 foo.bar.case2.x: value of x for case2 foo.bar.case2.y: value of y for case2 foo.bar.case2.z.t: value of z for case2 |
void |
load(File file)
Reads a property file (key and element pairs) from the given File. |
void |
load(File file,
String prefix)
Reads a property file (key and element pairs) from the given File. |
void |
removePropertiesListener(JPropertiesListener l)
Removes a listener for any change of this JProperties. |
Object |
setProperty(String name,
String value)
Sets value of a property. |
void |
updateAndSave(File file)
Updates and save properties. |
Methods inherited from class java.util.Hashtable |
---|
clear, clone, contains, containsKey, containsValue, elements, entrySet, equals, get, hashCode, isEmpty, keys, keySet, put, putAll, rehash, remove, size, toString, values |
Methods inherited from class java.lang.Object |
---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final String REVISION
protected boolean propertyNameAsDefaultValue
protected Set<JPropertiesListener> listenerSet
Constructor Detail |
---|
public JProperties()
Method Detail |
---|
protected Set<JPropertiesListener> getListenerSet()
addPropertiesListener(JPropertiesListener)
,
removePropertiesListener(JPropertiesListener)
public void addPropertiesListener(JPropertiesListener l)
l
- the listener to addremovePropertiesListener(JPropertiesListener)
public void removePropertiesListener(JPropertiesListener l)
l
- the listener to removeaddPropertiesListener(JPropertiesListener)
public void firePropertiesChange()
addPropertiesListener(JPropertiesListener)
public boolean containsProperty(String name)
name
- the key/name of the property to check
public String getProperty(String name)
name
- the key/name of the property to retrieve
public String getProperty(String name, String defaultValue)
name
- the key/name of the property to retrievedefaultValue
- the default value to use if the existing value is null.
public Object setProperty(String name, String value)
name
- the key/name of the property to retrievevalue
- the new value to assign.
public boolean getBooleanProperty(String name, boolean defaultValue)
name
- the key/name of the property to retrievedefaultValue
- the default value to use if the existing value
is null or is neither "false" nor "true" (case sensitive).
public int getIntegerProperty(String name, int defaultValue)
name
- the key/name of the property to retrievedefaultValue
- the default value to use if the existing value
is null or if Integer.parseInt() throws exception during String
to int conversion.
public long getLongProperty(String name, long defaultValue)
name
- the key/name of the property to retrievedefaultValue
- the default value to use if the existing value
is null or if Long.parseLong() throws exception during String
to long conversion.
public float getFloatProperty(String name, float defaultValue)
name
- the key/name of the property to retrievedefaultValue
- the default value to use if the existing value
is null or if Float.parseFloat() throws exception during String
to float conversion.
public double getDoubleProperty(String name, double defaultValue)
name
- the key/name of the property to retrievedefaultValue
- the default value to use if the existing value
is null or if Double.parseDouble() throws exception during String
to double conversion.
public String[] getStringArrayProperty(String name, String[] defaultValue)
name
- the key/name of the property to retrievedefaultValue
- the default value to use if the existing value
is null or no values could be found in the conversion.
protected static String[] buildArrayFromString(String value, String[] defaultValue)
public int[] getIntArrayProperty(String name, int[] defaultValue)
getStringArrayProperty(String, String[])
.
name
- the key/name of the property to retrievedefaultValue
- the default value to use if the existing value
is null or no values could be found in the conversion.
getStringArrayProperty(String, String[])
public void addProperties(Properties prop)
Properties
to
this JProperties
.
prop
- the properties to be addedpublic void addProperties(JProperties prop)
JProperties
to
this JProperties
.
prop
- the jproperties to be addedpublic JProperties getProperties(String prefix)
prefix
- the prefix the properties must match to be added to the
returned JProperties instance, if null, all properties are added.
public Map<String,Object> getSubProperties(String prefix)
foo.bar.case1.x: value of x for case1
foo.bar.case1.y: value of y for case1
foo.bar.case2.x: value of x for case2
foo.bar.case2.y: value of y for case2
foo.bar.case2.z.t: value of z for case2
prop.getSubProperties("foo.bar.")
returns a Map with the keys case1
and case2
.
A JProperties is bound to case1
and it contains the properties:
x: value of x for case1
y: value of y for case1
A JProperties is bound to case2
and it contains the properties:
x: value of x for case2
y: value of y for case2
z.t: value of z for case2
prefix
- the prefix
public void clearProperties()
public void load(File file) throws IOException
file
- the file from which to read properties.
IOException
- if an error occurred when reading from the input
stream.
IllegalArgumentException
- if the input stream contains a malformed
Unicode escape sequence.Properties.load(java.io.InputStream)
public void load(File file, String prefix) throws IOException
file
- the file from which to read properties.prefix
- a prefix to use add to all properties' name.
if null, no prefix is used.
IOException
- if an error occurred when reading from the input
stream.
IllegalArgumentException
- if the input stream contains a malformed
Unicode escape sequence.Properties.load(java.io.InputStream)
public void updateAndSave(File file) throws IOException
file
- the properties File to read and update.
IOException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |