Search this API

y.util
Class GlobalProperties

java.lang.Object
  extended by java.util.Dictionary<K,V>
      extended by java.util.Hashtable<java.lang.Object,java.lang.Object>
          extended by java.util.Properties
              extended by y.util.GlobalProperties
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, java.util.Map<java.lang.Object,java.lang.Object>

public class GlobalProperties
extends java.util.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(java.lang.Object o, ObjectStore os)
          Add another object store handler to the properties.
 void addPropertyChangeListener(java.beans.PropertyChangeListener pcl)
          Adds a property change listener.
 void addPropertyChangeListener(java.lang.String propertyName, java.beans.PropertyChangeListener pcl)
          Adds a property change listener.
 java.lang.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 invocation of load().
 ObjectStringConverter getConversion()
          Getter for property conversion.
 java.lang.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 invocation of load().
static GlobalProperties getInstance()
          Returns a singleton instance of global properties.
 java.io.File getProfileFilePath()
          Returns the file this class writes the settings to if the store() method is invoked;
protected  java.net.URL getProfileResource()
          This method is responsible for determining an URL that points to a profile file, that should be used by this instances load() method.
 java.lang.Object getProperty(java.lang.String key, java.lang.Class asClass)
          Retrieve a property in the specified class' form.
 java.lang.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 invocation of 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(java.net.URL fromUrl)
          Load the properties from the specified location.
 java.lang.Object put(java.lang.Object key, java.lang.Object value)
          Store a key value pair (String->Object).
 void removePropertyChangeListener(java.beans.PropertyChangeListener pcl)
          Removes a property change listener.
 void removePropertyChangeListener(java.lang.String propertyName, java.beans.PropertyChangeListener pcl)
          Removes a property change listener.
 void restore(java.lang.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(java.lang.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 invocation of load().
 void setEnvironmentName(java.lang.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 invocation of load().
 void setProfileFilePath(java.io.File file)
          Sets the file this class writes the settings to if the store() method is invoked;
 void setProperty(java.lang.String key, boolean value)
          Convenience setter.
 void setProperty(java.lang.String key, byte value)
          Convenience setter.
 void setProperty(java.lang.String key, double value)
          Convenience setter.
 void setProperty(java.lang.String key, float value)
          Convenience setter.
 void setProperty(java.lang.String key, int value)
          Convenience setter.
 void setUserHomeProfilePath(java.lang.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 invocation of load().
 void store()
          Store the properties to disc.
 void store(java.io.File file)
          Store the properties to the specified file.
 void store(java.lang.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, load, loadFromXML, propertyNames, save, setProperty, store, store, storeToXML, storeToXML, stringPropertyNames
 
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(java.lang.Object o,
                           ObjectStore os)
Add another object store handler to the properties.

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

store

public void store(java.lang.Object o)
Try to serialize the object using a previously installed ObjectStore.

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

restore

public void restore(java.lang.Object o)
Try to deserialize the object using a previously installed ObjectStore.

Parameters:
o - the object to deserialize 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 java.io.IOException
Load the default properties .yed/settings.ypf.

Throws:
java.io.IOException - if loading fails

getClassPathProfilePath

public java.lang.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 invocation of load().


setClassPathProfilePath

public void setClassPathProfilePath(java.lang.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 invocation of load().


getUserHomeProfilePath

public java.lang.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 invocation of load().


setUserHomeProfilePath

public void setUserHomeProfilePath(java.lang.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 invocation of load().


getEnvironmentName

public java.lang.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 invocation of load(). This String defaults to profile.


setEnvironmentName

public void setEnvironmentName(java.lang.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 invocation of load().


getProfileFilePath

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


setProfileFilePath

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


getProfileResource

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


store

public void store()
           throws java.io.IOException
Store the properties to disc.

Throws:
java.io.IOException - if io fails

load

public void load(java.net.URL fromUrl)
          throws java.io.IOException
Load the properties from the specified location.

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

store

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

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

addPropertyChangeListener

public void addPropertyChangeListener(java.beans.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(java.beans.PropertyChangeListener pcl)
Removes a property change listener.

Parameters:
pcl - the listener

addPropertyChangeListener

public void addPropertyChangeListener(java.lang.String propertyName,
                                      java.beans.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(java.lang.String propertyName,
                                         java.beans.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 java.lang.Object put(java.lang.Object key,
                            java.lang.Object value)
Store a key value pair (String->Object).

Specified by:
put in interface java.util.Map<java.lang.Object,java.lang.Object>
Overrides:
put in class java.util.Hashtable<java.lang.Object,java.lang.Object>
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 java.lang.Object getProperty(java.lang.String key,
                                    java.lang.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(java.lang.String key,
                        boolean value)
Convenience setter.

Parameters:
key - the key
value - the value
See Also:
Properties.setProperty(String, String)

setProperty

public void setProperty(java.lang.String key,
                        float value)
Convenience setter.

Parameters:
key - the key
value - the value
See Also:
Properties.setProperty(String, String)

setProperty

public void setProperty(java.lang.String key,
                        double value)
Convenience setter.

Parameters:
key - the key
value - the value
See Also:
Properties.setProperty(String, String)

setProperty

public void setProperty(java.lang.String key,
                        int value)
Convenience setter.

Parameters:
key - the key
value - the value
See Also:
Properties.setProperty(String, String)

setProperty

public void setProperty(java.lang.String key,
                        byte value)
Convenience setter.

Parameters:
key - the key
value - the value
See Also:
Properties.setProperty(String, String)

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