com.metamatrix.console.ui.util.property
Class PropertyProvider

java.lang.Object
  extended by com.metamatrix.console.ui.util.property.PropertyProvider

public class PropertyProvider
extends java.lang.Object

The PropertyProvider class provides property values on request. It can be configured to look at one or more property files in a predetermined order looking for properties. The first occurrence of the property is returned. This class uses the UIStandards class to read the property files and to obtain the property values.

Version:
1.0
Author:
Dan Florian

Field Summary
static java.lang.String COMMON_PROP
          The common properties file used by the Console.
static java.lang.String DEFAULT_ERROR_PREFIX
          The default error prefix is "**".
protected  javax.swing.AbstractButton DO_NOT_USE_1
          Declared just to get rid of javadoc warning.
protected  ObjectPropertyManager DO_NOT_USE_2
          Declared just to get rid of javadoc warning.
 
Constructor Summary
PropertyProvider(java.util.List thePropertiesCollection)
          Constructs a PropertyProvider that has one or more property files associated with it.
PropertyProvider(java.lang.String thePropertiesFile)
          Constructs a PropertyProvider that has only one properties file associated with it.
 
Method Summary
 boolean getBoolean(java.lang.String theKey)
          Gets the value of the given property as a boolean.
static PropertyProvider getDefault()
          A provider configured only to use COMMON_PROP.
 java.lang.String getErrorPrefix()
          Gets the error prefix.
 javax.swing.Icon getIcon(java.lang.String theKey)
          Gets the icon associated with the given property.
 int getInt(java.lang.String theKey, int theDefault)
          Gets the value of the given property as an int.
static javax.swing.Icon getMissingIcon()
          Gets the Icon used when the requested one cannot be found.
 java.lang.Object getObject(java.lang.String theKey)
          Gets the value of the given property as an Object.
 java.lang.String getPropertiesFile(java.lang.String theKey)
          Gets the first properties file name where the property was found.
 java.lang.String getString(java.lang.String theKey)
          Gets the requested property value.
 java.lang.String getString(java.lang.String theKey, boolean theReturnNullFlag)
          Gets the requested property value.
 java.lang.String getString(java.lang.String theKey, java.lang.Object[] theArgs)
          Gets the requested property value and inserts the argument element(s) into the returned message.
 void setErrorPrefix(java.lang.String theErrorPrefix)
          Sets the error prefix.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_ERROR_PREFIX

public static final java.lang.String DEFAULT_ERROR_PREFIX
The default error prefix is "**".

See Also:
Constant Field Values

COMMON_PROP

public static final java.lang.String COMMON_PROP
The common properties file used by the Console.

See Also:
Constant Field Values

DO_NOT_USE_1

protected javax.swing.AbstractButton DO_NOT_USE_1
Declared just to get rid of javadoc warning.


DO_NOT_USE_2

protected ObjectPropertyManager DO_NOT_USE_2
Declared just to get rid of javadoc warning.

Constructor Detail

PropertyProvider

public PropertyProvider(java.lang.String thePropertiesFile)
Constructs a PropertyProvider that has only one properties file associated with it.

Parameters:
thePropertiesFile - the name of the properties file
Throws:
java.lang.IllegalArgumentException - if argument is null or empty

PropertyProvider

public PropertyProvider(java.util.List thePropertiesCollection)
Constructs a PropertyProvider that has one or more property files associated with it.

Parameters:
thePropertiesCollection - a collection of property files
Throws:
java.lang.IllegalArgumentException - if argument is null or empty, or if any of the arguments elements are null, not a String, or an empty String
Method Detail

getBoolean

public boolean getBoolean(java.lang.String theKey)
Gets the value of the given property as a boolean. Here is an example properties file entry:
filename.required="true"

Parameters:
theKey - the property whose value is being requested
Returns:
the property value as a boolean or false if property not found

getDefault

public static PropertyProvider getDefault()
A provider configured only to use COMMON_PROP.

Returns:
the default property provider

getErrorPrefix

public java.lang.String getErrorPrefix()
Gets the error prefix. The error prefix together with the property name is returned as the property value when the property is not found.

Returns:
the error prefix

getIcon

public javax.swing.Icon getIcon(java.lang.String theKey)
Gets the icon associated with the given property. If the icon cannot be found, a generic one representing a missing icon is returned. Here is an example of a properties file entry:
icon.back="com/metamatrix/console/images/back_medium.gif"

Parameters:
theKey - the property whose value is being requested
Returns:
the property value as an Icon or a generic icon if not found
See Also:
getMissingIcon()

getInt

public int getInt(java.lang.String theKey,
                  int theDefault)
Gets the value of the given property as an int. Here is an example properties file entry:
portnum.default="15001"

Parameters:
theKey - the property whose value is being requested
theDefault - the default value
Returns:
the property value as an int or the default value if the property is not found

getMissingIcon

public static javax.swing.Icon getMissingIcon()
Gets the Icon used when the requested one cannot be found.

Returns:
the Icon used when the requested one cannot be found

getObject

public java.lang.Object getObject(java.lang.String theKey)
Gets the value of the given property as an Object. Here is an example properties file entry:
importexport.extensions=new String[] {"xml"}

Parameters:
theKey - the property whose value is being requested
Returns:
the property value as an Object or null if not found

getPropertiesFile

public java.lang.String getPropertiesFile(java.lang.String theKey)
Gets the first properties file name where the property was found.

Parameters:
theKey - the property whose value is being requested
Returns:
the properties file name where the property was found

getString

public java.lang.String getString(java.lang.String theKey)
Gets the requested property value. This version of getString never returns null. If the property cannot be found, the property name is prepended with the error prefix and returned.

Parameters:
theKey - the property whose value is being requested
Returns:
the property value or the property value with the error prefix prepended to it

getString

public java.lang.String getString(java.lang.String theKey,
                                  boolean theReturnNullFlag)
Gets the requested property value. If the theReturnNullFlag is true a null value is returned if the property cannot be found. If set to false and the property cannot be found, the property name is prepended with the error prefix and returned.

Parameters:
theKey - the property whose value is being requested
theReturnNullFlag - indicates if null should be returned if the property is not found
Returns:
the property value, the property value with the error prefix prepended to it, or null

getString

public java.lang.String getString(java.lang.String theKey,
                                  java.lang.Object[] theArgs)
Gets the requested property value and inserts the argument element(s) into the returned message. Here is an example properties file entry:
confirmdelete.title="Delete Host {0}"

Parameters:
theKey - the property whose value is being requested
theArgs - the arguments being inserted into the property value
Returns:
the property value with the arguments inserted in the appropriate place or null if not found

setErrorPrefix

public void setErrorPrefix(java.lang.String theErrorPrefix)
Sets the error prefix. When the property cannot be found, the error prefix is prepended to the property name and returned as the property value. If the parameter is null or empty, the default prefix is used.

Parameters:
theErrorPrefix - the new error prefix
See Also:
DEFAULT_ERROR_PREFIX


Copyright © 2009. All Rights Reserved.