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

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

public class FallbackConfigurationBackend
extends java.lang.Object
implements ConfigurationBackend

A ConfigurationBackend that supports fallback mechanisms.

The FallbackConfigurationBackend distguishes between the #primaries and their fallbacks. The first are an arbitrary ConfigurationBackend and the latter is a Map the defines fallbacks for the ISettings through <name,fallbackName> pairs.
Thus if a ISetting is to be retrieved and not found in the #primaries the fallbacks will be queried and if there's such a fallback ISetting it will be retrieved from the #primaries instead of the requested one.
Note that the fallback retrieval is done recursively and will resolve indirect/mutiple fallbacks, too!

Author:
Michael "kULO" Kulovits

Field Summary
protected  java.util.Map<java.lang.String,java.lang.String> fallbacks
           
protected  ConfigurationBackend primarySettings
           
 
Constructor Summary
FallbackConfigurationBackend(ConfigurationBackend primarySettings, java.util.Map<java.lang.String,java.lang.String> fallbacks)
           
 
Method Summary
 ISetting get(java.lang.String name)
          Retrieves the ISetting with the passed name.
 java.util.List<ISetting> getSettings()
          Adds all #primaries as well as all fallbacks for which there's no primary one.
 boolean isPrimarySetting(java.lang.String name)
           
 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

primarySettings

protected ConfigurationBackend primarySettings

fallbacks

protected java.util.Map<java.lang.String,java.lang.String> fallbacks
Constructor Detail

FallbackConfigurationBackend

public FallbackConfigurationBackend(ConfigurationBackend primarySettings,
                                    java.util.Map<java.lang.String,java.lang.String> fallbacks)
Parameters:
primaries - - the primary ISettings
fallbacks - - the mapping of primary to fallback primaries
Method Detail

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()
Adds all #primaries as well as all fallbacks for which there's no primary one.

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

isPrimarySetting

public boolean isPrimarySetting(java.lang.String name)
Parameters:
name -
Returns:


Copyright © 2010 emarsys AG. All Rights Reserved.