|
uPortal 2.4.1 API Documentation |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.jasig.portal.properties.PropertiesManager
Provides access to properties.
It is important to understand that usage of this class is different from what you might be used to in java.util.Properties. Specifically, when you get a Properties property, if that property is not set, the return value is NULL. However, when you call the basic getters here, if the property is not set, a RuntimeException is thrown. These methods will never return null (except if you pass in null as the default return value for the methods that take a default).
There are methods to get properties as various primitive types, int, double, float, etc. When you invoke one of these methods on a property that is found but cannot be parsed as your desired type, a RuntimeException is thrown.
There are corresponding methods which take as a second parameter a default value. These methods, instead of throwing a RuntimeException when the property cannot be found, return the default value. You can use the default value "null" to invoke getProperty() with semantics more like the java.util.Properties object. These augmented accessors which take defaults will be, I hope, especially useful in static initializers. Providing a default in your static initializer will keep your class from blowing up at initialization when your property cannot be found. This seems especially advantageous when there is a plausible default value.
This class has a comprehensive JUnit testcase. Please keep the testcase up to date with any changes you make to this class.
Field Summary | |
static java.lang.String |
PORTAL_PROPERTIES_FILE_SYSTEM_VARIABLE
|
Constructor Summary | |
PropertiesManager()
|
Method Summary | |
static java.util.Set |
getMissingProperties()
Get a Set of the names of properties that have been requested but were not set. |
static java.lang.String |
getProperty(java.lang.String name)
Returns the value of a property for a given name. |
static java.lang.String |
getProperty(java.lang.String name,
java.lang.String defaultValue)
Get the value of the property with the given name. |
static boolean |
getPropertyAsBoolean(java.lang.String name)
Returns the value of a property for a given name. |
static boolean |
getPropertyAsBoolean(java.lang.String name,
boolean defaultValue)
Get a property as a boolean, specifying a default value. |
static byte |
getPropertyAsByte(java.lang.String name)
Returns the value of a property for a given name as a byte |
static byte |
getPropertyAsByte(java.lang.String name,
byte defaultValue)
Get the value of the given property as a byte, specifying a fallback default value. |
static double |
getPropertyAsDouble(java.lang.String name)
Returns the value of a property for a given name as a long |
static double |
getPropertyAsDouble(java.lang.String name,
double defaultValue)
Get the value of the given property as a double. |
static float |
getPropertyAsFloat(java.lang.String name)
Returns the value of a property for a given name as a float |
static float |
getPropertyAsFloat(java.lang.String name,
float defaultValue)
Get the value of the given property as a float. |
static int |
getPropertyAsInt(java.lang.String name)
Returns the value of a property for a given name as an int |
static int |
getPropertyAsInt(java.lang.String name,
int defaultValue)
Get the value of a given property as an int. |
static long |
getPropertyAsLong(java.lang.String name)
Returns the value of a property for a given name as a long |
static long |
getPropertyAsLong(java.lang.String name,
long defaultValue)
Get the value of the given property as a long. |
static short |
getPropertyAsShort(java.lang.String name)
Returns the value of a property for a given name as a short |
static short |
getPropertyAsShort(java.lang.String name,
short defaultValue)
Returns the value of a property for a given name as a short. |
static java.lang.String |
getPropertyUntrimmed(java.lang.String name)
Returns the value of a property for a given name including whitespace trailing the property value, but not including whitespace leading the property value. |
static java.lang.String |
getPropertyUntrimmed(java.lang.String name,
java.lang.String defaultValue)
Get the value of a property for the given name including any whitespace that may be at the beginning or end of the property value. |
static void |
setProperties(java.util.Properties props)
Setter method to set the underlying Properties. |
Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final java.lang.String PORTAL_PROPERTIES_FILE_SYSTEM_VARIABLE
Constructor Detail |
public PropertiesManager()
Method Detail |
public static void setProperties(java.util.Properties props)
props
- - Properties to be injected.public static java.lang.String getProperty(java.lang.String name) throws MissingPropertyException
name
- the name of the requested property
MissingPropertyException
- - if the requested property cannot be foundpublic static java.lang.String getPropertyUntrimmed(java.lang.String name) throws MissingPropertyException
name
- the name of the requested property
MissingPropertyException
- - (undeclared) if the requested property is not foundpublic static boolean getPropertyAsBoolean(java.lang.String name) throws MissingPropertyException
true
is
returned if the property is set to "true", "yes", "y", or "on"
(regardless of case),
and false
is returned in all other cases.
name
- the name of the requested property
true
if property is set to "true", "yes", "y", or "on" regardless of case, otherwise false
MissingPropertyException
- - when no property of the given name is declared.public static byte getPropertyAsByte(java.lang.String name) throws MissingPropertyException, BadPropertyException
byte
name
- the name of the requested property
byte
MissingPropertyException
- - if the property is not set
BadPropertyException
- - if the property cannot be parsed as a bytepublic static short getPropertyAsShort(java.lang.String name) throws MissingPropertyException, BadPropertyException
short
name
- the name of the requested property
short
MissingPropertyException
- - if the property is not set
BadPropertyException
- - if the property cannot be parsed as a short or is not set.public static int getPropertyAsInt(java.lang.String name) throws MissingPropertyException, BadPropertyException
int
name
- the name of the requested property
int
MissingPropertyException
- - if the property is not set
BadPropertyException
- - if the property cannot be parsed as an intpublic static long getPropertyAsLong(java.lang.String name) throws MissingPropertyException, BadPropertyException
long
name
- the name of the requested property
long
MissingPropertyException
- - if the property is not set
BadPropertyException
- - if the property cannot be parsed as a longpublic static float getPropertyAsFloat(java.lang.String name) throws MissingPropertyException, BadPropertyException
float
name
- the name of the requested property
float
MissingPropertyException
- - if the property is not set
BadPropertyException
- - if the property cannot be parsed as a floatpublic static double getPropertyAsDouble(java.lang.String name) throws MissingPropertyException, BadPropertyException
long
name
- the name of the requested property
double
MissingPropertyException
- - if the property has not been set
BadPropertyException
- - if the property cannot be parsed as a double or is not set.public static java.lang.String getProperty(java.lang.String name, java.lang.String defaultValue)
name
- - the name of the property to be retrieved.defaultValue
- - a fallback default value which will be returned if the property cannot be found.
public static java.lang.String getPropertyUntrimmed(java.lang.String name, java.lang.String defaultValue)
name
- - the name of the requested propertydefaultValue
- - a default value to fall back on if the property cannot be found
public static boolean getPropertyAsBoolean(java.lang.String name, boolean defaultValue)
name
- - the name of the property to be accesseddefaultValue
- - default value that will be returned in the event of any error
public static byte getPropertyAsByte(java.lang.String name, byte defaultValue)
name
- - the name of the property to be accesseddefaultValue
- - the default value that will be returned in the event of any error
public static short getPropertyAsShort(java.lang.String name, short defaultValue)
name
- - the name of the requested propertydefaultValue
- - a default value that will be returned in the event of any error
public static int getPropertyAsInt(java.lang.String name, int defaultValue)
name
- - the name of the requested propertydefaultValue
- - a fallback default value for the property
public static long getPropertyAsLong(java.lang.String name, long defaultValue)
name
- - the name of the requested propertydefaultValue
- - a fallback default value that will be returned if there is any problem
public static float getPropertyAsFloat(java.lang.String name, float defaultValue)
name
- - the name of the requested propertydefaultValue
- - a fallback default value that will be returned if there is any problem
public static double getPropertyAsDouble(java.lang.String name, double defaultValue)
name
- - the name of the requested propertydefaultValue
- - a fallback default value that will be returned if there is any problem
public static java.util.Set getMissingProperties()
|
uPortal 2.4.1 API Documentation |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |