com.emarsys.ecommon.prefs.config.backend
Class PropertiesConfigurationBackend

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 com.emarsys.ecommon.prefs.config.backend.PropertiesConfigurationBackend
All Implemented Interfaces:
ConfigurationBackend, java.io.Serializable, java.lang.Cloneable, java.util.Map<java.lang.Object,java.lang.Object>
Direct Known Subclasses:
SnapshotPropertiesConfigurationBackend

public class PropertiesConfigurationBackend
extends java.util.Properties
implements ConfigurationBackend

A ConfigurationBackend with a Properties object as configuration store.

PropertiesConfigurationBackend is simply an adapter or a bridge from the Configuration API to plain old Properties whilest being both an instance of Properties and ConfigurationBackend.
Therefore a PropertiesConfigurationBackend for instance can be used to create a ConfigurationBackend that wraps System.getProperties().

NOTE: that the PropertiesConfigurationBackend does reflect changes in the original, wrapped Properties object used to initialize itself! But this is not the case if the ISettings of another ConfigurationBackend have been copied.

Because the ISettings are actually stored in a Properties instance a PropertiesConfigurationBackend is not capable of conserving anything but the bare name and value of the settings, thus there's for instance always an unspecified SettingMode for instances retrieved.
But said specific limitation can be "fixed" by wrapping the a PropertiesConfigurationBackend into a ModeSettingConfigurationBackend.

Author:
Michael "kULO" Kulovits
See Also:
Serialized Form

Field Summary
protected  java.util.Properties props
          The storage backend for the ISetting's names and values.
 
Fields inherited from class java.util.Properties
defaults
 
Constructor Summary
  PropertiesConfigurationBackend()
           Creates a new, empty PropertiesConfigurationBackend.
protected PropertiesConfigurationBackend(java.util.Properties props)
           Creates a new PropertiesConfigurationBackend that uses the passed properties as its storage, see props.
 
Method Summary
 void clear()
           
 java.lang.Object clone()
           
 boolean contains(java.lang.Object value)
           
 boolean containsKey(java.lang.Object key)
           
 boolean containsValue(java.lang.Object value)
           
static PropertiesConfigurationBackend copy(ConfigurationBackend backend)
           Creates a new PropertiesConfigurationBackend instance that contains all ISettings from the passed backend.
 java.util.Enumeration<java.lang.Object> elements()
           
 java.util.Set<java.util.Map.Entry<java.lang.Object,java.lang.Object>> entrySet()
           
 boolean equals(java.lang.Object o)
           
 java.lang.Object get(java.lang.Object key)
           
 ISetting get(java.lang.String name)
          Retrieves the ISetting with the passed name.
 java.lang.String getProperty(java.lang.String key)
           
 java.lang.String getProperty(java.lang.String key, java.lang.String defaultValue)
           
 java.util.List<ISetting> getSettings()
           Retrieves all ISettings from this backend.
 int hashCode()
           
 boolean isEmpty()
           
 java.util.Enumeration<java.lang.Object> keys()
           
 java.util.Set<java.lang.Object> keySet()
           
 void list(java.io.PrintStream out)
           
 void list(java.io.PrintWriter out)
           
 void load(java.io.InputStream inStream)
           
 void loadFromXML(java.io.InputStream in)
           
 java.util.Enumeration<?> propertyNames()
           
 java.lang.Object put(java.lang.Object key, java.lang.Object value)
           
 void putAll(java.util.Map<? extends java.lang.Object,? extends java.lang.Object> t)
           
 java.lang.Object remove(java.lang.Object key)
           
 void save(java.io.OutputStream out, java.lang.String comments)
          Deprecated.  
 void set(ISetting setting)
          Sets the passed setting which must not be null in this configuration backend, if a setting with the given name is already present it will be overridden.
 java.lang.Object setProperty(java.lang.String key, java.lang.String value)
           
 int size()
           
 void store(java.io.OutputStream out, java.lang.String comments)
           
 void storeToXML(java.io.OutputStream os, java.lang.String comment)
           
 void storeToXML(java.io.OutputStream os, java.lang.String comment, java.lang.String encoding)
           
 java.lang.String toString()
           
 java.util.Collection<java.lang.Object> values()
           
static PropertiesConfigurationBackend wrap(java.util.Properties props)
           Creates a new PropertiesConfigurationBackend that uses the passed Properties to store its ISetting's names and values.
 
Methods inherited from class java.util.Properties
load, store, stringPropertyNames
 
Methods inherited from class java.util.Hashtable
rehash
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

props

protected java.util.Properties props
The storage backend for the ISetting's names and values.

Constructor Detail

PropertiesConfigurationBackend

protected PropertiesConfigurationBackend(java.util.Properties props)
                                  throws java.lang.IllegalArgumentException

Creates a new PropertiesConfigurationBackend that uses the passed properties as its storage, see props.

Changes to the created instance will thus be reflected in the passed Properties.

Parameters:
props - - the Properties instance to be wrapped
Throws:
java.lang.IllegalArgumentException - - if the passed properties are null.

PropertiesConfigurationBackend

public PropertiesConfigurationBackend()

Creates a new, empty PropertiesConfigurationBackend.

Creates a new, empty Properties object which is used as the backing store the new PropertiesConfigurationBackend instance.

See Also:
PropertiesConfigurationBackend(Properties)
Method Detail

copy

public static PropertiesConfigurationBackend copy(ConfigurationBackend backend)
                                           throws java.lang.IllegalArgumentException

Creates a new PropertiesConfigurationBackend instance that contains all ISettings from the passed backend.

Note that this factory method retrieves the ISettings from the passed backend by calling ConfigurationBackend.getSettings() which will be copied into the newly created PropertiesConfigurationBackend and therefore changes will not be relfected in the original, passed ConfigurationBackend.
Note that the described semantic of copy(ConfigurationBackend) differs from the one in wrap(Properties).

Parameters:
backend - - the ConfigurationBackend whose ISettings should be copied; must not be null.
Returns:
always a newly created PropertiesConfigurationBackend instance, never null.
Throws:
java.lang.IllegalArgumentException
See Also:
PropertiesConfigurationBackend()

wrap

public static PropertiesConfigurationBackend wrap(java.util.Properties props)

Creates a new PropertiesConfigurationBackend that uses the passed Properties to store its ISetting's names and values.

The wrap factory method is just a more verbose wrapped to PropertiesConfigurationBackend(Properties). The returned ConfigurationBackend will therefore propagate changes to the passed Properties instance.

Parameters:
props - - the Properties to be wrapped into a ConfigurationBackend.
Returns:
always a newly created PropertiesConfigurationBackend instance, never null.
See Also:
PropertiesConfigurationBackend(Properties)

get

public ISetting get(java.lang.String name)
             throws java.lang.IllegalArgumentException
Description copied from interface: ConfigurationBackend
Retrieves the ISetting with the passed name.

Specified by:
get in interface ConfigurationBackend
Returns:
the ISetting with the passed name or null if not present.
Throws:
java.lang.IllegalArgumentException - - if the passed name is null.
See Also:
com.emarsys.core.setting.backend.ConfigurationBackend#get(java.lang.String)

set

public void set(ISetting setting)
         throws java.lang.IllegalArgumentException
Description copied from interface: ConfigurationBackend
Sets the passed setting which must not be null in this configuration backend, if a setting with the given name is already present it will be overridden. The next call to ConfigurationBackend.get(String) with the passed setting's name will return the passed setting.

Specified by:
set in interface ConfigurationBackend
Throws:
java.lang.IllegalArgumentException - - if the passed setting, its name or value is null.
See Also:
com.emarsys.core.setting.backend.ConfigurationBackend#set(ISetting)

getSettings

public java.util.List<ISetting> getSettings()
Description copied from interface: ConfigurationBackend

Retrieves all ISettings from this backend.

What exactly "all" means in the context of the concrete ConfigurationBackend is up to the implementation. For instance the List may or may not contain default values or fallbacked ISettings or might even return a cached list.

The only requirement for this method is to be logically in synch with ConfigurationBackend.get(String) and ConfigurationBackend.set(ISetting). Thus if a Setting is inserted/updated/deleted and nothing is changed in the meantime the next call to ConfigurationBackend.getSettings() has to reflect the changes made.

Specified by:
getSettings in interface ConfigurationBackend
Returns:
always a valid List of ISettings, never null.
See Also:
com.emarsys.core.setting.backend.ConfigurationBackend#getSettings()

clear

public void clear()
Specified by:
clear in interface java.util.Map<java.lang.Object,java.lang.Object>
Overrides:
clear in class java.util.Hashtable<java.lang.Object,java.lang.Object>
See Also:
Hashtable.clear()

clone

public java.lang.Object clone()
Overrides:
clone in class java.util.Hashtable<java.lang.Object,java.lang.Object>
Returns:
See Also:
Hashtable.clone()

contains

public boolean contains(java.lang.Object value)
Overrides:
contains in class java.util.Hashtable<java.lang.Object,java.lang.Object>
Parameters:
value -
Returns:
See Also:
Hashtable.contains(java.lang.Object)

containsKey

public boolean containsKey(java.lang.Object key)
Specified by:
containsKey in interface java.util.Map<java.lang.Object,java.lang.Object>
Overrides:
containsKey in class java.util.Hashtable<java.lang.Object,java.lang.Object>
Parameters:
key -
Returns:
See Also:
Hashtable.containsKey(java.lang.Object)

containsValue

public boolean containsValue(java.lang.Object value)
Specified by:
containsValue in interface java.util.Map<java.lang.Object,java.lang.Object>
Overrides:
containsValue in class java.util.Hashtable<java.lang.Object,java.lang.Object>
Parameters:
value -
Returns:
See Also:
Hashtable.containsValue(java.lang.Object)

elements

public java.util.Enumeration<java.lang.Object> elements()
Overrides:
elements in class java.util.Hashtable<java.lang.Object,java.lang.Object>
Returns:
See Also:
Hashtable.elements()

entrySet

public java.util.Set<java.util.Map.Entry<java.lang.Object,java.lang.Object>> entrySet()
Specified by:
entrySet in interface java.util.Map<java.lang.Object,java.lang.Object>
Overrides:
entrySet in class java.util.Hashtable<java.lang.Object,java.lang.Object>
Returns:
See Also:
Hashtable.entrySet()

equals

public boolean equals(java.lang.Object o)
Specified by:
equals in interface java.util.Map<java.lang.Object,java.lang.Object>
Overrides:
equals in class java.util.Hashtable<java.lang.Object,java.lang.Object>
Parameters:
o -
Returns:
See Also:
Hashtable.equals(java.lang.Object)

get

public java.lang.Object get(java.lang.Object key)
Specified by:
get in interface java.util.Map<java.lang.Object,java.lang.Object>
Overrides:
get in class java.util.Hashtable<java.lang.Object,java.lang.Object>
Parameters:
key -
Returns:
See Also:
Hashtable.get(java.lang.Object)

getProperty

public java.lang.String getProperty(java.lang.String key,
                                    java.lang.String defaultValue)
Overrides:
getProperty in class java.util.Properties
Parameters:
key -
defaultValue -
Returns:
See Also:
Properties.getProperty(java.lang.String, java.lang.String)

getProperty

public java.lang.String getProperty(java.lang.String key)
Overrides:
getProperty in class java.util.Properties
Parameters:
key -
Returns:
See Also:
Properties.getProperty(java.lang.String)

hashCode

public int hashCode()
Specified by:
hashCode in interface java.util.Map<java.lang.Object,java.lang.Object>
Overrides:
hashCode in class java.util.Hashtable<java.lang.Object,java.lang.Object>
Returns:
See Also:
Hashtable.hashCode()

isEmpty

public boolean isEmpty()
Specified by:
isEmpty in interface java.util.Map<java.lang.Object,java.lang.Object>
Overrides:
isEmpty in class java.util.Hashtable<java.lang.Object,java.lang.Object>
Returns:
See Also:
Hashtable.isEmpty()

keys

public java.util.Enumeration<java.lang.Object> keys()
Overrides:
keys in class java.util.Hashtable<java.lang.Object,java.lang.Object>
Returns:
See Also:
Hashtable.keys()

keySet

public java.util.Set<java.lang.Object> keySet()
Specified by:
keySet in interface java.util.Map<java.lang.Object,java.lang.Object>
Overrides:
keySet in class java.util.Hashtable<java.lang.Object,java.lang.Object>
Returns:
See Also:
Hashtable.keySet()

list

public void list(java.io.PrintStream out)
Overrides:
list in class java.util.Properties
Parameters:
out -
See Also:
Properties.list(java.io.PrintStream)

list

public void list(java.io.PrintWriter out)
Overrides:
list in class java.util.Properties
Parameters:
out -
See Also:
Properties.list(java.io.PrintWriter)

load

public void load(java.io.InputStream inStream)
          throws java.io.IOException
Overrides:
load in class java.util.Properties
Parameters:
inStream -
Throws:
java.io.IOException
See Also:
Properties.load(java.io.InputStream)

loadFromXML

public void loadFromXML(java.io.InputStream in)
                 throws java.io.IOException,
                        java.util.InvalidPropertiesFormatException
Overrides:
loadFromXML in class java.util.Properties
Parameters:
in -
Throws:
java.io.IOException
java.util.InvalidPropertiesFormatException
See Also:
Properties.loadFromXML(java.io.InputStream)

propertyNames

public java.util.Enumeration<?> propertyNames()
Overrides:
propertyNames in class java.util.Properties
Returns:
See Also:
Properties.propertyNames()

put

public java.lang.Object put(java.lang.Object key,
                            java.lang.Object value)
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 -
value -
Returns:
See Also:
Hashtable.put(java.lang.Object, java.lang.Object)

putAll

public void putAll(java.util.Map<? extends java.lang.Object,? extends java.lang.Object> t)
Specified by:
putAll in interface java.util.Map<java.lang.Object,java.lang.Object>
Overrides:
putAll in class java.util.Hashtable<java.lang.Object,java.lang.Object>
Parameters:
t -
See Also:
Hashtable.putAll(java.util.Map)

remove

public java.lang.Object remove(java.lang.Object key)
Specified by:
remove in interface java.util.Map<java.lang.Object,java.lang.Object>
Overrides:
remove in class java.util.Hashtable<java.lang.Object,java.lang.Object>
Parameters:
key -
Returns:
See Also:
Hashtable.remove(java.lang.Object)

save

public void save(java.io.OutputStream out,
                 java.lang.String comments)
Deprecated. 

Overrides:
save in class java.util.Properties
Parameters:
out -
comments -
See Also:
Properties.save(java.io.OutputStream, java.lang.String)

setProperty

public java.lang.Object setProperty(java.lang.String key,
                                    java.lang.String value)
Overrides:
setProperty in class java.util.Properties
Parameters:
key -
value -
Returns:
See Also:
Properties.setProperty(java.lang.String, java.lang.String)

size

public int size()
Specified by:
size in interface java.util.Map<java.lang.Object,java.lang.Object>
Overrides:
size in class java.util.Hashtable<java.lang.Object,java.lang.Object>
Returns:
See Also:
Hashtable.size()

store

public void store(java.io.OutputStream out,
                  java.lang.String comments)
           throws java.io.IOException
Overrides:
store in class java.util.Properties
Parameters:
out -
comments -
Throws:
java.io.IOException
See Also:
Properties.store(java.io.OutputStream, java.lang.String)

storeToXML

public void storeToXML(java.io.OutputStream os,
                       java.lang.String comment,
                       java.lang.String encoding)
                throws java.io.IOException
Overrides:
storeToXML in class java.util.Properties
Parameters:
os -
comment -
encoding -
Throws:
java.io.IOException
See Also:
Properties.storeToXML(java.io.OutputStream, java.lang.String, java.lang.String)

storeToXML

public void storeToXML(java.io.OutputStream os,
                       java.lang.String comment)
                throws java.io.IOException
Overrides:
storeToXML in class java.util.Properties
Parameters:
os -
comment -
Throws:
java.io.IOException
See Also:
Properties.storeToXML(java.io.OutputStream, java.lang.String)

toString

public java.lang.String toString()
Overrides:
toString in class java.util.Hashtable<java.lang.Object,java.lang.Object>
Returns:
See Also:
Hashtable.toString()

values

public java.util.Collection<java.lang.Object> values()
Specified by:
values in interface java.util.Map<java.lang.Object,java.lang.Object>
Overrides:
values in class java.util.Hashtable<java.lang.Object,java.lang.Object>
Returns:
See Also:
Hashtable.values()


Copyright © 2010 emarsys AG. All Rights Reserved.