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.
<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.
 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

Project Darkstar, Version 0.9.10.12
2013-07-29 21:37:44

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