com.sun.sgs.impl.sharedutil
Class PropertiesWrapper

java.lang.Object
  extended by com.sun.sgs.impl.sharedutil.PropertiesWrapper

public class PropertiesWrapper
extends Object

Wrapper around a Properties that provides convenience methods for accessing primitives.


Constructor Summary
PropertiesWrapper(Properties properties)
          Creates an instance that delegates to the given Properties.
 
Method Summary
 boolean getBooleanProperty(String name, boolean defaultValue)
          Returns the value of a boolean property.
<T> T
getClassInstanceProperty(String name, Class<T> type, Class<?>[] paramTypes, Object... args)
          Returns an instance of the class whose fully qualified class name is specified by a property, and that has a constructor with the specified parameters.
<T> T
getClassInstanceProperty(String name, String defaultClass, Class<T> type, Class<?>[] paramTypes, Object... args)
          Returns an instance of the class whose fully qualified class name is specified by a property, and that has a constructor with the specified parameters.
 List<Class<?>> getClassListProperty(String name)
          Returns a List of Class typed objects.
<T extends Enum<T>>
List<T>
getEnumListProperty(String name, Class<T> enumType, T defaultElement)
          Returns a list of Enums of the type specified by enumType.
<T extends Enum<T>>
T
getEnumProperty(String name, Class<T> enumType, T defaultValue)
          Returns the value of an Enum property.
 int getIntProperty(String name, int defaultValue)
          Returns the value of an int property.
 int getIntProperty(String name, int defaultValue, int min, int max)
          Returns the value of an int property within a bound range of values.
<T> List<T>
getListProperty(String name, Class<T> type, T defaultElement)
          Returns a list of objects of the type specified by type.
 long getLongProperty(String name, long defaultValue)
          Returns the value of a long property.
 long getLongProperty(String name, long defaultValue, long min, long max)
          Returns the value of a long property within a bound range of values.
 Properties getProperties()
          Returns the associated Properties.
 String getProperty(String name)
          Returns the value of a property as a String, or null if the property is not found.
 String getProperty(String name, String defaultValue)
          Returns the value of a property as a String, or the default value if the property is not found.
 int getRequiredIntProperty(String name)
          Returns the value of a required int property.
 int getRequiredIntProperty(String name, int min, int max)
          Returns the value of a required int property within a bound range of values.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PropertiesWrapper

public PropertiesWrapper(Properties properties)
Creates an instance that delegates to the given Properties.

Parameters:
properties - the Properties to wrap
Method Detail

getProperties

public Properties getProperties()
Returns the associated Properties.

Returns:
the associated Properties

getProperty

public String getProperty(String name)
Returns the value of a property as a String, or null if the property is not found.

Parameters:
name - the property name
Returns:
the value or null

getProperty

public String getProperty(String name,
                          String defaultValue)
Returns the value of a property as a String, or the default value if the property is not found.

Parameters:
name - the property name
defaultValue - the default value
Returns:
the value

getBooleanProperty

public boolean getBooleanProperty(String name,
                                  boolean defaultValue)
Returns the value of a boolean property.

Parameters:
name - the property name
defaultValue - the default value
Returns:
the value

getIntProperty

public int getIntProperty(String name,
                          int defaultValue)
Returns the value of an int property.

Parameters:
name - the property name
defaultValue - the default value
Returns:
the value
Throws:
NumberFormatException - if the value does not contain a parsable int

getRequiredIntProperty

public int getRequiredIntProperty(String name)
Returns the value of a required int property.

Parameters:
name - the property name
Returns:
the value
Throws:
IllegalArgumentException - if the value is not set
NumberFormatException - if the value does not contain a parsable int

getIntProperty

public int getIntProperty(String name,
                          int defaultValue,
                          int min,
                          int max)
Returns the value of an int property within a bound range of values.

Parameters:
name - the property name
defaultValue - the default value
min - the minimum value to allow
max - the maximum value to allow
Returns:
the value
Throws:
IllegalArgumentException - if the value or defaultValue is less than min or greater than max, or if min is greater than max
NumberFormatException - if the value does not contain a parsable int

getRequiredIntProperty

public int getRequiredIntProperty(String name,
                                  int min,
                                  int max)
Returns the value of a required int property within a bound range of values.

Parameters:
name - the property name
min - the minimum value to allow
max - the maximum value to allow
Returns:
the value
Throws:
IllegalArgumentException - if the value or defaultValue is less than min or greater than max, or if min is greater than max, or if the value is not set
NumberFormatException - if the value does not contain a parsable int

getLongProperty

public long getLongProperty(String name,
                            long defaultValue)
Returns the value of a long property.

Parameters:
name - the property name
defaultValue - the default value
Returns:
the value
Throws:
NumberFormatException - if the value does not contain a parsable long

getLongProperty

public long getLongProperty(String name,
                            long defaultValue,
                            long min,
                            long max)
Returns the value of a long property within a bound range of values.

Parameters:
name - the property name
defaultValue - the default value
min - the minimum value to allow
max - the maximum value to allow
Returns:
the value
Throws:
IllegalArgumentException - if the value or defaultValue is less than min or greater than max, or if min is greater than max
NumberFormatException - if the value does not contain a parsable long

getClassInstanceProperty

public <T> T getClassInstanceProperty(String name,
                                      Class<T> type,
                                      Class<?>[] paramTypes,
                                      Object... args)
Returns an instance of the class whose fully qualified class name is specified by a property, and that has a constructor with the specified parameters. The class should extend or implement the specified type, and not be abstract.

Type Parameters:
T - the type of the return value
Parameters:
name - the property name
type - the class which the return value should be an instance of
paramTypes - the constructor parameter types
args - the arguments to pass to the constructor
Returns:
the new instance or null if the property is not found
Throws:
IllegalArgumentException - if the property is found and a problem occurs creating the instance, or if the constructor throws a checked exception

getClassInstanceProperty

public <T> T getClassInstanceProperty(String name,
                                      String defaultClass,
                                      Class<T> type,
                                      Class<?>[] paramTypes,
                                      Object... args)
Returns an instance of the class whose fully qualified class name is specified by a property, and that has a constructor with the specified parameters. The class should extend or implement the specified type, and not be abstract.

Type Parameters:
T - the type of the return value
Parameters:
name - the property name
defaultClass - the fully qualified class name to use if the name property is not found
type - the class which the return value should be an instance of
paramTypes - the constructor parameter types
args - the arguments to pass to the constructor
Returns:
the new instance or null if the property is not found and defaultClassName is null
Throws:
IllegalArgumentException - if a problem occurs creating the instance, or if the constructor throws a checked exception

getEnumProperty

public <T extends Enum<T>> T getEnumProperty(String name,
                                             Class<T> enumType,
                                             T defaultValue)
Returns the value of an Enum property.

Type Parameters:
T - the enumeration type
Parameters:
name - the property name
enumType - the enumeration type
defaultValue - the default value
Returns:
the value
Throws:
IllegalArgumentException - if the value does not name a constant of the enumeration type

getListProperty

public <T> List<T> getListProperty(String name,
                                   Class<T> type,
                                   T defaultElement)
Returns a list of objects of the type specified by type. The objects are created from the property with the given name from the backing set of properties. The property is assumed to be a colon separated list of Strings, and each element in the list is instantiated by calling the given type's Constructor with a single String parameter. If any of the Strings in the colon separated list is an empty string, the value of defaultElement will be used for that item in the returned List. If the property with the given name is not found, an empty list will be returned.

Type Parameters:
T - the type of the objects in the returned List
Parameters:
name - the property name
type - the class which each object in the returned List should be an instance of
defaultElement - the default value to use if an empty String is one of the items in the list
Returns:
a list of objects of the given type represented by the property with the given name, or an empty list if the property is not found
Throws:
IllegalArgumentException - if a problem occurs creating an instance of the given class type, or the class type does not have a constructor that takes a single String parameter

getEnumListProperty

public <T extends Enum<T>> List<T> getEnumListProperty(String name,
                                                       Class<T> enumType,
                                                       T defaultElement)
Returns a list of Enums of the type specified by enumType. The objects are created from the property with the given name from the backing set of properties. The property is assumed to be a colon separated list of Strings, and each element in the list is instantiated by calling the Enum.valueOf method on each respective String in the list. If any of the Strings in the colon separated list is an empty string, the value of defaultElement will be used for that item in the returned List. If the property with the given name is not found, an empty list will be returned.

Type Parameters:
T - the Enum type of the objects in the returned List
Parameters:
name - the property name
enumType - the Enum class which each object in the returned List should be an instance of
defaultElement - the default value to use if an empty String is one of the items in the list
Returns:
a list of Enum objects of the given type represented by the property with the given name
Throws:
IllegalArgumentException - if any of the items in the list is not a valid value for the given Enum type

getClassListProperty

public List<Class<?>> getClassListProperty(String name)
Returns a List of Class typed objects. The objects in the list are created from the property with the given name from the backing set of properties. The property is assumed to be a colon separated list of Strings, where each String is a fully qualified class name of a class. Any empty String appearing in the list will be added to the returned list as a null. If the property with the given name is not found, an empty list will be returned.

Parameters:
name - the name of the property
Returns:
a list of Class objects represented by the property with the given name
Throws:
IllegalArgumentException - if a Class cannot be found for any of the items in the list

Project Darkstar, Version 0.9.11.5
2013-07-29 22:08:40

Copyright © 2007-2013 Sun Microsystems, Inc. All rights reserved