|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.emarsys.ecommon.prefs.config.Configuration
public class Configuration
A Configuration
represents a generic storage
for settings
which hold the configuration
of your system, module or some other software artifact.
The whole Configuration
API is intended to provide
a lightweight and easy to (re)use configuration subsystem.
Some of the core principles and concepts are:
String
sISetting
s are just name-value pairs,
no XML or other hirarchical structuredeclaration
of the settings from their actual storageConfiguration
Properties
, Preferences
, DB or XML settings,
etc.) into a single coherent configuration subsystemConfiguration
Configuration
, but this will/might be tackled
in future versions)
A Configuration
consists of a ConfigurationBackend
,
that is used to retrieve the actual ISetting
s and is
associated with a ConfigurationDeclaration
that defines
its String
name and Configuration.Type
as well as possibly
declared default values or fallback settings
.
A Configuration
might represent an aggregation or chain
of ConfigurationBackend
s, see for instance
FallbackConfigurationBackend
or
DefaultsConfigurationBackend
, whilest being a
ConfigurationBackend
itself that is associated
with a Configuration.Type
as well as a name.
Furthermore a Configuration
serves as an
abstract factory for itself or ConfigurationBackend
s
respectively that is driven by its declared Configuration.Type
.
The Configuration
's factory methods will create its
backend
by aggregating or chaining several
ConfigurationBackend
s according to its corresponding
ConfigurationDeclaration
in order to support fallback
settings, default values, etc.; see
getInstance()
as well as Configuration.Type.createConfigBackend()
for details.
Nested Class Summary | |
---|---|
static class |
Configuration.Type
Defines different Configuration.Type s of concrete
Configuration instances. |
Field Summary | |
---|---|
protected NamedConfigurationBackend |
backend
|
protected ConfigurationDeclaration |
declaration
|
Constructor Summary | |
---|---|
protected |
Configuration(ConfigurationBackend backend,
ConfigurationDeclaration declaration)
|
Method Summary | |
---|---|
boolean |
equals(java.lang.Object that)
Uses the Configuration 's type and name but NOT
its actual ISetting s for comparison. |
ISetting |
get(java.lang.String name)
Retrieves the ISetting with the passed name. |
ConfigurationDeclaration |
getDeclaration()
|
static Configuration |
getInstance(ConfigurationBackend config,
ConfigurationDeclaration declaration)
Primary factory method for Configuration instances. |
static Configuration |
getInstanceDeclaredBy(ConfigurationBackend config,
java.lang.Object declarationObj)
A factory method for Configuration s that uses
the passed "declaration object" to get its
ConfigurationDeclaration . |
static Configuration |
getInstanceDeclaredBy(ConfigurationBackend config,
java.lang.Object declarationObj,
Configuration.Type type)
A factory method for Configuration s that uses
the passed "declaration object" to get its
ConfigurationDeclaration but overrides the
declaration objects Configuration.Type with the passed one. |
java.lang.String |
getName()
|
java.util.List<ISetting> |
getSettings()
Retrieves all ISetting s from this backend. |
Configuration.Type |
getType()
|
int |
hashCode()
|
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.String |
toString()
|
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
protected final NamedConfigurationBackend backend
protected final ConfigurationDeclaration declaration
Constructor Detail |
---|
protected Configuration(ConfigurationBackend backend, ConfigurationDeclaration declaration)
backend
- declaration
- Method Detail |
---|
public static Configuration getInstance(ConfigurationBackend config, ConfigurationDeclaration declaration) throws ConfigurationException
Primary factory method for Configuration
instances.
Creates a new Configuration
instance that
uses a backend
created
by the Configuration.Type
that's associated with the passed
declaration
.
config
- - the primary ConfigurationBackend
declaration
- - the ConfigurationDeclaration
Configuration
instance,
never null
ConfigurationException
- - on any errorConfiguration(ConfigurationBackend, ConfigurationDeclaration)
public static Configuration getInstanceDeclaredBy(ConfigurationBackend config, java.lang.Object declarationObj) throws ConfigurationException
A factory method for Configuration
s that uses
the passed "declaration object" to get its
ConfigurationDeclaration
.
This factory method will create Configuration
instances
that utilize the passed ConfigurationBackend
to lookup
ISetting
s and initializes itself according to the
ClassConfigurationDeclaration
that is held by the
passed configuration declarating Object
.
NOTE: the passed declaration object's type or supertype
have to be annotated with DeclareConfiguration
.
config
- - the ConfigurationBackend
declarationObj
- - the instance specifying a
ClassConfigurationDeclaration
having a
DeclareConfiguration
annotation
Configuration
instance,
never null
ConfigurationException
- - on any errorpublic static Configuration getInstanceDeclaredBy(ConfigurationBackend config, java.lang.Object declarationObj, Configuration.Type type) throws ConfigurationException
A factory method for Configuration
s that uses
the passed "declaration object" to get its
ConfigurationDeclaration
but overrides the
declaration objects Configuration.Type
with the passed one.
This factory method will create Configuration
instances
that utilize the passed ConfigurationBackend
to lookup
ISetting
s and initializes itself according to the
ClassConfigurationDeclaration
that is held by the
passed configuration declarating Object
.
NOTE: the passed declaration object's type or supertype
have to be annotated with DeclareConfiguration
.
config
- - the ConfigurationBackend
declarationObj
- - the instance specifying a
ClassConfigurationDeclaration
having a
DeclareConfiguration
annotationtype
- - the Configuration.Type
to use instead of the
one specified by the DeclareConfiguration
annotation
of declarationObj
Configuration
instance,
never null
ConfigurationException
- - on any errorpublic ConfigurationDeclaration getDeclaration()
public Configuration.Type getType()
public java.lang.String getName()
public ISetting get(java.lang.String name) throws java.lang.IllegalArgumentException
ConfigurationBackend
ISetting
with the passed name.
get
in interface ConfigurationBackend
ISetting
with the
passed name or null
if not present.
java.lang.IllegalArgumentException
- - if the passed name is
null
.com.emarsys.core.setting.backend.ConfigurationBackend#get(java.lang.String)
public java.util.List<ISetting> getSettings()
ConfigurationBackend
Retrieves all ISetting
s 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 ISetting
s 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.
getSettings
in interface ConfigurationBackend
List
of ISetting
s,
never null
.com.emarsys.core.setting.backend.ConfigurationBackend#getSettings()
public void set(ISetting setting) throws java.lang.IllegalArgumentException
ConfigurationBackend
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.
set
in interface ConfigurationBackend
java.lang.IllegalArgumentException
- - if the passed setting,
its name or value is null
.com.emarsys.core.setting.backend.ConfigurationBackend#set(ISetting)
public boolean equals(java.lang.Object that)
Configuration
's type and name but NOT
its actual ISetting
s for comparison. Thus note
that equal Configuration
's might not represent
the same settings.
equals
in class java.lang.Object
Object.equals(java.lang.Object)
public int hashCode()
hashCode
in class java.lang.Object
Object.hashCode()
public java.lang.String toString()
toString
in class java.lang.Object
Object.toString()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |