|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.metamatrix.common.util.PropertiesUtils
public final class PropertiesUtils
Static utility methods for common tasks having to do with java.util.Properties.
Nested Class Summary | |
---|---|
static class |
PropertiesUtils.InvalidPropertyException
|
Constructor Summary | |
---|---|
PropertiesUtils()
|
Method Summary | |
---|---|
static java.util.Properties |
clone(java.util.Properties props)
Performs a correct deep clone of the properties object by capturing all properties in the default(s) and placing them directly into the new Properties object. |
static java.util.Properties |
clone(java.util.Properties props,
boolean makeUnmodifiable)
Performs a correct deep clone of the properties object by capturing all properties in the default(s) and placing them directly into the new Properties object. |
static java.util.Properties |
clone(java.util.Properties props,
java.util.Properties defaults,
boolean deepClone)
Performs a correct deep clone of the properties object by capturing all properties in the default(s) and placing them directly into the new Properties object. |
static java.util.Properties |
clone(java.util.Properties props,
java.util.Properties defaults,
boolean deepClone,
boolean makeUnmodifiable)
Performs a correct deep clone of the properties object by capturing all properties in the default(s) and placing them directly into the new Properties object. |
static int |
compare(java.util.Properties p1,
java.util.Properties p2)
This method implements a 'compareTo' logic for two Properties objects, equivalent to calling p1.compareTo(p2) if the
Properties class implemented
Comparable (which it does not). |
static void |
copyProperty(java.util.Properties srcProperties,
java.lang.String srcPropName,
java.util.Properties tgtProperties,
java.lang.String tgtPropName)
|
static java.util.List |
filter(java.lang.String pattern,
java.util.Properties props)
Returns a list of property names matching the given pattern. |
static boolean |
filterTest(java.lang.String pattern,
java.lang.String sCandidate)
Returns a boolean indicating whether the string matched the given pattern. |
static boolean |
getBooleanProperty(java.util.Properties props,
java.lang.String propName,
boolean defaultValue)
|
static double |
getDoubleProperty(java.util.Properties props,
java.lang.String propName,
double defaultValue)
|
static float |
getFloatProperty(java.util.Properties props,
java.lang.String propName,
float defaultValue)
|
static int |
getIntProperty(java.util.Properties props,
java.lang.String propName,
int defaultValue)
|
static long |
getLongProperty(java.util.Properties props,
java.lang.String propName,
long defaultValue)
|
static java.util.Properties |
getProperties(java.lang.String filterPattern,
java.util.Properties props)
Obtains from this source the list of all properties that match the pattern specified by the filter. |
static java.util.Properties |
load(java.lang.String fileName)
|
static java.util.Properties |
loadAsResource(java.lang.Class clazz,
java.lang.String resourceName)
|
static java.lang.String |
loadHeader(java.lang.String fileName)
Read the header part of a properties file into a String. |
static java.lang.String |
prettyPrint(java.util.Properties props)
|
static void |
print(java.io.PrintStream stream,
java.util.Properties props)
|
static void |
print(java.lang.String fileName,
java.util.Properties props)
Write the specified properties to the specified file, with the specified header. |
static void |
print(java.lang.String fileName,
java.util.Properties props,
java.lang.String header)
Write the specified properties to the specified file, with the specified header. |
static void |
putAll(java.util.Properties addToThis,
java.util.Properties withThese)
This method is intended to replace the use of the putAll
method of Properties inherited from java.util.Hashtable . |
static java.util.Properties |
resolveNestedProperties(java.util.Properties original)
The speciality of nested properties is, in a given property file there can be values with pattern like "${...}"
key1=value1
key2=${key1}/value2
where the value of the key2 should resolve to value1/value2
also if the property in the pattern ${..} is not found in the loaded
properties, then it will look up for the property value in the System
properties. |
static java.lang.String |
saveConvert(java.lang.String theString,
boolean escapeSpace)
|
static void |
setBeanProperties(java.lang.Object bean,
java.util.Properties props,
java.lang.String prefix)
|
static void |
setOverrideProperies(java.util.Properties base,
java.util.Properties override)
|
static java.util.Properties |
sort(java.util.Properties props)
|
static java.util.Collection |
sortPropertiesForPrinting(java.util.Properties props)
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public PropertiesUtils()
Method Detail |
---|
public static java.util.List filter(java.lang.String pattern, java.util.Properties props)
pattern
- The property name to match which may include a '*'.props
- The properties to search.
public static java.util.Properties getProperties(java.lang.String filterPattern, java.util.Properties props)
The filter is a string that may contain the '*' character as a wildcard one or more times in the string. For example, the following filter:
*metamatrix.*
finds all properties that contain somewhere in the property name the string "metamatrix.".
filterPattern
- the string filter pattern that will be used to narrow the set of properties returned.props
- The properties to search.
public static java.util.Properties clone(java.util.Properties props)
UnmodifiableProperties
, this method returns an
UnmodifiableProperties
instance around a new (flattened)
copy of the underlying Properties object.
public static java.util.Properties clone(java.util.Properties props, boolean makeUnmodifiable)
UnmodifiableProperties
instance around a new (flattened)
copy of the underlying Properties object.
public static java.util.Properties clone(java.util.Properties props, java.util.Properties defaults, boolean deepClone)
UnmodifiableProperties
, this method returns an
UnmodifiableProperties
instance around a new (flattened)
copy of the underlying Properties object.
public static java.util.Properties clone(java.util.Properties props, java.util.Properties defaults, boolean deepClone, boolean makeUnmodifiable)
UnmodifiableProperties
instance around a new (flattened)
copy of the underlying Properties object.
public static int compare(java.util.Properties p1, java.util.Properties p2)
p1.compareTo(p2)
if the
Properties
class implemented
Comparable
(which it does not).
p1
- the first Properties instance to compare; may be nullp2
- the second Properties instance to compare; may be null
p1
is less than, equal to, or greater than p2
, respectively.public static void putAll(java.util.Properties addToThis, java.util.Properties withThese)
This method is intended to replace the use of the putAll
method of Properties
inherited from java.util.Hashtable
.
The problem with that method is that, since it is inherited from
Hashtable
, default properties are lost.
For example, the following code
Properties a;
Properties b;
//initialize ...
a.putAll(b);
will fail if b
had been constructed with a default
Properties
object. Those defaults would be lost and
not added to a
.
The above code could be correctly performed with this method, like this:
Properties a;
Properties b;
//initialize ...
PropertiesUtils.putAll(a,b);
In the above example, a
is modified - properties are added to
it (note that if a
has defaults they will remain unaffected.)
The properties from b
, including defaults, will be
added to a
using its setProperty
method -
these new properties will overwrite any pre-existing ones of the same
name.
addToThis
- This Properties object is modified; the properties
of the other parameter are added to this. The added property values
will replace any current property values of the same names.withThese
- The properties (including defaults) of this
object are added to the "addToThis" parameter.public static void setOverrideProperies(java.util.Properties base, java.util.Properties override)
public static int getIntProperty(java.util.Properties props, java.lang.String propName, int defaultValue) throws PropertiesUtils.InvalidPropertyException
PropertiesUtils.InvalidPropertyException
public static long getLongProperty(java.util.Properties props, java.lang.String propName, long defaultValue)
public static float getFloatProperty(java.util.Properties props, java.lang.String propName, float defaultValue)
public static double getDoubleProperty(java.util.Properties props, java.lang.String propName, double defaultValue)
public static boolean getBooleanProperty(java.util.Properties props, java.lang.String propName, boolean defaultValue)
public static java.lang.String loadHeader(java.lang.String fileName) throws java.io.IOException
fileName
-
java.io.IOException
public static java.util.Properties load(java.lang.String fileName) throws java.io.IOException
java.io.IOException
public static java.util.Properties loadAsResource(java.lang.Class clazz, java.lang.String resourceName) throws java.io.IOException
java.io.IOException
public static java.util.Properties sort(java.util.Properties props)
public static void print(java.lang.String fileName, java.util.Properties props, java.lang.String header) throws java.io.IOException
fileName
- props
- header
-
java.io.IOException
public static void print(java.lang.String fileName, java.util.Properties props) throws java.io.IOException
java.io.IOException
public static void print(java.io.PrintStream stream, java.util.Properties props)
public static java.lang.String prettyPrint(java.util.Properties props)
public static java.util.Collection sortPropertiesForPrinting(java.util.Properties props)
public static java.lang.String saveConvert(java.lang.String theString, boolean escapeSpace)
public static final void copyProperty(java.util.Properties srcProperties, java.lang.String srcPropName, java.util.Properties tgtProperties, java.lang.String tgtPropName)
public static java.util.Properties resolveNestedProperties(java.util.Properties original) throws java.io.IOException
key1=value1
key2=${key1}/value2
where the value of the key2
should resolve to value1/value2
also if the property in the pattern ${..}
is not found in the loaded
properties, then it will look up for the property value in the System
properties. Multiple nesting is OK, however recursive nested is not good, and
behaviour is undocumented in this case.
original
- - Original properties to be resolved
java.io.IOException
public static boolean filterTest(java.lang.String pattern, java.lang.String sCandidate)
pattern
- The property name to match which may include a '*'.props
- The properties to search.
public static void setBeanProperties(java.lang.Object bean, java.util.Properties props, java.lang.String prefix)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |