Arch4J 1.1

org.arch4j.property
Class XMLPropertyManager

java.lang.Object
  |
  +--org.arch4j.property.XMLPropertyManager
All Implemented Interfaces:
PropertyConstants, PropertyManager

public class XMLPropertyManager
extends Object
implements PropertyManager, PropertyConstants

This class manages the reading, writing, and parsing of an XML-based property file. It also provides backward compatibility to the old-style property scheme by supporting the old API.

When no property domains are used, the simplest format for the XML-based property file looks like this:

 <?xml version="1.0" encoding="UTF-8" ?>
 <xml-properties>
   <property key="someKey" value="Some Value" type="string" />
   <property key="some.boolean.key" value="true" type="boolean" />
   <property key="long.key.multiple" value="12023453454" type="long" />
   <property key="long.key.multiple" value="-987654321012" type="long" />
 </xml-properties>
 

In this case, a default domain is used. This file is functionally equivalent to:

 <?xml version="1.0" encoding="UTF-8" ?>
 <xml-properties>
   <domain name="$DEFAULT$">
     <property key="someKey" value="Some Value" type="string" />
     <property key="some.boolean.key" value="true" type="boolean" />
     <property key="long.key.multiple" value="12023453454" type="long" />
     <property key="long.key.multiple" value="-987654321012" type="long" />
   </domain>
 </xml-properties>
 

Properties can be defined with the following list of data types:

 boolean
 char
 double
 float
 int
 long
 string
 

In order to remain backward compatible, split your properties up into domains, specifically, the ones that other components within Arch4J use. For example, here are a few of the known domains:

 <?xml version="1.0" encoding="UTF-8" ?>
 <xml-properties>
   <domain name="dataaccess">
     <property key="defaultConnection" value="myMainDatabase" type="string" />
     <property key="myMainDatabase.driver" value="com.mysql.jdbc.Driver" type="string" />
     <property key="myMainDatabase.url" value="jdbc:mysql:///testdata" type="string" />
     <property key="myMainDatabase.username" value="root" type="string" />
     <property key="myMainDatabase.password" value="" type="string" />
     <property key="myMainDatabase.maxConnections" value="10" type="string" />
     <property key="myMainDatabase.useArch4JPool" value="false" type="string" />
   </domain>
   <domain name="logging">
     <property key="framework.class" value="org.arch4j.logging.log4j.Log4JLoggingFramework" type="string" />
     <property key="framework.log4j" value="log4j.properties" type="string" />
   </domain>
 </xml-properties>
 

One drawback to maintaining backward compatibility is that properties in the older domains must be defined with the type of string, since that is all that is available via the Java Properties API.

While it may not be well-formed XML, the parser will allow properties to be both inside and outside the domain tag. Those properties defined outside of the domain tag will be considered to be in the default domain. If a new property is created by using one of the getXXX() methods in this class that takes a default value, then the property data will be written back out to disk. Default properties will be put into the canonical default domain tag.

For new properties that are part of an application and not part of an existing Arch4J domain, application developers can either define their own set of domains or use the default domain. The new format allows developers to create arrays of values for a single property key. When using a Java properties file, the keys have to be unique, as in

 primary.colors.1=red
 primary.colors.2=yellow
 primary.colors.3=blue
 
and then some contrived method needs to be developed to group by the .1, .2, .3 numbers.

The same property can be defined in XML as

 <property key="primary.colors" value="red" type="string" />
 <property key="primary.colors" value="yellow" type="string" />
 <property key="primary.colors" value="blue" type="string" />
 
and retrieved via the method getStringArray("primary.colors").

Version:
$Revision: 1.6 $
Author:
Ross E. Greinke

Field Summary
 
Fields inherited from interface org.arch4j.property.PropertyConstants
ADD_STRING, BOOLEAN_CHAR, BOOLEAN_NAME, CHAR_CHAR, CHAR_NAME, DEFAULT_DOMAIN_NAME, DOMAIN_CHAR, DOMAIN_TAG_NAME, DOUBLE_CHAR, DOUBLE_NAME, EMPTY_STRING, FALSE_STRING, FLOAT_CHAR, FLOAT_NAME, INT_CHAR, INT_NAME, KEY_CHAR, KEY_TAG_NAME, LONG_CHAR, LONG_NAME, NAME_CHAR, NAME_TAG_NAME, PROPERTY_CHAR, PROPERTY_TAG_NAME, STRING_CHAR, STRING_NAME, TOP_LEVEL_CHAR, TOP_LEVEL_TAG_NAME, TRUE_STRING, TYPE_CHAR, TYPE_TAG_NAME, VALUE_CHAR, VALUE_TAG_NAME, XML_DECLARATION
 
Constructor Summary
XMLPropertyManager(File propertyFile)
          Constructs a XMLPropertyManager, which manages the given property file.
 
Method Summary
 boolean getBoolean(String propertyName)
          Returns the property value for the given property key as a boolean.
 boolean getBoolean(String propertyName, boolean defaultValue)
          Returns the property value for the given property key as a boolean.
 boolean getBoolean(String domainName, String propertyName)
          Returns the property value for the given property key as a boolean within the given domain.
 boolean getBoolean(String domainName, String propertyName, boolean defaultValue)
          Returns the property value for the given property key as a boolean within the given domain.
 boolean[] getBooleanArray(String propertyName)
          Returns an array of boolean property values for the given property key.
 boolean[] getBooleanArray(String propertyName, boolean defaultValue)
          Returns an array of boolean property values for the given property key.
 boolean[] getBooleanArray(String domainName, String propertyName)
          Returns an array of boolean property values for the given property key within the given domain.
 boolean[] getBooleanArray(String domainName, String propertyName, boolean defaultValue)
          Returns an array of boolean property values for the given property key within the given domain.
 char getChar(String propertyName)
          Returns the property value for the given property key as a char.
 char getChar(String propertyName, char defaultValue)
          Returns the property value for the given property key as a char.
 char getChar(String domainName, String propertyName)
          Returns the property value for the given property key as a char within the given domain.
 char getChar(String domainName, String propertyName, char defaultValue)
          Returns the property value for the given property key as a char within the given domain.
 char[] getCharArray(String propertyName)
          Returns an array of char property values for the given property key.
 char[] getCharArray(String propertyName, char defaultValue)
          Returns an array of char property values for the given property key.
 char[] getCharArray(String domainName, String propertyName)
          Returns an array of char property values for the given property key within the given domain.
 char[] getCharArray(String domainName, String propertyName, char defaultValue)
          Returns an array of char property values for the given property key within the given domain.
static String getDefaultDomainName()
          Returns the string used as the default, global domain name.
 double getDouble(String propertyName)
          Returns the property value for the given property key as a double.
 double getDouble(String propertyName, double defaultValue)
          Returns the property value for the given property key as a double.
 double getDouble(String domainName, String propertyName)
          Returns the property value for the given property key as a double within the given domain.
 double getDouble(String domainName, String propertyName, double defaultValue)
          Returns the property value for the given property key as a double within the given domain.
 double[] getDoubleArray(String propertyName)
          Returns an array of double property values for the given property key.
 double[] getDoubleArray(String propertyName, double defaultValue)
          Returns an array of double property values for the given property key.
 double[] getDoubleArray(String domainName, String propertyName)
          Returns an array of double property values for the given property key within the given domain.
 double[] getDoubleArray(String domainName, String propertyName, double defaultValue)
          Returns an array of double property values for the given property key within the given domain.
 float getFloat(String propertyName)
          Returns the property value for the given property key as a float.
 float getFloat(String propertyName, float defaultValue)
          Returns the property value for the given property key as a float.
 float getFloat(String domainName, String propertyName)
          Returns the property value for the given property key as a float within the given domain.
 float getFloat(String domainName, String propertyName, float defaultValue)
          Returns the property value for the given property key as a float within the given domain.
 float[] getFloatArray(String propertyName)
          Returns an array of float property values for the given property key.
 float[] getFloatArray(String propertyName, float defaultValue)
          Returns an array of float property values for the given property key.
 float[] getFloatArray(String domainName, String propertyName)
          Returns an array of float property values for the given property key within the given domain.
 float[] getFloatArray(String domainName, String propertyName, float defaultValue)
          Returns an array of float property values for the given property key within the given domain.
 int getInt(String propertyName)
          Returns the property value for the given property key as an int.
 int getInt(String propertyName, int defaultValue)
          Returns the property value for the given property key as an int.
 int getInt(String domainName, String propertyName)
          Returns the property value for the given property key as an int within the given domain.
 int getInt(String domainName, String propertyName, int defaultValue)
          Returns the property value for the given property key as an int within the given domain.
 int[] getIntArray(String propertyName)
          Returns an array of int property values for the given property key.
 int[] getIntArray(String propertyName, int defaultValue)
          Returns an array of int property values for the given property key.
 int[] getIntArray(String domainName, String propertyName)
          Returns an array of int property values for the given property key within the given domain.
 int[] getIntArray(String domainName, String propertyName, int defaultValue)
          Returns an array of int property values for the given property key within the given domain.
 long getLong(String propertyName)
          Returns the property value for the given property key as a long.
 long getLong(String propertyName, long defaultValue)
          Returns the property value for the given property key as a long.
 long getLong(String domainName, String propertyName)
          Returns the property value for the given property key as a long within the given domain.
 long getLong(String domainName, String propertyName, long defaultValue)
          Returns the property value for the given property key as a long within the given domain.
 long[] getLongArray(String propertyName)
          Returns an array of long property values for the given property key.
 long[] getLongArray(String propertyName, long defaultValue)
          Returns an array of long property values for the given property key.
 long[] getLongArray(String domainName, String propertyName)
          Returns an array of long property values for the given property key within the given domain.
 long[] getLongArray(String domainName, String propertyName, long defaultValue)
          Returns an array of long property values for the given property key within the given domain.
 Properties getProperties(String forDomain)
          Returns all the Properties associated with a given domain.
 String getProperty(String forDomain, String propertyName)
          Searches for the property with the specified property name within the given domain.
 String getProperty(String forDomain, String propertyName, String defaultValue)
          Searches for the property with the specified property name within the given domain.
 File getPropertyDirectory()
          Returns the property directory where property files are stored.
 String getString(String propertyName)
          Returns the property value for the given property key as a String.
 String getString(String propertyName, String defaultValue)
          Returns the property value for the given property key as a String.
 String getString(String domainName, String propertyName, String defaultValue)
          Returns the property value for the given property key as a String within the given domain.
 String[] getStringArray(String propertyName)
          Returns an array of String property values for the given property key.
 String[] getStringArray(String propertyName, String defaultValue)
          Returns an array of String property values for the given property key.
 String[] getStringArray(String domainName, String propertyName, String defaultValue)
          Returns an array of String property values for the given property key within the given domain.
 void load()
          Parse and load the properties.
 void setProperty(String forDomain, String propertyName, String propertyValue)
          This method sets the given property for a given domain Each time setProperty is called it writes to the file and refreshes the cache If the entry exists the value is changed otherwise a new value is added.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XMLPropertyManager

public XMLPropertyManager(File propertyFile)
Constructs a XMLPropertyManager, which manages the given property file.

Parameters:
propertyFile - The XML property file to manage.
Method Detail

load

public void load()
Parse and load the properties.


getDefaultDomainName

public static String getDefaultDomainName()
Returns the string used as the default, global domain name.

Returns:
The string used as the default, global domain name.

getBoolean

public boolean getBoolean(String propertyName)
Returns the property value for the given property key as a boolean. Throws an IllegalArgumentException if the property is not found, since primitives have no default value. This method can be used to check the existence of a property without actually adding a new value. Simply try to get the value and catch the exception.

Parameters:
propertyName - The key to search for.
Returns:
The property value for the property key as a boolean.
Throws:
IllegalArgumentException - if the property was not found.

getBoolean

public boolean getBoolean(String domainName,
                          String propertyName)
Returns the property value for the given property key as a boolean within the given domain. Throws an IllegalArgumentException if the property is not found, since primitives have no default value. This method can be used to check the existence of a property without actually adding a new value. Simply try to get the value and catch the exception.

Parameters:
domainName - The domain name.
propertyName - The key to search for.
Returns:
The property value for the property key as a boolean.
Throws:
IllegalArgumentException - if the property was not found.

getBoolean

public boolean getBoolean(String propertyName,
                          boolean defaultValue)
Returns the property value for the given property key as a boolean. Returns the default value if the property is not found.

Parameters:
propertyName - The key to search for.
defaultValue - The value to return if the property key is not found.
Returns:
The property value for the property key as a boolean or the default value.

getBoolean

public boolean getBoolean(String domainName,
                          String propertyName,
                          boolean defaultValue)
Returns the property value for the given property key as a boolean within the given domain. Returns the default value if the property is not found.

Parameters:
domainName - The domain name.
propertyName - The key to search for.
defaultValue - The value to return if the property key is not found.
Returns:
The property value for the property key as a boolean or the default value.

getBooleanArray

public boolean[] getBooleanArray(String propertyName)
Returns an array of boolean property values for the given property key.

Parameters:
propertyName - The key to search for.
Returns:
An array of boolean property values for the property key.

getBooleanArray

public boolean[] getBooleanArray(String domainName,
                                 String propertyName)
Returns an array of boolean property values for the given property key within the given domain.

Parameters:
domainName - The domain name.
propertyName - The key to search for.
Returns:
An array of boolean property values for the property key.

getBooleanArray

public boolean[] getBooleanArray(String propertyName,
                                 boolean defaultValue)
Returns an array of boolean property values for the given property key. If the property is not found, a new boolean array containing the default value will be created and returned.

Parameters:
propertyName - The key to search for.
defaultValue - The value to include in the returned array if the property key is not found.
Returns:
An array of boolean property values for the property key.

getBooleanArray

public boolean[] getBooleanArray(String domainName,
                                 String propertyName,
                                 boolean defaultValue)
Returns an array of boolean property values for the given property key within the given domain. If the property is not found, a new boolean array containing the default value will be created and returned.

Parameters:
domainName - The domain name.
propertyName - The key to search for.
defaultValue - The value to include in the returned array if the property key is not found.
Returns:
An array of boolean property values for the property key.

getChar

public char getChar(String propertyName)
Returns the property value for the given property key as a char. Throws an IllegalArgumentException if the property is not found, since primitives have no default value. This method can be used to check the existence of a property without actually adding a new value. Simply try to get the value and catch the exception.

Parameters:
propertyName - The key to search for.
Returns:
The property value for the property key as a char.
Throws:
IllegalArgumentException - if the property was not found.

getChar

public char getChar(String domainName,
                    String propertyName)
Returns the property value for the given property key as a char within the given domain. Throws an IllegalArgumentException if the property is not found, since primitives have no default value. This method can be used to check the existence of a property without actually adding a new value. Simply try to get the value and catch the exception.

Parameters:
domainName - The domain name.
propertyName - The key to search for.
Returns:
The property value for the property key as a char.
Throws:
IllegalArgumentException - if the property was not found.

getChar

public char getChar(String propertyName,
                    char defaultValue)
Returns the property value for the given property key as a char. Returns the default value if the property is not found.

Parameters:
propertyName - The key to search for.
defaultValue - The value to return if the property key is not found.
Returns:
The property value for the property key as a char or the default value.

getChar

public char getChar(String domainName,
                    String propertyName,
                    char defaultValue)
Returns the property value for the given property key as a char within the given domain. Returns the default value if the property is not found.

Parameters:
domainName - The domain name.
propertyName - The key to search for.
defaultValue - The value to return if the property key is not found.
Returns:
The property value for the property key as a char or the default value.

getCharArray

public char[] getCharArray(String propertyName)
Returns an array of char property values for the given property key.

Parameters:
propertyName - The key to search for.
Returns:
An array of char property values for the property key.

getCharArray

public char[] getCharArray(String domainName,
                           String propertyName)
Returns an array of char property values for the given property key within the given domain.

Parameters:
domainName - The domain name.
propertyName - The key to search for.
Returns:
An array of char property values for the property key.

getCharArray

public char[] getCharArray(String propertyName,
                           char defaultValue)
Returns an array of char property values for the given property key. If the property is not found, a new char array containing the default value will be created and returned.

Parameters:
propertyName - The key to search for.
defaultValue - The value to include in the returned array if the property key is not found.
Returns:
An array of char property values for the property key.

getCharArray

public char[] getCharArray(String domainName,
                           String propertyName,
                           char defaultValue)
Returns an array of char property values for the given property key within the given domain. If the property is not found, a new char array containing the default value will be created and returned.

Parameters:
domainName - The domain name.
propertyName - The key to search for.
defaultValue - The value to include in the returned array if the property key is not found.
Returns:
An array of char property values for the property key.

getDouble

public double getDouble(String propertyName)
Returns the property value for the given property key as a double. Throws an IllegalArgumentException if the property is not found, since primitives have no default value. This method can be used to check the existence of a property without actually adding a new value. Simply try to get the value and catch the exception.

Parameters:
propertyName - The key to search for.
Returns:
The property value for the property key as a double.
Throws:
IllegalArgumentException - if the property was not found.

getDouble

public double getDouble(String domainName,
                        String propertyName)
Returns the property value for the given property key as a double within the given domain. Throws an IllegalArgumentException if the property is not found, since primitives have no default value. This method can be used to check the existence of a property without actually adding a new value. Simply try to get the value and catch the exception.

Parameters:
domainName - The domain name.
propertyName - The key to search for.
Returns:
The property value for the property key as a double.
Throws:
IllegalArgumentException - if the property was not found.

getDouble

public double getDouble(String propertyName,
                        double defaultValue)
Returns the property value for the given property key as a double. Returns the default value if the property is not found.

Parameters:
propertyName - The key to search for.
defaultValue - The value to return if the property key is not found.
Returns:
The property value for the property key as a double or the default value.

getDouble

public double getDouble(String domainName,
                        String propertyName,
                        double defaultValue)
Returns the property value for the given property key as a double within the given domain. Returns the default value if the property is not found.

Parameters:
domainName - The domain name.
propertyName - The key to search for.
defaultValue - The value to return if the property key is not found.
Returns:
The property value for the property key as a double or the default value.

getDoubleArray

public double[] getDoubleArray(String propertyName)
Returns an array of double property values for the given property key.

Parameters:
propertyName - The key to search for.
Returns:
An array of double property values for the property key.

getDoubleArray

public double[] getDoubleArray(String domainName,
                               String propertyName)
Returns an array of double property values for the given property key within the given domain.

Parameters:
domainName - The domain name.
propertyName - The key to search for.
Returns:
An array of double property values for the property key.

getDoubleArray

public double[] getDoubleArray(String propertyName,
                               double defaultValue)
Returns an array of double property values for the given property key. If the property is not found, a new double array containing the default value will be created and returned.

Parameters:
propertyName - The key to search for.
defaultValue - The value to include in the returned array if the property key is not found.
Returns:
An array of double property values for the property key.

getDoubleArray

public double[] getDoubleArray(String domainName,
                               String propertyName,
                               double defaultValue)
Returns an array of double property values for the given property key within the given domain. If the property is not found, a new double array containing the default value will be created and returned.

Parameters:
domainName - The domain name.
propertyName - The key to search for.
defaultValue - The value to include in the returned array if the property key is not found.
Returns:
An array of double property values for the property key.

getFloat

public float getFloat(String propertyName)
Returns the property value for the given property key as a float. Throws an IllegalArgumentException if the property is not found, since primitives have no default value. This method can be used to check the existence of a property without actually adding a new value. Simply try to get the value and catch the exception.

Parameters:
propertyName - The key to search for.
Returns:
The property value for the property key as a float.
Throws:
IllegalArgumentException - if the property was not found.

getFloat

public float getFloat(String domainName,
                      String propertyName)
Returns the property value for the given property key as a float within the given domain. Throws an IllegalArgumentException if the property is not found, since primitives have no default value. This method can be used to check the existence of a property without actually adding a new value. Simply try to get the value and catch the exception.

Parameters:
domainName - The domain name.
propertyName - The key to search for.
Returns:
The property value for the property key as a float.
Throws:
IllegalArgumentException - if the property was not found.

getFloat

public float getFloat(String propertyName,
                      float defaultValue)
Returns the property value for the given property key as a float. Returns the default value if the property is not found.

Parameters:
propertyName - The key to search for.
defaultValue - The value to return if the property key is not found.
Returns:
The property value for the property key as a float or the default value.

getFloat

public float getFloat(String domainName,
                      String propertyName,
                      float defaultValue)
Returns the property value for the given property key as a float within the given domain. Returns the default value if the property is not found.

Parameters:
domainName - The domain name.
propertyName - The key to search for.
defaultValue - The value to return if the property key is not found.
Returns:
The property value for the property key as a float or the default value.

getFloatArray

public float[] getFloatArray(String propertyName)
Returns an array of float property values for the given property key.

Parameters:
propertyName - The key to search for.
Returns:
An array of float property values for the property key.

getFloatArray

public float[] getFloatArray(String domainName,
                             String propertyName)
Returns an array of float property values for the given property key within the given domain.

Parameters:
domainName - The domain name.
propertyName - The key to search for.
Returns:
An array of float property values for the property key.

getFloatArray

public float[] getFloatArray(String propertyName,
                             float defaultValue)
Returns an array of float property values for the given property key. If the property is not found, a new float array containing the default value will be created and returned.

Parameters:
propertyName - The key to search for.
defaultValue - The value to include in the returned array if the property key is not found.
Returns:
An array of float property values for the property key.

getFloatArray

public float[] getFloatArray(String domainName,
                             String propertyName,
                             float defaultValue)
Returns an array of float property values for the given property key within the given domain. If the property is not found, a new float array containing the default value will be created and returned.

Parameters:
domainName - The domain name.
propertyName - The key to search for.
defaultValue - The value to include in the returned array if the property key is not found.
Returns:
An array of float property values for the property key.

getInt

public int getInt(String propertyName)
Returns the property value for the given property key as an int. Throws an IllegalArgumentException if the property is not found, since primitives have no default value. This method can be used to check the existence of a property without actually adding a new value. Simply try to get the value and catch the exception.

Parameters:
propertyName - The key to search for.
Returns:
The property value for the property key as an int.
Throws:
IllegalArgumentException - if the property was not found.

getInt

public int getInt(String domainName,
                  String propertyName)
Returns the property value for the given property key as an int within the given domain. Throws an IllegalArgumentException if the property is not found, since primitives have no default value. This method can be used to check the existence of a property without actually adding a new value. Simply try to get the value and catch the exception.

Parameters:
domainName - The domain name.
propertyName - The key to search for.
Returns:
The property value for the property key as an int.
Throws:
IllegalArgumentException - if the property was not found.

getInt

public int getInt(String propertyName,
                  int defaultValue)
Returns the property value for the given property key as an int. Returns the default value if the property is not found.

Parameters:
propertyName - The key to search for.
defaultValue - The value to return if the property key is not found.
Returns:
The property value for the property key as an int or the default value.

getInt

public int getInt(String domainName,
                  String propertyName,
                  int defaultValue)
Returns the property value for the given property key as an int within the given domain. Returns the default value if the property is not found.

Parameters:
domainName - The domain name.
propertyName - The key to search for.
defaultValue - The value to return if the property key is not found.
Returns:
The property value for the property key as an int or the default value.

getIntArray

public int[] getIntArray(String propertyName)
Returns an array of int property values for the given property key.

Parameters:
propertyName - The key to search for.
Returns:
An array of int property values for the property key.

getIntArray

public int[] getIntArray(String domainName,
                         String propertyName)
Returns an array of int property values for the given property key within the given domain.

Parameters:
domainName - The domain name.
propertyName - The key to search for.
Returns:
An array of int property values for the property key.

getIntArray

public int[] getIntArray(String propertyName,
                         int defaultValue)
Returns an array of int property values for the given property key. If the property is not found, a new int array containing the default value will be created and returned.

Parameters:
propertyName - The key to search for.
defaultValue - The value to include in the returned array if the property key is not found.
Returns:
An array of int property values for the property key.

getIntArray

public int[] getIntArray(String domainName,
                         String propertyName,
                         int defaultValue)
Returns an array of int property values for the given property key within the given domain. If the property is not found, a new int array containing the default value will be created and returned.

Parameters:
domainName - The domain name.
propertyName - The key to search for.
defaultValue - The value to include in the returned array if the property key is not found.
Returns:
An array of int property values for the property key.

getLong

public long getLong(String propertyName)
Returns the property value for the given property key as a long. Throws an IllegalArgumentException if the property is not found, since primitives have no default value. This method can be used to check the existence of a property without actually adding a new value. Simply try to get the value and catch the exception.

Parameters:
propertyName - The key to search for.
Returns:
The property value for the property key as a long.
Throws:
IllegalArgumentException - if the property was not found.

getLong

public long getLong(String domainName,
                    String propertyName)
Returns the property value for the given property key as a long within the given domain. Throws an IllegalArgumentException if the property is not found, since primitives have no default value. This method can be used to check the existence of a property without actually adding a new value. Simply try to get the value and catch the exception.

Parameters:
domainName - The domain name.
propertyName - The key to search for.
Returns:
The property value for the property key as a long.
Throws:
IllegalArgumentException - if the property was not found.

getLong

public long getLong(String propertyName,
                    long defaultValue)
Returns the property value for the given property key as a long. Returns the default value if the property is not found.

Parameters:
propertyName - The key to search for.
defaultValue - The value to return if the property key is not found.
Returns:
The property value for the property key as a long or the default value.

getLong

public long getLong(String domainName,
                    String propertyName,
                    long defaultValue)
Returns the property value for the given property key as a long within the given domain. Returns the default value if the property is not found.

Parameters:
domainName - The domain name.
propertyName - The key to search for.
defaultValue - The value to return if the property key is not found.
Returns:
The property value for the property key as a long or the default value.

getLongArray

public long[] getLongArray(String propertyName)
Returns an array of long property values for the given property key.

Parameters:
propertyName - The key to search for.
Returns:
An array of long property values for the property key.

getLongArray

public long[] getLongArray(String domainName,
                           String propertyName)
Returns an array of long property values for the given property key within the given domain.

Parameters:
domainName - The domain name.
propertyName - The key to search for.
Returns:
An array of long property values for the property key.

getLongArray

public long[] getLongArray(String propertyName,
                           long defaultValue)
Returns an array of long property values for the given property key. If the property is not found, a new long array containing the default value will be created and returned.

Parameters:
propertyName - The key to search for.
defaultValue - The value to include in the returned array if the property key is not found.
Returns:
An array of long property values for the property key.

getLongArray

public long[] getLongArray(String domainName,
                           String propertyName,
                           long defaultValue)
Returns an array of long property values for the given property key within the given domain. If the property is not found, a new long array containing the default value will be created and returned.

Parameters:
domainName - The domain name.
propertyName - The key to search for.
defaultValue - The value to include in the returned array if the property key is not found.
Returns:
An array of long property values for the property key.

getString

public String getString(String propertyName)
Returns the property value for the given property key as a String. Returns null if the property is not found.

Parameters:
propertyName - The key to search for.
Returns:
The property value for the property key as a String or null.

getString

public String getString(String propertyName,
                        String defaultValue)
Returns the property value for the given property key as a String. Returns the default value if the property is not found.

Parameters:
propertyName - The key to search for.
defaultValue - The value to return if the property key is not found.
Returns:
The property value for the property key as a String or the default value.

getString

public String getString(String domainName,
                        String propertyName,
                        String defaultValue)
Returns the property value for the given property key as a String within the given domain. Returns the default value if the property is not found.

Parameters:
domainName - The domain name.
propertyName - The key to search for.
defaultValue - The value to return if the property key is not found.
Returns:
The property value for the property key as a String or the default value.

getStringArray

public String[] getStringArray(String propertyName)
Returns an array of String property values for the given property key.

Parameters:
propertyName - The key to search for.
Returns:
An array of String property values for the property key.

getStringArray

public String[] getStringArray(String propertyName,
                               String defaultValue)
Returns an array of String property values for the given property key. If the property is not found, a new String array containing the default value will be created and returned. If the default value is null, a null will be returned.

Parameters:
propertyName - The key to search for.
defaultValue - The value to include in the returned array if the property key is not found.
Returns:
An array of String property values for the property key.

getStringArray

public String[] getStringArray(String domainName,
                               String propertyName,
                               String defaultValue)
Returns an array of String property values for the given property key within the given domain. If the property is not found, a new String array containing the default value will be created and returned. If the default value is null, a null will be returned.

Parameters:
domainName - The domain name.
propertyName - The key to search for.
defaultValue - The value to include in the returned array if the property key is not found.
Returns:
An array of String property values for the property key.

getPropertyDirectory

public File getPropertyDirectory()
Returns the property directory where property files are stored.

Specified by:
getPropertyDirectory in interface PropertyManager
Returns:
The property directory as a File.

getProperties

public Properties getProperties(String forDomain)
Returns all the Properties associated with a given domain. If there is more than one value for a given property key, the first one in the array is retrieved.

Specified by:
getProperties in interface PropertyManager
Parameters:
forDomain - The domain name.
Returns:
The properties associated with domain, as a Properties object.

getProperty

public String getProperty(String forDomain,
                          String propertyName)
Searches for the property with the specified property name within the given domain. The method returns null if the property is not found.

Specified by:
getProperty in interface PropertyManager
Parameters:
forDomain - The domain name.
propertyName - The key to search for.
Returns:
The property value for the property (name) key or null.

setProperty

public void setProperty(String forDomain,
                        String propertyName,
                        String propertyValue)
This method sets the given property for a given domain Each time setProperty is called it writes to the file and refreshes the cache If the entry exists the value is changed otherwise a new value is added.

Specified by:
setProperty in interface PropertyManager
Parameters:
forDomain - The domain name.
propertyName - The key to search for.
propertyValue - The new value for the property (name) key or null.

getProperty

public String getProperty(String forDomain,
                          String propertyName,
                          String defaultValue)
Searches for the property with the specified property name within the given domain. The method returns the default value if the property is not found.

Specified by:
getProperty in interface PropertyManager
Parameters:
forDomain - The domain name.
propertyName - The key to search for.
defaultValue - The value to return if the property (name) key is not found.
Returns:
The property value for the property (name) key or the default value.

Arch4J 1.1

Copyright © 2000-2004 SpiderLogic, a service of Wipfli Ullrich Bertelson LLP.