org.openbp.common.setting
Class PropertyFileProvider

java.lang.Object
  extended by org.openbp.common.setting.PropertyFileProvider
All Implemented Interfaces:
SettingProvider

public class PropertyFileProvider
extends java.lang.Object
implements SettingProvider

Implementation of a setting provider that supports access to property files. Property files contain lines of the form

Author:
Heiko Erhardt

Constructor Summary
PropertyFileProvider()
          Default constructor.
 
Method Summary
 void clear()
          Clears all property settings.
 java.lang.String getFileHeader()
          Gets the property file header.
 java.util.Properties getProperties()
          Gets the table of all properties.
 java.lang.String getPropertyResourceName()
          Gets the property file name.
 java.net.URL getPropertyResourceUrl()
          Gets the URL of the property resource.
 java.lang.Object getSetting(java.lang.String name)
          Gets a setting value.
 boolean isMandatory()
          Gets the mandatory flag.
 boolean isReadonly()
          Gets the readonly flag.
 boolean isSaveExistingPropertiesOnly()
          Gets the flag to save only properties that already exist in the property file.
 boolean loadSettings()
          Loads the settings.
 boolean saveSettings()
          Saves the settings.
 void setFileHeader(java.lang.String fileHeader)
          Sets the property file header.
 void setMandatory(boolean mandatory)
          Sets the mandatory flag.
 void setProperties(java.util.Properties properties)
          Sets the table of all properties.
 void setPropertyResourceName(java.lang.String propertyResourceName)
          Sets the property file name.
 void setReadonly(boolean readonly)
          Sets the readonly flag.
 void setSaveExistingPropertiesOnly(boolean saveExistingPropertiesOnly)
          Sets the flag to save only properties that already exist in the property file.
 boolean setSetting(java.lang.String name, java.lang.Object value)
          Sets a setting.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

PropertyFileProvider

public PropertyFileProvider()
Default constructor.

Method Detail

clear

public void clear()
Clears all property settings.


toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

getPropertyResourceName

public java.lang.String getPropertyResourceName()
Gets the property file name.


setPropertyResourceName

public void setPropertyResourceName(java.lang.String propertyResourceName)
Sets the property file name.


getPropertyResourceUrl

public java.net.URL getPropertyResourceUrl()
Gets the URL of the property resource.

Returns:
The URL or null if it could not be determined

getFileHeader

public java.lang.String getFileHeader()
Gets the property file header.


setFileHeader

public void setFileHeader(java.lang.String fileHeader)
Sets the property file header.


getProperties

public java.util.Properties getProperties()
Gets the table of all properties.


setProperties

public void setProperties(java.util.Properties properties)
Sets the table of all properties.


isReadonly

public boolean isReadonly()
Gets the readonly flag.


setReadonly

public void setReadonly(boolean readonly)
Sets the readonly flag.


isMandatory

public boolean isMandatory()
Gets the mandatory flag.


setMandatory

public void setMandatory(boolean mandatory)
Sets the mandatory flag.


isSaveExistingPropertiesOnly

public boolean isSaveExistingPropertiesOnly()
Gets the flag to save only properties that already exist in the property file.


setSaveExistingPropertiesOnly

public void setSaveExistingPropertiesOnly(boolean saveExistingPropertiesOnly)
Sets the flag to save only properties that already exist in the property file.


getSetting

public java.lang.Object getSetting(java.lang.String name)
Gets a setting value.

Specified by:
getSetting in interface SettingProvider
Parameters:
name - Name of the setting
Returns:
The setting value or null if the setting does not exist

setSetting

public boolean setSetting(java.lang.String name,
                          java.lang.Object value)
Sets a setting. Note that you have to call saveSettings() in order to write the settings back to the property file.

Specified by:
setSetting in interface SettingProvider
Parameters:
name - Name of the setting
value - Value of the setting
Returns:
true If the provider was able to save the setting.
false If the provider does not feel responsible for this setting or cannot save the setting.

loadSettings

public boolean loadSettings()
Loads the settings. Forces the provider to (re-)load the settings.

Specified by:
loadSettings in interface SettingProvider
Returns:
true If the setting were successfully loaded. false If the settings could not be loaded.

saveSettings

public boolean saveSettings()
Saves the settings. Makes the provider to save the current setting values.
Note that some providers may save the setting values automatically if setSetting(java.lang.String, java.lang.Object) is called. In this case, this method will do nothing and should return true.

Specified by:
saveSettings in interface SettingProvider
Returns:
true If the setting were successfully saved or the provider is not save-capable. false If there was an error saving the properties.


Copyright © 2011. All Rights Reserved.