Jitsi: the OpenSource Java VoIP and Instant Messaging client.

net.java.sip.communicator.impl.configuration
Class ConfigurationServiceImpl

java.lang.Object
  extended by net.java.sip.communicator.impl.configuration.ConfigurationServiceImpl
All Implemented Interfaces:
ConfigurationService

public class ConfigurationServiceImpl
extends Object
implements ConfigurationService

A straightforward implementation of the ConfigurationService using an XML or a .properties file for storing properties. Currently only String properties are meaningfully saved (we should probably consider how and whether we should take care of the rest).

Author:
Emil Ivov, Damian Minkov, Lyubomir Marinov, Dmitri Melnikov

Field Summary
 
Fields inherited from interface net.java.sip.communicator.service.configuration.ConfigurationService
PNAME_CONFIGURATION_FILE_NAME, PNAME_SC_HOME_DIR_LOCATION, PNAME_SC_HOME_DIR_NAME
 
Constructor Summary
ConfigurationServiceImpl()
           
 
Method Summary
 void addPropertyChangeListener(PropertyChangeListener listener)
          Adds a PropertyChangeListener to the listener list.
 void addPropertyChangeListener(String propertyName, PropertyChangeListener listener)
          Adds a PropertyChangeListener to the listener list for a specific property.
 void addVetoableChangeListener(ConfigVetoableChangeListener listener)
          Adds a VetoableChangeListener to the listener list.
 void addVetoableChangeListener(String propertyName, ConfigVetoableChangeListener listener)
          Adds a VetoableChangeListener to the listener list for a specific property.
 List<String> getAllPropertyNames()
          Returns a java.util.List of Strings containing all property names.
 boolean getBoolean(String propertyName, boolean defaultValue)
          Gets the value of a specific property as a boolean.
 int getInt(String propertyName, int defaultValue)
          Gets the value of a specific property as a signed decimal integer.
 long getLong(String propertyName, long defaultValue)
          Gets the value of a specific property as a signed decimal long integer.
 Object getProperty(String propertyName)
          Returns the value of the property with the specified name or null if no such property exists.
 List<String> getPropertyNamesByPrefix(String prefix, boolean exactPrefixMatch)
          Returns a java.util.List of Strings containing the all property names that have the specified prefix.
 List<String> getPropertyNamesBySuffix(String suffix)
          Returns a List of Strings containing the property names that have the specified suffix.
 String getScHomeDirLocation()
          Returns the location of the directory where SIP Communicator is to store user specific data such as configuration files, message and call history as well as is bundle repository.
 String getScHomeDirName()
          Returns the name of the directory where SIP Communicator is to store user specific data such as configuration files, message and call history as well as is bundle repository.
 String getString(String propertyName)
          Returns the String value of the specified property (minus all encompasssing whitespaces)and null in case no property value was mapped against the specified propertyName, or in case the returned property string had zero length or contained whitespaces only.
 String getString(String propertyName, String defaultValue)
          Returns the String value of the specified property and null in case no property value was mapped against the specified propertyName, or in case the returned property string had zero length or contained whitespaces only.
 void purgeStoredConfiguration()
          Deletes the configuration file currently used by this implementation.
 void reloadConfiguration()
          Deletes the current configuration and reloads it from the configuration file.
 void removeProperty(String propertyName)
          Removes the property with the specified name.
 void removePropertyChangeListener(PropertyChangeListener listener)
          Removes a PropertyChangeListener from the listener list.
 void removePropertyChangeListener(String propertyName, PropertyChangeListener listener)
          Removes a PropertyChangeListener from the listener list for a specific property.
 void removeVetoableChangeListener(ConfigVetoableChangeListener listener)
          Removes a VetoableChangeListener from the listener list.
 void removeVetoableChangeListener(String propertyName, ConfigVetoableChangeListener listener)
          Removes a VetoableChangeListener from the listener list for a specific property.
 void setProperties(Map<String,Object> properties)
          Sets a set of specific properties to specific values as a batch operation meaning that first VetoableChangeListeners are asked to approve the modifications of the specified properties to the specified values, then the modifications are performed if no complaints have been raised in the form of PropetyVetoException and finally PropertyChangeListeners are notified about the changes of each of the specified properties.
 void setProperty(String propertyName, Object property)
          Sets the property with the specified name to the specified value.
 void setProperty(String propertyName, Object property, boolean isSystem)
          Sets the property with the specified name to the specified.
(package private)  void start(org.osgi.framework.BundleContext bc)
          Initializes the configuration service impl and makes it load an initial configuration from the conf file.
(package private)  void stop()
          Called on service stop.
 void storeConfiguration()
          Store the current set of properties back to the configuration file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ConfigurationServiceImpl

public ConfigurationServiceImpl()
Method Detail

setProperty

public void setProperty(String propertyName,
                        Object property)
Sets the property with the specified name to the specified value. Calling this method would first trigger a PropertyChangeEvent that will be dispatched to all VetoableChangeListeners. In case no complaints (PropertyVetoException) have been received, the property will be actually changed and a PropertyChangeEvent will be dispatched.

Specified by:
setProperty in interface ConfigurationService
Parameters:
propertyName - String
property - Object

setProperty

public void setProperty(String propertyName,
                        Object property,
                        boolean isSystem)
Sets the property with the specified name to the specified. Calling this method would first trigger a PropertyChangeEvent that will be dispatched to all VetoableChangeListeners. In case no complaints (PropertyVetoException) have been received, the property will be actually changed and a PropertyChangeEvent will be dispatched. This method also allows the caller to specify whether or not the specified property is a system one.

Specified by:
setProperty in interface ConfigurationService
Parameters:
propertyName - the name of the property to change.
property - the new value of the specified property.
isSystem - specifies whether or not the property being is a System property and should be resolved against the system property set. If the property has previously been specified as system then this value is internally forced to true.

setProperties

public void setProperties(Map<String,Object> properties)
Description copied from interface: ConfigurationService
Sets a set of specific properties to specific values as a batch operation meaning that first VetoableChangeListeners are asked to approve the modifications of the specified properties to the specified values, then the modifications are performed if no complaints have been raised in the form of PropetyVetoException and finally PropertyChangeListeners are notified about the changes of each of the specified properties. The batch operations allows the ConfigurationService implementations to optimize, for example, the saving of the configuration which in this case can be performed only once for the setting of multiple properties.

Specified by:
setProperties in interface ConfigurationService
Parameters:
properties - a Map of property names to their new values to be set

removeProperty

public void removeProperty(String propertyName)
Removes the property with the specified name. Calling this method would first trigger a PropertyChangeEvent that will be dispatched to all VetoableChangeListeners. In case no complaints (PropertyVetoException) have been received, the property will be actually changed and a PropertyChangeEvent will be dispatched. All properties with prefix propertyName will also be removed.

Specified by:
removeProperty in interface ConfigurationService
Parameters:
propertyName - the name of the property to change.

getProperty

public Object getProperty(String propertyName)
Returns the value of the property with the specified name or null if no such property exists.

Specified by:
getProperty in interface ConfigurationService
Parameters:
propertyName - the name of the property that is being queried.
Returns:
the value of the property with the specified name.

getAllPropertyNames

public List<String> getAllPropertyNames()
Returns a java.util.List of Strings containing all property names.

Specified by:
getAllPropertyNames in interface ConfigurationService
Returns:
a java.util.Listcontaining all property names

getPropertyNamesByPrefix

public List<String> getPropertyNamesByPrefix(String prefix,
                                             boolean exactPrefixMatch)
Returns a java.util.List of Strings containing the all property names that have the specified prefix. Depending on the value of the exactPrefixMatch parameter the method will (when false) or will not (when exactPrefixMatch is true) include property names that have prefixes longer than the specified prefix param.

Example:

Imagine a configuration service instance containing 2 properties only:
net.java.sip.communicator.PROP1=value1
net.java.sip.communicator.service.protocol.PROP1=value2

A call to this method with a prefix="net.java.sip.communicator" and exactPrefixMatch=true would only return the first property - net.java.sip.communicator.PROP1, whereas the same call with exactPrefixMatch=false would return both properties as the second prefix includes the requested prefix string.

Specified by:
getPropertyNamesByPrefix in interface ConfigurationService
Parameters:
prefix - a String containing the prefix (the non dotted non-caps part of a property name) that we're looking for.
exactPrefixMatch - a boolean indicating whether the returned property names should all have a prefix that is an exact match of the the prefix param or whether properties with prefixes that contain it but are longer than it are also accepted.
Returns:
a java.util.Listcontaining all property name String-s matching the specified conditions.

getPropertyNamesBySuffix

public List<String> getPropertyNamesBySuffix(String suffix)
Returns a List of Strings containing the property names that have the specified suffix. A suffix is considered to be everything after the last dot in the property name.

For example, imagine a configuration service instance containing two properties only:

net.java.sip.communicator.PROP1=value1 net.java.sip.communicator.service.protocol.PROP1=value2

A call to this method with suffix equal to "PROP1" will return both properties, whereas the call with suffix equal to "communicator.PROP1" or "PROP2" will return an empty List. Thus, if the suffix argument contains a dot, nothing will be found.

Specified by:
getPropertyNamesBySuffix in interface ConfigurationService
Parameters:
suffix - the suffix for the property names to be returned
Returns:
a List of Strings containing the property names which contain the specified suffix

addPropertyChangeListener

public void addPropertyChangeListener(PropertyChangeListener listener)
Adds a PropertyChangeListener to the listener list.

Specified by:
addPropertyChangeListener in interface ConfigurationService
Parameters:
listener - the PropertyChangeListener to be added

removePropertyChangeListener

public void removePropertyChangeListener(PropertyChangeListener listener)
Removes a PropertyChangeListener from the listener list.

Specified by:
removePropertyChangeListener in interface ConfigurationService
Parameters:
listener - the PropertyChangeListener to be removed

addPropertyChangeListener

public void addPropertyChangeListener(String propertyName,
                                      PropertyChangeListener listener)
Adds a PropertyChangeListener to the listener list for a specific property.

Specified by:
addPropertyChangeListener in interface ConfigurationService
Parameters:
propertyName - one of the property names listed above
listener - the PropertyChangeListener to be added

removePropertyChangeListener

public void removePropertyChangeListener(String propertyName,
                                         PropertyChangeListener listener)
Removes a PropertyChangeListener from the listener list for a specific property.

Specified by:
removePropertyChangeListener in interface ConfigurationService
Parameters:
propertyName - a valid property name
listener - the PropertyChangeListener to be removed

addVetoableChangeListener

public void addVetoableChangeListener(ConfigVetoableChangeListener listener)
Adds a VetoableChangeListener to the listener list.

Specified by:
addVetoableChangeListener in interface ConfigurationService
Parameters:
listener - the VetoableChangeListener to be added

removeVetoableChangeListener

public void removeVetoableChangeListener(ConfigVetoableChangeListener listener)
Removes a VetoableChangeListener from the listener list.

Specified by:
removeVetoableChangeListener in interface ConfigurationService
Parameters:
listener - the VetoableChangeListener to be removed

addVetoableChangeListener

public void addVetoableChangeListener(String propertyName,
                                      ConfigVetoableChangeListener listener)
Adds a VetoableChangeListener to the listener list for a specific property.

Specified by:
addVetoableChangeListener in interface ConfigurationService
Parameters:
propertyName - one of the property names listed above
listener - the VetoableChangeListener to be added

removeVetoableChangeListener

public void removeVetoableChangeListener(String propertyName,
                                         ConfigVetoableChangeListener listener)
Removes a VetoableChangeListener from the listener list for a specific property.

Specified by:
removeVetoableChangeListener in interface ConfigurationService
Parameters:
propertyName - a valid property name
listener - the VetoableChangeListener to be removed

stop

void stop()
Called on service stop.


start

void start(org.osgi.framework.BundleContext bc)
Initializes the configuration service impl and makes it load an initial configuration from the conf file.

Parameters:
bc - the BundleContext provided by the OSGi framework

reloadConfiguration

public void reloadConfiguration()
                         throws IOException,
                                XMLException
Description copied from interface: ConfigurationService
Deletes the current configuration and reloads it from the configuration file. The name of the configuration file is queried from the system property net.java.sip.communicator.PROPERTIES_FILE_NAME, and is set to sip-communicator.xml in case the property does not contain a valid file name. The location might be one of three possibile, checked in the following order:
1. The current directory.
2. The sip-communicator directory in the user.home ($HOME/.sip-communicator) 3. A location in the classpath (such as the sip-communicator jar file).

In the last case the file is copied to the sip-communicator configuration directory right after being extracted from the classpath location.

Specified by:
reloadConfiguration in interface ConfigurationService
Throws:
IOException - in case reading the configuration failes
XMLException - in case parsing the configuration file has failed

storeConfiguration

public void storeConfiguration()
                        throws IOException
Description copied from interface: ConfigurationService
Store the current set of properties back to the configuration file. The name of the configuration file is queried from the system property net.java.sip.communicator.PROPERTIES_FILE_NAME, and is set to sip-communicator.xml in case the property does not contain a valid file name. The location might be one of three possibile, checked in the following order:
1. The current directory.
2. The sip-communicator directory in the user.home ($HOME/.sip-communicator) 3. A location in the classpath (such as the sip-communicator jar file).

In the last case the file is copied to the sip-communicator configuration directory right after being extracted from the classpath location.

Specified by:
storeConfiguration in interface ConfigurationService
Throws:
IOException - in case storing the configuration failed.

getScHomeDirLocation

public String getScHomeDirLocation()
Returns the location of the directory where SIP Communicator is to store user specific data such as configuration files, message and call history as well as is bundle repository.

Specified by:
getScHomeDirLocation in interface ConfigurationService
Returns:
the location of the directory where SIP Communicator is to store user specific data such as configuration files, message and call history as well as is bundle repository.

getScHomeDirName

public String getScHomeDirName()
Returns the name of the directory where SIP Communicator is to store user specific data such as configuration files, message and call history as well as is bundle repository.

Specified by:
getScHomeDirName in interface ConfigurationService
Returns:
the name of the directory where SIP Communicator is to store user specific data such as configuration files, message and call history as well as is bundle repository.

getString

public String getString(String propertyName)
Returns the String value of the specified property (minus all encompasssing whitespaces)and null in case no property value was mapped against the specified propertyName, or in case the returned property string had zero length or contained whitespaces only.

Specified by:
getString in interface ConfigurationService
Parameters:
propertyName - the name of the property that is being queried.
Returns:
the result of calling the property's toString method and null in case there was no vlaue mapped against the specified propertyName, or the returned string had zero length or contained whitespaces only.

getString

public String getString(String propertyName,
                        String defaultValue)
Returns the String value of the specified property and null in case no property value was mapped against the specified propertyName, or in case the returned property string had zero length or contained whitespaces only.

Specified by:
getString in interface ConfigurationService
Parameters:
propertyName - the name of the property that is being queried.
defaultValue - the value to be returned if the specified property name is not associated with a value in this ConfigurationService
Returns:
the result of calling the property's toString method and defaultValue in case there was no value mapped against the specified propertyName, or the returned string had zero length or contained whitespaces only.

getBoolean

public boolean getBoolean(String propertyName,
                          boolean defaultValue)
Description copied from interface: ConfigurationService
Gets the value of a specific property as a boolean. If the specified property name is associated with a value in this ConfigurationService, the string representation of the value is parsed into a boolean according to the rules of Boolean.parseBoolean(String) . Otherwise, defaultValue is returned.

Specified by:
getBoolean in interface ConfigurationService
Parameters:
propertyName - the name of the property to get the value of as a boolean
defaultValue - the value to be returned if the specified property name is not associated with a value in this ConfigurationService
Returns:
the value of the property with the specified name in this ConfigurationService as a boolean; defaultValue if the property with the specified name is not associated with a value in this ConfigurationService

getInt

public int getInt(String propertyName,
                  int defaultValue)
Gets the value of a specific property as a signed decimal integer. If the specified property name is associated with a value in this ConfigurationService, the string representation of the value is parsed into a signed decimal integer according to the rules of Integer.parseInt(String) . If parsing the value as a signed decimal integer fails or there is no value associated with the specified property name, defaultValue is returned.

Specified by:
getInt in interface ConfigurationService
Parameters:
propertyName - the name of the property to get the value of as a signed decimal integer
defaultValue - the value to be returned if parsing the value of the specified property name as a signed decimal integer fails or there is no value associated with the specified property name in this ConfigurationService
Returns:
the value of the property with the specified name in this ConfigurationService as a signed decimal integer; defaultValue if parsing the value of the specified property name fails or no value is associated in this ConfigurationService with the specified property name

getLong

public long getLong(String propertyName,
                    long defaultValue)
Gets the value of a specific property as a signed decimal long integer. If the specified property name is associated with a value in this ConfigurationService, the string representation of the value is parsed into a signed decimal long integer according to the rules of Long.parseLong(String) . If parsing the value as a signed decimal long integer fails or there is no value associated with the specified property name, defaultValue is returned.

Specified by:
getLong in interface ConfigurationService
Parameters:
propertyName - the name of the property to get the value of as a signed decimal long integer
defaultValue - the value to be returned if parsing the value of the specified property name as a signed decimal long integer fails or there is no value associated with the specified property name in this ConfigurationService
Returns:
the value of the property with the specified name in this ConfigurationService as a signed decimal long integer; defaultValue if parsing the value of the specified property name fails or no value is associated in this ConfigurationService with the specified property name

purgeStoredConfiguration

public void purgeStoredConfiguration()
Deletes the configuration file currently used by this implementation.

Specified by:
purgeStoredConfiguration in interface ConfigurationService

Jitsi: the OpenSource Java VoIP and Instant Messaging client.

Jitsi, the OpenSource Java VoIP and Instant Messaging client.
Distributable under LGPL license.