y.util
Class GlobalProperties

java.lang.Object
  |
  +--java.util.Dictionary
        |
        +--java.util.Hashtable
              |
              +--java.util.Properties
                    |
                    +--y.util.GlobalProperties
All Implemented Interfaces:
Cloneable, Map, Serializable

public class GlobalProperties
extends Properties

Singleton class that can manage global properties for an application, store and reload them in and from a properties file and manage the object <-> string conversion process.

See Also:
Serialized Form

Field Summary
 
Fields inherited from class java.util.Properties
defaults
 
Method Summary
 void addObjectStore(Object o, ObjectStore os)
          add another objectstore handler to the properties
 void addPropertyChangeListener(PropertyChangeListener pcl)
          Adds a property change listener.
 void addPropertyChangeListener(String propertyName, PropertyChangeListener pcl)
          Adds a property change listener.
 String getClassPathProfilePath()
          Returns the relative path from the class path to the profile that will be used for loading the properties into this instance upon invokation of GlobalProperties.load().
 ObjectStringConverter getConversion()
          Getter for property conversion.
 String getEnvironmentName()
          Returns the environment name that will be queried for an filename that will be used for loading the properties into this instance upon invokation of GlobalProperties.load().
static GlobalProperties getInstance()
          Returns a singleton instance of global properties.
 File getProfileFilePath()
          Returns the file this class writes the settings to if the GlobalProperties.store() method is invoked;
protected  URL getProfileResource()
          This method is responsible for determining an URL that points to a profile file, that should be used by this instances GlobalProperties.load() method.
 Object getProperty(String key, Class asClass)
          retrieve a property in the specified class' form
 String getUserHomeProfilePath()
          Returns the relative path from the user home to the profile that will be used for loading the properties into this instance upon invokation of GlobalProperties.load().
protected static void installInstance(GlobalProperties gp)
          install the given singleton object as the singleton
 void load()
          load the default properties .yed/settings.ypf
 void load(URL fromUrl)
          load the properties from the specified location
 Object put(Object key, Object value)
          store a key value pair (String->Object)
 void removePropertyChangeListener(PropertyChangeListener pcl)
          Removes a property change listener.
 void removePropertyChangeListener(String propertyName, PropertyChangeListener pcl)
          Removes a property change listener.
 void restore(Object o)
          try to deserialize the object using a previously installed ObjectStore
 void restoreAll()
          restore all previously registered object from the underlying properties
 void setClassPathProfilePath(String path)
          Sets the relative path from the class path to the profile that will be used for loading the properties into this instance upon invokation of GlobalProperties.load().
 void setEnvironmentName(String name)
          Sets the environment name that will be queried for an filename that will be used for loading the properties into this instance upon invokation of GlobalProperties.load().
 void setProfileFilePath(File file)
          Sets the file this class writes the settings to if the GlobalProperties.store() method is invoked;
 void setProperty(String key, boolean value)
          convenience setter
 void setProperty(String key, byte value)
          convenience setter
 void setProperty(String key, double value)
          convenience setter
 void setProperty(String key, float value)
          convenience setter
 void setProperty(String key, int value)
          convenience setter
 void setUserHomeProfilePath(String path)
          Sets the relative path from the user home to the profile that will be used for loading the properties into this instance upon invokation of GlobalProperties.load().
 void store()
          store the properties to disc
 void store(File file)
          Store the properties to the specified file.
 void store(Object o)
          try to serialize the object using a previously installed ObjectStore
 void storeAll()
          store all elements registered previously to the underlying properties instance
 
Methods inherited from class java.util.Properties
getProperty, getProperty, list, list, load, propertyNames, save, setProperty, store
 
Methods inherited from class java.util.Hashtable
clear, clone, contains, containsKey, containsValue, elements, entrySet, equals, get, hashCode, isEmpty, keys, keySet, putAll, rehash, remove, size, toString, values
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Method Detail

installInstance

protected static void installInstance(GlobalProperties gp)
install the given singleton object as the singleton


addObjectStore

public void addObjectStore(Object o,
                           ObjectStore os)
add another objectstore handler to the properties

Parameters:
o - the object to be stored
os - the given handler

store

public void store(Object o)
try to serialize the object using a previously installed ObjectStore

Parameters:
o - the object to serializ to this properties object

restore

public void restore(Object o)
try to deserialize the object using a previously installed ObjectStore

Parameters:
o - the object to deserializ from this properties object

storeAll

public void storeAll()
store all elements registered previously to the underlying properties instance


restoreAll

public void restoreAll()
restore all previously registered object from the underlying properties


load

public void load()
          throws IOException
load the default properties .yed/settings.ypf

Throws:
IOException - if loading fails

getClassPathProfilePath

public String getClassPathProfilePath()
Returns the relative path from the class path to the profile that will be used for loading the properties into this instance upon invokation of GlobalProperties.load().


setClassPathProfilePath

public void setClassPathProfilePath(String path)
Sets the relative path from the class path to the profile that will be used for loading the properties into this instance upon invokation of GlobalProperties.load().


getUserHomeProfilePath

public String getUserHomeProfilePath()
Returns the relative path from the user home to the profile that will be used for loading the properties into this instance upon invokation of GlobalProperties.load().


setUserHomeProfilePath

public void setUserHomeProfilePath(String path)
Sets the relative path from the user home to the profile that will be used for loading the properties into this instance upon invokation of GlobalProperties.load().


getEnvironmentName

public String getEnvironmentName()
Returns the environment name that will be queried for an filename that will be used for loading the properties into this instance upon invokation of GlobalProperties.load(). This String defaults to profile.


setEnvironmentName

public void setEnvironmentName(String name)
Sets the environment name that will be queried for an filename that will be used for loading the properties into this instance upon invokation of GlobalProperties.load().


getProfileFilePath

public File getProfileFilePath()
Returns the file this class writes the settings to if the GlobalProperties.store() method is invoked;


setProfileFilePath

public void setProfileFilePath(File file)
Sets the file this class writes the settings to if the GlobalProperties.store() method is invoked;


getProfileResource

protected URL getProfileResource()
This method is responsible for determining an URL that points to a profile file, that should be used by this instances GlobalProperties.load() method. By default, the implementation uses the environment property, the relative path from the user home and the relatvie path in the classpath in that order to determine the file to be chosen.


store

public void store()
           throws IOException
store the properties to disc

Throws:
IOException - if io fails

load

public void load(URL fromUrl)
          throws IOException
load the properties from the specified location

Throws:
IOException - if loading fails
Parameters:
fromUrl - where to get the properties from

store

public void store(File file)
           throws IOException
Store the properties to the specified file. This method returns silently if file is null.

Throws:
IOException - if I/O fails
Parameters:
file - where to store the properties

addPropertyChangeListener

public void addPropertyChangeListener(PropertyChangeListener pcl)
Adds a property change listener. All registered listeners will be informed when a property value will be changed by a call to Properties.setProperty(String, String).

Parameters:
pcl - the listener

removePropertyChangeListener

public void removePropertyChangeListener(PropertyChangeListener pcl)
Removes a property change listener.

Parameters:
pcl - the listener

addPropertyChangeListener

public void addPropertyChangeListener(String propertyName,
                                      PropertyChangeListener pcl)
Adds a property change listener. All registered listeners will be informed when the property value will be changed by a call to Properties.setProperty(String, String).

Parameters:
propertyName - the property
pcl - the listener

removePropertyChangeListener

public void removePropertyChangeListener(String propertyName,
                                         PropertyChangeListener pcl)
Removes a property change listener.

Parameters:
propertyName - the property
pcl - the listener

getInstance

public static GlobalProperties getInstance()
Returns a singleton instance of global properties.

Returns:
the instance

put

public Object put(Object key,
                  Object value)
store a key value pair (String->Object)

Specified by:
put in interface Map
Overrides:
put in class Hashtable
Parameters:
key - the key (String)
value - the value
Returns:
the former value

getConversion

public ObjectStringConverter getConversion()
Getter for property conversion.

Returns:
Value of property conversion.

getProperty

public Object getProperty(String key,
                          Class asClass)
retrieve a property in the specified class' form

Parameters:
key - the key for the property
asClass - the type of the returned object
Returns:
the object or null if none was found

setProperty

public void setProperty(String key,
                        boolean value)
convenience setter

Parameters:
key - the key
value - the value

setProperty

public void setProperty(String key,
                        float value)
convenience setter

Parameters:
key - the key
value - the value

setProperty

public void setProperty(String key,
                        double value)
convenience setter

Parameters:
key - the key
value - the value

setProperty

public void setProperty(String key,
                        int value)
convenience setter

Parameters:
key - the key
value - the value

setProperty

public void setProperty(String key,
                        byte value)
convenience setter

Parameters:
key - the key
value - the value

© Copyright 2000-2003,
yWorks GmbH.
All rights reserved.

2003