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

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

public class SnapshotPropertiesConfigurationBackend
extends PropertiesConfigurationBackend

An immutable version of PropertiesConfigurationBackend.

This class is useful if you want to pass an immutable snapshot of a ConfigurationBackend to some client.

An ImmutableObjectException will be thrown on every method that would change the underlying Properties object.

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

Field Summary
 
Fields inherited from class com.emarsys.ecommon.prefs.config.backend.PropertiesConfigurationBackend
props
 
Fields inherited from class java.util.Properties
defaults
 
Constructor Summary
protected SnapshotPropertiesConfigurationBackend(java.util.Properties props)
           
 
Method Summary
 void clear()
           
static PropertiesConfigurationBackend copy(ConfigurationBackend backend)
          The same as snapshoot(ConfigurationBackend).
 void load(java.io.InputStream inStream)
           
 void loadFromXML(java.io.InputStream in)
           
 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 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)
           
static PropertiesConfigurationBackend snapshoot(ConfigurationBackend backend)
           Creates a new PropertiesConfigurationBackend instance that contains all ISettings from the passed backend.
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 com.emarsys.ecommon.prefs.config.backend.PropertiesConfigurationBackend
clone, contains, containsKey, containsValue, elements, entrySet, equals, get, get, getProperty, getProperty, getSettings, hashCode, isEmpty, keys, keySet, list, list, propertyNames, save, size, store, storeToXML, storeToXML, toString, 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
 

Constructor Detail

SnapshotPropertiesConfigurationBackend

protected SnapshotPropertiesConfigurationBackend(java.util.Properties props)
                                          throws java.lang.IllegalArgumentException
Parameters:
props -
Throws:
java.lang.IllegalArgumentException
Method Detail

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 SnapshotPropertiesConfigurationBackend(Properties).

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

copy

public static PropertiesConfigurationBackend copy(ConfigurationBackend backend)
The same as snapshoot(ConfigurationBackend). Has been redefined in order to override PropertiesConfigurationBackend.copy(ConfigurationBackend) and prevent misunderstandings.

Parameters:
backend -
Returns:
lways a newly created PropertiesConfigurationBackend instance, never null.

snapshoot

public static PropertiesConfigurationBackend snapshoot(ConfigurationBackend backend)

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.
Note that this 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.
See Also:
PropertiesConfigurationBackend.copy(ConfigurationBackend), wrap(Properties)

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
Overrides:
set in class PropertiesConfigurationBackend
Throws:
java.lang.IllegalArgumentException - - if the passed setting, its name or value is null.
See Also:
PropertiesConfigurationBackend.set(com.emarsys.ecommon.prefs.config.ISetting)

clear

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

load

public void load(java.io.InputStream inStream)
          throws java.io.IOException
Overrides:
load in class PropertiesConfigurationBackend
Throws:
java.io.IOException
See Also:
PropertiesConfigurationBackend.load(java.io.InputStream)

loadFromXML

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

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 PropertiesConfigurationBackend
See Also:
PropertiesConfigurationBackend.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 PropertiesConfigurationBackend
See Also:
PropertiesConfigurationBackend.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 PropertiesConfigurationBackend
See Also:
PropertiesConfigurationBackend.remove(java.lang.Object)

setProperty

public java.lang.Object setProperty(java.lang.String key,
                                    java.lang.String value)
Overrides:
setProperty in class PropertiesConfigurationBackend
See Also:
PropertiesConfigurationBackend.setProperty(java.lang.String, java.lang.String)


Copyright © 2010 emarsys AG. All Rights Reserved.