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

java.lang.Object
  extended by com.emarsys.ecommon.prefs.config.backend.DefaultsConfigurationBackend
All Implemented Interfaces:
ConfigurationBackend

public class DefaultsConfigurationBackend
extends java.lang.Object
implements ConfigurationBackend

A ConfigurationBackend that supports default values.

Author:
Michael "kULO" Kulovits

Field Summary
protected  ConfigurationBackend defaults
           
protected  ConfigurationBackend settings
           
 
Constructor Summary
DefaultsConfigurationBackend(ConfigurationBackend settings, ConfigurationBackend defaults)
          Creates a new DefaultsConfigurationBackend with the passed settings and its defaults.
 
Method Summary
static ConfigurationBackend cascade(ConfigurationBackend... backends)
          Creates a new DefaultsConfigurationBackend with the passed ConfigurationBackend recursively cascaded as the defaults of its predecessor.
static ConfigurationBackend cascade(java.util.List<ConfigurationBackend> backends)
          Creates a new DefaultsConfigurationBackend with the passed ConfigurationBackend recursively cascaded as the defaults of its predecessor.
 ISetting get(java.lang.String name)
          Looks for the specified ISetting in settings and if not present the value in defaults will be searched.
 java.util.List<ISetting> getSettings()
          Returns all settings included the defaults for missing ones in the wrapped backend.
 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

settings

protected ConfigurationBackend settings

defaults

protected ConfigurationBackend defaults
Constructor Detail

DefaultsConfigurationBackend

public DefaultsConfigurationBackend(ConfigurationBackend settings,
                                    ConfigurationBackend defaults)
                             throws java.lang.IllegalArgumentException
Creates a new DefaultsConfigurationBackend with the passed settings and its defaults.

Parameters:
settings -
defaults -
Throws:
java.lang.IllegalArgumentException
Method Detail

cascade

public static ConfigurationBackend cascade(ConfigurationBackend... backends)
Creates a new DefaultsConfigurationBackend with the passed ConfigurationBackend recursively cascaded as the defaults of its predecessor.

Parameters:
backends - - the ConfigurationBackends to be cascaded
Returns:
a new ConfigurationBackend that uses the passed backends for retrieving default values in their respective order.
See Also:
cascade(List)

cascade

public static ConfigurationBackend cascade(java.util.List<ConfigurationBackend> backends)
Creates a new DefaultsConfigurationBackend with the passed ConfigurationBackend recursively cascaded as the defaults of its predecessor.

Parameters:
backends - - the ConfigurationBackends to be cascaded
Returns:
a new ConfigurationBackend that uses the passed backends for retrieving default values in their respective order.
See Also:
cascade(List)

get

public ISetting get(java.lang.String name)
             throws java.lang.IllegalArgumentException
Looks for the specified ISetting in settings and if not present the value in defaults will be searched.

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()
Returns all settings included the defaults for missing ones in the wrapped backend.

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


Copyright © 2010 emarsys AG. All Rights Reserved.