flex.messaging.config
Class ConfigMap

java.lang.Object
  extended by java.util.AbstractMap
      extended by java.util.HashMap
          extended by java.util.LinkedHashMap
              extended by flex.messaging.config.ConfigMap
All Implemented Interfaces:
Serializable, Cloneable, Map

public class ConfigMap
extends LinkedHashMap

The ConfigMap class is a helper implementation of Map that makes it easier to handle properties that can appear one or more times. If a property is set more than once, it is converted to a List and added as another property rather than replacing the existing property. It also provides utility APIs for getting properties from the Map, cast to a certain type and allows a default to be specified in the event that the property is missing.

See Also:
Serialized Form

Constructor Summary
ConfigMap()
          Constructs an empty ConfigMap with the default initial capacity of 10.
ConfigMap(ConfigMap m)
          Constructs a new ConfigMap and copies the values from the supplied map to this map.
ConfigMap(int initialCapacity)
          Constructs a new ConfigMap with the initial capacity specified.
 
Method Summary
 void addProperties(ConfigMap p)
          Adds all properties from a map to this map.
 void addProperty(String name, ConfigMap value)
          Adds a ConfigMap value to this map for the given property name.
 void addProperty(String name, String value)
          Adds a String value to this map for the given property name.
 void allowProperty(String name)
          Sets a property name as allowed without needing to access the property value.
 List findAllUnusedProperties()
          Returns a list of qualified property names that have not been accessed by one of the get*() methods.
 void findUnusedProperties(String parentPath, boolean recurse, Collection result)
          Gathers a collection of properties that exist in the map but have not been explicitly accessed nor marked as allowed.
 Object get(Object name)
          Gets the value for the given property name.
 String getProperty(String name)
          Gets the property with the specified name as a string if possible.
 boolean getPropertyAsBoolean(String name, boolean defaultValue)
          Gets the property with the specified name as a boolean if possible, or returns the default value if the property is undefined.
 int getPropertyAsInt(String name, int defaultValue)
          Gets the property with the specified name as an int if possible, or returns the default value if the property is undefined.
 List getPropertyAsList(String name, List defaultValue)
          Gets a property (or set of properties) as a List.
 long getPropertyAsLong(String name, long defaultValue)
          Gets the property with the specified name as a long if possible, or returns the default value if the property is undefined.
 ConfigMap getPropertyAsMap(String name, ConfigMap defaultValue)
          Gets the property with the specified name as a ConfigMap if possible, or returns the default value if the property is undefined.
 String getPropertyAsString(String name, String defaultValue)
          Gets the property with the specified name as a String if possible, or returns the default value if the property is undefined.
 Set propertyNames()
          Gets the set of property names contained in this map.
 
Methods inherited from class java.util.LinkedHashMap
clear, containsValue
 
Methods inherited from class java.util.HashMap
clone, containsKey, entrySet, isEmpty, keySet, put, putAll, remove, size, values
 
Methods inherited from class java.util.AbstractMap
equals, hashCode, toString
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Map
containsKey, entrySet, equals, hashCode, isEmpty, keySet, put, putAll, remove, size, values
 

Constructor Detail

ConfigMap

public ConfigMap()
Constructs an empty ConfigMap with the default initial capacity of 10.


ConfigMap

public ConfigMap(int initialCapacity)
Constructs a new ConfigMap with the initial capacity specified.

Parameters:
initialCapacity - the initial capacity.

ConfigMap

public ConfigMap(ConfigMap m)
Constructs a new ConfigMap and copies the values from the supplied map to this map.

Parameters:
m - a ConfigMap whose properties are to be added to this ConfigMap.
Method Detail

addProperties

public void addProperties(ConfigMap p)
Adds all properties from a map to this map.

Parameters:
p - a ConfigMap whose properties are to be added to this ConfigMap.

addProperty

public void addProperty(String name,
                        String value)
Adds a String value to this map for the given property name.

Parameters:
name - the property name
value - the property value

addProperty

public void addProperty(String name,
                        ConfigMap value)
Adds a ConfigMap value to this map for the given property name.

Parameters:
name - the property name
value - the property value

propertyNames

public Set propertyNames()
Gets the set of property names contained in this map.

Returns:
a Set of property name Strings.

allowProperty

public void allowProperty(String name)
Sets a property name as allowed without needing to access the property value. This marks a property as allowed for validation purposes.

Parameters:
name - the property name to allow

get

public Object get(Object name)
Gets the value for the given property name. Also records that this property was accessed.

Specified by:
get in interface Map
Overrides:
get in class LinkedHashMap
Parameters:
name - the property name
Returns:
the value for the property, or null if property does not exist in this map.

getProperty

public String getProperty(String name)
Gets the property with the specified name as a string if possible.

Parameters:
name - The property name.
Returns:
The property name.
Throws:
ConfigurationException - if there are multiple values for the property name.

getPropertyAsMap

public ConfigMap getPropertyAsMap(String name,
                                  ConfigMap defaultValue)
Gets the property with the specified name as a ConfigMap if possible, or returns the default value if the property is undefined.

Throws:
ConfigurationException - if there are multiple values for the property name.

getPropertyAsString

public String getPropertyAsString(String name,
                                  String defaultValue)
Gets the property with the specified name as a String if possible, or returns the default value if the property is undefined.

Throws:
ConfigurationException - if there are multiple values for the property name.

getPropertyAsList

public List getPropertyAsList(String name,
                              List defaultValue)
Gets a property (or set of properties) as a List. If only one property exists it is added as the only entry to a new List.

Parameters:
name - the property name
defaultValue - the value to return if the property is not found
Returns:
the value for the property as a List if it exists in this map, otherwise the defaultValue is returned.

getPropertyAsBoolean

public boolean getPropertyAsBoolean(String name,
                                    boolean defaultValue)
Gets the property with the specified name as a boolean if possible, or returns the default value if the property is undefined.

Throws:
ConfigurationException - if there are multiple values for the property name.

getPropertyAsInt

public int getPropertyAsInt(String name,
                            int defaultValue)
Gets the property with the specified name as an int if possible, or returns the default value if the property is undefined.

Throws:
ConfigurationException - if there are multiple values for the property name.

getPropertyAsLong

public long getPropertyAsLong(String name,
                              long defaultValue)
Gets the property with the specified name as a long if possible, or returns the default value if the property is undefined.

Throws:
ConfigurationException - if there are multiple values for the property name.

findAllUnusedProperties

public List findAllUnusedProperties()
Returns a list of qualified property names that have not been accessed by one of the get*() methods.


findUnusedProperties

public void findUnusedProperties(String parentPath,
                                 boolean recurse,
                                 Collection result)
Gathers a collection of properties that exist in the map but have not been explicitly accessed nor marked as allowed. This list is helpful in validating a set of properties as one can detect those that are unknown or unexpected.

Parameters:
parentPath - Used to track the depth of property in a potential hierarchy of ConfigMaps.
recurse - Whether sub maps should be recursively searched.
result - the collection of unused properties in this map.


Copyright © 2008 Adobe Systems Inc. All Rights Reserved.

 

Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/blazeds/1/javadoc/flex/messaging/config/ConfigMap.html