org.cementj.base
Class ApplicationEnvironment

java.lang.Object
  extended by org.cementj.base.ApplicationEnvironment

public abstract class ApplicationEnvironment
extends java.lang.Object

This class provides base functionality for managing configuration properties for applications.

This class assumes that your configuration file is a properties file (see java.util.Properties). If it isn't, you'll have to override the loadProperties method. More detail below.

By default, this class will look for updated properties on the first use after 10 minutes of the last check for updates. You can change this interval by overriding the method getUpdateTimeIntervalInMillis(). An example is provided.

To use this class, do the following:

  • Extend this class in your application.
  • Implement the getConfigurationFileName() method, which returns the name of your configuration file. A sample implementation follows:
  •  protected String getConfigurationFileName()  {return "myapp.properties";}
     
  • Declare a singleton instance as follows (SampleEnvironment extends ApplicationEnvironment):
  •  private static final SampleEnvironment _myEnvironment = new SampleEnvironment();
     
  • Declare an accessor for each of your application properties. An example follows:
  •  public static String getDatabaseConnectionPoolName()
     {
       return _myEnvironment.getProperty("db.pool");
     }
     
  • If you want to change the default refresh interval of 10 minutes, override method getUpdateTimeIntervalInMillis(). An example follows:
  •  protected long getUpdateTimeIntervalInMillis()      {return 1200000;}
     
  • If you have a configuration file in another format, you can override the loadProperties() method and set the properties individually with setProperty().
  • Copyright: Delta Vortex Technologies, 2003.


    Field Summary
    static java.lang.String DEFAULT_CONFIG_FILE_NAME
               
    static long DEFAULT_UPDATE_TIME_INTERVAL
              The default update time interval for application properties is 10 minutes.
     
    Constructor Summary
    protected ApplicationEnvironment()
               
     
    Method Summary
    protected abstract  java.lang.String getConfigurationFileName()
              Method to return the applications configuration property filename.
    protected  java.lang.String getProperty(java.lang.String name)
              Returns the value of a property from the environment.
    protected  java.lang.String getProperty(java.lang.String name, java.lang.String defaultValue)
              Returns the value of a property from the environment.
    protected  java.util.Enumeration getPropertyKeyEnumeration()
               
    protected  long getUpdateTimeIntervalInMillis()
              Provides the refresh time interval used to check fo changes in the properties file.
    protected  void loadProperties()
               
    protected  void loadProperties(java.util.Properties props)
              Appends properties to the application property set.
    protected  void setProperty(java.lang.String property, java.lang.String value)
              Sets a property in the environment.
     
    Methods inherited from class java.lang.Object
    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
     

    Field Detail

    DEFAULT_UPDATE_TIME_INTERVAL

    public static final long DEFAULT_UPDATE_TIME_INTERVAL
    The default update time interval for application properties is 10 minutes.

    See Also:
    Constant Field Values

    DEFAULT_CONFIG_FILE_NAME

    public static final java.lang.String DEFAULT_CONFIG_FILE_NAME
    See Also:
    Constant Field Values
    Constructor Detail

    ApplicationEnvironment

    protected ApplicationEnvironment()
    Method Detail

    getProperty

    protected java.lang.String getProperty(java.lang.String name)
    Returns the value of a property from the environment.

    Parameters:
    name -
    Returns:
    value

    getProperty

    protected java.lang.String getProperty(java.lang.String name,
                                           java.lang.String defaultValue)
    Returns the value of a property from the environment. If the property doesn't exist, the default value is returned.

    Parameters:
    name -
    defaultValue -
    Returns:
    value

    setProperty

    protected void setProperty(java.lang.String property,
                               java.lang.String value)
    Sets a property in the environment. Neither the proporty or its value can be null.

    Parameters:
    property -
    value -

    loadProperties

    protected void loadProperties()

    loadProperties

    protected void loadProperties(java.util.Properties props)
    Appends properties to the application property set.

    Parameters:
    props -

    getPropertyKeyEnumeration

    protected java.util.Enumeration getPropertyKeyEnumeration()

    getConfigurationFileName

    protected abstract java.lang.String getConfigurationFileName()
    Method to return the applications configuration property filename.

    Returns:
    fileName

    getUpdateTimeIntervalInMillis

    protected long getUpdateTimeIntervalInMillis()
    Provides the refresh time interval used to check fo changes in the properties file.

    Returns:
    timeInMillis


    Copyright © 2003 Delta Vortex Technologies, Inc. All Rights Reserved.