PropertyMap

public class PropertyMap extends PersistentComponent implements PropertySheet

PropertyMap is an implementation of a PropertySheet. It represents a property sheet with a map structure and is actually backed by a Properties object.

Author:Hugo Y. K. Lam

See also: java.util.Properties

Constructors

PropertyMap

public PropertyMap()

Creates a new instance of PropertyMap.

PropertyMap

public PropertyMap(Properties p)

Creates a new instance of PropertyMap.

Parameters:
  • p – the Properties object which backs this map.

PropertyMap

public PropertyMap(URL url)

Creates a new instance of PropertyMap.

Parameters:
  • url – the url of the properties source.
Throws:
  • ComponentException – if the properties could not be loaded from the specified url.

Methods

append

public boolean append(PropertySheet p)

Appends a property sheet to this property map. The specified property sheet can only be appended if it is of the PropertyMap type.

Parameters:
  • p – the property sheet to be appended.
Returns:

true if the operation is successful. false otherwise.

See also: hk.hku.cecid.piazza.commons.util.PropertySheet.append(hk.hku.cecid.piazza.commons.util.PropertySheet)

containsKey

public boolean containsKey(String key)

Checks if the specified key exists in this property map.

Parameters:
  • key – the property key.
Returns:

true if the specified key exists in this property map.

See also: hk.hku.cecid.piazza.commons.util.PropertySheet.containsKey(java.lang.String)

createProperties

public Properties createProperties(String keyPrefix)

Creates a Properties object which stores the properties retrieved by the specified key prefix.

Parameters:
  • keyPrefix – the property key prefix.
Returns:

a Properties object which stores the retrieved properties.

See also: hk.hku.cecid.piazza.commons.util.PropertySheet.createProperties(java.lang.String)

getProperties

public String[] getProperties(String keyPrefix)

Gets a list of properties with the specified key.

Parameters:
  • keyPrefix – the property key prefix.
Returns:

the properties with the specified key.

See also: hk.hku.cecid.piazza.commons.util.PropertySheet.getProperties(java.lang.String)

getProperties

public String[][] getProperties(String keyPrefix, String keySuffixes)

Gets a two-dimensional list of properties with the specified key prefix and key suffixes. The key prefix, along with the suffixes, will define the first dimension of the list while the key suffixes will define the second dimension. E.g.

# Properties content
application.listener1.id=MyListener
application.listener1.name=My Listener
application.listener2.id=MyListener2
application.listener2.name=My Listener 2

Key Prefix: application.listener
Key Suffixes: id,name

Note that the resulted array will be sorted alphabetically according to the original
keys but not the specified key suffixes order or the property values.

Returned array:
{{"MyListener","My Listener"},{"MyListener2","My Listener 2"}}
Parameters:
  • keyPrefix – the property key prefix.
  • keySuffixes – the property key suffixes delimited by either ‘,’, ‘;’ or ‘|’.
Returns:

a two-dimensional list of properties with the specified keys.

See also: hk.hku.cecid.piazza.commons.util.PropertySheet.getProperties(java.lang.String, java.lang.String)

getProperty

public String getProperty(String key)

Gets a property with the specified key.

Parameters:
  • key – the property key.
Returns:

the property with the specified key.

See also: hk.hku.cecid.piazza.commons.util.PropertySheet.getProperty(java.lang.String)

getProperty

public String getProperty(String key, String def)

Gets a property with the specified key.

Parameters:
  • key – the property key.
  • def – the default value.
Returns:

the property with the specified key.

See also: hk.hku.cecid.piazza.commons.util.PropertySheet.getProperty(java.lang.String, java.lang.String)

getPropertyNames

protected String[] getPropertyNames(String keyPrefix)

Gets all property names with the specified key prefix.

Parameters:
  • keyPrefix – the property key prefix.
Returns:

the property names with the specified key prefix.

loading

protected void loading(URL url)

Loads the properties from the specified url location.

Parameters:
  • url – the url of the properties source.
Throws:
  • Exception – if the operation is unsuccessful.

See also: hk.hku.cecid.piazza.commons.module.PersistentComponent.loading(java.net.URL)

propertyNames

public Enumeration propertyNames()

Gets all the existing property names.

Returns:all the existing property names.

See also: hk.hku.cecid.piazza.commons.util.PropertySheet.propertyNames()

removeProperty

public boolean removeProperty(String key)

Removes a property with the specified key.

Parameters:
  • key – the property key.
Returns:

true if the operation is successful. false otherwise.

See also: hk.hku.cecid.piazza.commons.util.PropertySheet.removeProperty(java.lang.String)

setProperty

public boolean setProperty(String key, String value)

Sets a property value with the specified key.

Parameters:
  • key – the property key.
  • value – the property value.
Returns:

true if the operation is successful. false otherwise.

See also: hk.hku.cecid.piazza.commons.util.PropertySheet.setProperty(java.lang.String, java.lang.String)

storing

protected void storing(URL url)

Stores the properties to the specified url location.

Parameters:
  • url – the url of the properties source.
Throws:
  • Exception – if the operation is unsuccessful.

See also: hk.hku.cecid.piazza.commons.module.PersistentComponent.storing(java.net.URL)