Arch4J 1.1

org.arch4j.property
Class PropertyProvider

java.lang.Object
  |
  +--org.arch4j.property.PropertyProvider

public class PropertyProvider
extends Object

This class is the main service provider for simple property services. The services are accessed via the static getProvider() method. Originally, this provider was designed as a mechanism to aggregate the plethora of Java Properties files into a single cohesive service, whereby property keys could be looked up via a domain, which acted as a grouping mechanism. This model is referred to as old-style property management.

The new-style mechanism uses a single XML file to contain the properties, retains the concept of domain as a grouping mechanism within the XML file, and adds the ability to define a type for each property value, such as boolean or int. In addition to the XML property file, the new-style mechanism adds an easy startup concept by way of a startup constants class. This eases the burden of bootstrapping enough system properties just to let the various Arch4J providers themselves startup. The other providers should use this class for all of their property lookup, either by looking up a property via a particular domain, or by using the default domain, or by accessing constant values through the new constants class.

For historical purposes, properties retrieved via the old-style mechanism uses code that looks like the following:

 String value = PropertyProvider.getProvider().getPropertyManager().
     getProperty("someDomain", "someProperty.key");
 

The domain is taken as the root of the property file name. The suffix .properties is appended to the domain name to create a file name that is parsed to try to find the property.

Property files are searched for in the directory specified by the system property arch4j.property.directory. This property can be set on the Java VM command line with the -D option, as in:

 java -Darch4j.property.directory=C:/properties -classpath ...
 

If the system property is not set, property files will be searched for in the current directory (where the VM was started). If the property file is not found in that directory, the property manager will try to find the file by searching for the file as a resource on the classpath. This is useful for web applications that cannot set the system property arch4j.property.directory.

For the new-style, constants class-based mechanism, this class is initialized by searching for the system property arch4j.constants.class. If that property is set, then the new-style is used. Otherwise, the old-style is used. If the constants class property is defined, the value should be a class name, a subclass of StartupConstants. This class will create an instance of that constants class, available on the provider via the method getConstants(). The constants class is used to point the property provider at the application home directory, and to an XML property file. Once loaded, properties can be retrieved in exactly the same manner as above, via one of the getProperty() methods.

Since the XML-based property scheme adds type capability, there is an additional method available on this class which can be used to get at all the new functionality. It is named getNewPropertyManager(). Not only can you access string property values, but other types as well. For example:

 int timeout = PropertyProvider.getProvider().getNewPropertyManager().
     getInt("someDomain", "someTimeoutProperty.key");
 

The conversion of non-string types is performed when the XML property file is parsed. Any errors are reported at that time, so valid types are guaranteed at application runtime.

The format of the XML property file allows more than one value to be stored for each key, so you can get an array of values for a single key without having separate key names for each element.

 int[] validValues = PropertyProvider.getProvider().getNewPropertyManager().
     getIntArray("someDomain", "validValues");
 

Even though the concept of domains is maintained with the new-style scheme, you do not need to use it. A default domain is maintained and used if not specified. The following example shows this; simply leave the domain name off.

 double rate = PropertyProvider.getProvider().getNewPropertyManager().
     getDouble("conversionRate");
 

If your application runs inside of a web container, use the StartupServlet to configure the bootstrapping of the property provider instead of using system properties. See the documentation on that class for more information, as well as the documentation on StartupConstants for rich client applications (Swing apps or Console apps). For information on the format and tags used in the XML properties file, see XMLPropertyManager.

Version:
$Revision: 1.11 $
Author:
Russ Brown, Ross E. Greinke
See Also:
PropertyManager, StartupConstants, StartupServlet, XMLPropertyManager

Field Summary
static String PROPERTY_DIRECTORY_PROPERTY
          The old-style property specifying where property files live.
static String SUPPRESS_CONSTANTS_MESSAGE_PROPERTY
          The property that can be used to suppress the constants warning message.
 
Constructor Summary
protected PropertyProvider()
           
 
Method Summary
 StartupConstants getConstants()
          Returns the startup constants.
 XMLPropertyManager getNewPropertyManager()
          Returns the new-style property manager, which allows access to all of the additional methods available.
 PropertyManager getPropertyManager()
          Returns the property manager.
static PropertyProvider getProvider()
          Returns the single instance of the PropertyProvider.
protected  void initialize()
          Initialize the receiver.
static void resetProvider()
          Reset the single instance of the PropertyProvider.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PROPERTY_DIRECTORY_PROPERTY

public static final String PROPERTY_DIRECTORY_PROPERTY
The old-style property specifying where property files live.

See Also:
Constant Field Values

SUPPRESS_CONSTANTS_MESSAGE_PROPERTY

public static final String SUPPRESS_CONSTANTS_MESSAGE_PROPERTY
The property that can be used to suppress the constants warning message.

See Also:
Constant Field Values
Constructor Detail

PropertyProvider

protected PropertyProvider()
Method Detail

initialize

protected void initialize()
Initialize the receiver.


getProvider

public static PropertyProvider getProvider()
Returns the single instance of the PropertyProvider.

Returns:
The single instance of the PropertyProvider.

resetProvider

public static void resetProvider()
Reset the single instance of the PropertyProvider.


getConstants

public StartupConstants getConstants()
Returns the startup constants.

Returns:
The startup constants.

getPropertyManager

public PropertyManager getPropertyManager()
Returns the property manager.

Returns:
The property manager.

getNewPropertyManager

public XMLPropertyManager getNewPropertyManager()
Returns the new-style property manager, which allows access to all of the additional methods available.

Returns:
The property manager, casted to be a XMLPropertyManager.

Arch4J 1.1

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