Top Description Fields Constructors Methods
org.hibernate.util

public final Class PropertiesHelper

extends Object
Class Inheritance
Imports
java.util.HashMap, .Map, .Properties, .StringTokenizer, .Iterator

Collection of helper methods for dealing with java.util.Properties objects.
Authors
Gavin King, Steve Ebersole

Field Summary

Modifier and TypeField and Description
private static final String

Constructor Summary

AccessConstructor and Description
private
PropertiesHelper()

Disallow instantiation

Method Summary

Modifier and TypeMethod and Description
private static String
extractFromSystem(String systemPropertyName)

public static String

Returns:

The property value; may be null.
extractPropertyValue
(String
The name of the property for which to extract value
propertyName
,
Properties
The properties object
properties
)

Extract a property value by name from the given properties object.

public static boolean

Returns:

The property value.
getBoolean
(String
The name of the property for which to retrieve value
propertyName
,
Properties
The properties object
properties
)

Get a property value as a boolean.

public static boolean

Returns:

The property value.
getBoolean
(String
The name of the property for which to retrieve value
propertyName
,
Properties
The properties object
properties
,
boolean
The default property value to use.
defaultValue
)

Get a property value as a boolean.

public static int

Returns:

The property value.
getInt
(String
The name of the property for which to retrieve value
propertyName
,
Properties
The properties object
properties
,
int
The default property value to use.
defaultValue
)

Get a property value as an int.

public static Integer

Returns:

The property value; may be null.
getInteger
(String
The name of the property for which to retrieve value
propertyName
,
Properties
The properties object
properties
)

Get a property value as an Integer.

public static String

Returns:

The property value; may be null.
getString
(String
The name of the property for which to retrieve value
propertyName
,
Properties
The properties object
properties
,
String
The default property value to use.
defaultValue
)

Get a property value as a string.

public static Properties

Returns:

cloned and masked properties
maskOut
(Properties
properties to check
props
,
String
proeprty to mask
key
)

replace a property by a starred version

public static String

Returns:

The (possibly) interpolated property value.
resolvePlaceHolder
(String
The property value to be processed for interpolation.
property
)

Handles interpolation processing for a single property.

public static void
resolvePlaceHolders(Properties
The properties object.
properties
)

Handles interpolation processing for all entries in a properties object.

public static Map<K, V>

Returns:

The resulting map; never null, though perhaps empty.
toMap
(String
The name of the property for which to retrieve value
propertyName
,
String
The string defining tokens used as both entry and key/value delimiters.
delim
,
Properties
The properties object
properties
)

Constructs a map from a property value.

public static String[]

Returns:

The array; never null, though may be empty.
toStringArray
(String
The name of the property for which to retrieve value
propertyName
,
String
The delimiter used to separate individual array elements.
delim
,
Properties
The properties object
properties
)

Get a property value as a string array.

public static String[]

Returns:

The array; never null, though may be empty.
toStringArray
(String
The string form of the string array.
stringForm
,
String
The delimiter used to separate individual array elements.
delim
)

Convert a string to an array of strings.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

PLACEHOLDER_STARTback to summary
private static final String PLACEHOLDER_START

Constructor Detail

PropertiesHelperback to summary
private PropertiesHelper()

Disallow instantiation

Method Detail

extractFromSystemback to summary
private static String extractFromSystem(String systemPropertyName)
extractPropertyValueback to summary
public static String extractPropertyValue(String propertyName, Properties properties)

Extract a property value by name from the given properties object.

Both null and empty string are viewed as the same, and return null.

Parameters
propertyName:String

The name of the property for which to extract value

properties:Properties

The properties object

Returns:String

The property value; may be null.

getBooleanback to summary
public static boolean getBoolean(String propertyName, Properties properties)

Get a property value as a boolean. Shorthand for calling getBoolean(String, java.util.Properties, boolean) with false as the default value.

Parameters
propertyName:String

The name of the property for which to retrieve value

properties:Properties

The properties object

Returns:boolean

The property value.

getBooleanback to summary
public static boolean getBoolean(String propertyName, Properties properties, boolean defaultValue)

Get a property value as a boolean.

First, the string value is extracted, and then Boolean#valueOf(String) is used to determine the correct boolean value.

Parameters
propertyName:String

The name of the property for which to retrieve value

properties:Properties

The properties object

defaultValue:boolean

The default property value to use.

Returns:boolean

The property value.

See Also
extractPropertyValue(String, java.util.Properties)
getIntback to summary
public static int getInt(String propertyName, Properties properties, int defaultValue)

Get a property value as an int.

First, the string value is extracted, and then Integer#parseInt(String) is used to determine the correct int value for any non-null property values.

Parameters
propertyName:String

The name of the property for which to retrieve value

properties:Properties

The properties object

defaultValue:int

The default property value to use.

Returns:int

The property value.

See Also
extractPropertyValue(String, java.util.Properties)
getIntegerback to summary
public static Integer getInteger(String propertyName, Properties properties)

Get a property value as an Integer.

First, the string value is extracted, and then Integer#valueOf(String) is used to determine the correct boolean value for any non-null property values.

Parameters
propertyName:String

The name of the property for which to retrieve value

properties:Properties

The properties object

Returns:Integer

The property value; may be null.

See Also
extractPropertyValue(String, java.util.Properties)
getStringback to summary
public static String getString(String propertyName, Properties properties, String defaultValue)

Get a property value as a string.

Parameters
propertyName:String

The name of the property for which to retrieve value

properties:Properties

The properties object

defaultValue:String

The default property value to use.

Returns:String

The property value; may be null.

See Also
extractPropertyValue(String, java.util.Properties)
maskOutback to summary
public static Properties maskOut(Properties props, String key)

replace a property by a starred version

Parameters
props:Properties

properties to check

key:String

proeprty to mask

Returns:Properties

cloned and masked properties

resolvePlaceHolderback to summary
public static String resolvePlaceHolder(String property)

Handles interpolation processing for a single property.

Parameters
property:String

The property value to be processed for interpolation.

Returns:String

The (possibly) interpolated property value.

resolvePlaceHoldersback to summary
public static void resolvePlaceHolders(Properties properties)

Handles interpolation processing for all entries in a properties object.

Parameters
properties:Properties

The properties object.

toMapback to summary
public static Map<K, V> toMap(String propertyName, String delim, Properties properties)

Constructs a map from a property value.

The exact behavior here is largely dependant upon what is passed in as the delimiter.

Parameters
propertyName:String

The name of the property for which to retrieve value

delim:String

The string defining tokens used as both entry and key/value delimiters.

properties:Properties

The properties object

Returns:Map<K, V>

The resulting map; never null, though perhaps empty.

See Also
extractPropertyValue(String, java.util.Properties)
toStringArrayback to summary
public static String[] toStringArray(String propertyName, String delim, Properties properties)

Get a property value as a string array.

Parameters
propertyName:String

The name of the property for which to retrieve value

delim:String

The delimiter used to separate individual array elements.

properties:Properties

The properties object

Returns:String[]

The array; never null, though may be empty.

See Also
extractPropertyValue(String, java.util.Properties), toStringArray(String, String)
toStringArrayback to summary
public static String[] toStringArray(String stringForm, String delim)

Convert a string to an array of strings. The assumption is that the individual array elements are delimited in the source stringForm param by the delim param.

Parameters
stringForm:String

The string form of the string array.

delim:String

The delimiter used to separate individual array elements.

Returns:String[]

The array; never null, though may be empty.