|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.emarsys.ecommon.prefs.config.declaration.GenericConfigurationDeclaration
com.emarsys.ecommon.prefs.config.declaration.ClassConfigurationDeclaration
public class ClassConfigurationDeclaration
A ClassConfigurationDeclaration
represents a
ConfigurationDeclaration
that is specified through
public static final String
fields of a Class
.
Thus it forms some kind of an in-code configuration declaration.
A ClassConfigurationDeclaration
can be created out of
any Object
whose Class
is annotated with
DeclareConfiguration
.
NOTE that every String
constant of such a
Class
that is not excluded through the String[]
Field
specified by DeclareConfiguration.excludedNames()
will be treated as a potential ISetting
name, default value
or fallback declaration.
Nested Class Summary |
---|
Nested classes/interfaces inherited from interface com.emarsys.ecommon.prefs.config.ConfigurationDeclaration |
---|
ConfigurationDeclaration.DeclarationType |
Field Summary | |
---|---|
protected DeclareConfiguration |
declarationAnnotation
|
protected java.lang.Class<?> |
declarationClass
|
protected java.lang.Object |
declarationInstance
|
protected java.util.List<java.lang.String> |
excludedNames
|
Fields inherited from class com.emarsys.ecommon.prefs.config.declaration.GenericConfigurationDeclaration |
---|
defaults, fallbacks, name, settingNames, type |
Constructor Summary | |
---|---|
ClassConfigurationDeclaration(java.lang.Object declarationInstance)
Creates a new ClassConfigurationDeclaration
out of the passed "declaration object". |
Method Summary | |
---|---|
static boolean |
declaresConfiguration(java.lang.Class<?> clazz)
Checks whether or not the passed Class declares a
Configuration by checking if an DeclareConfiguration
Annotation is present. |
protected ConfigurationDeclaration.DeclarationType |
getDeclarationType(java.lang.reflect.Field field)
Determines the DeclarationType of the passed
Field . |
protected java.util.List<java.lang.String> |
getExcludedNames()
|
protected java.lang.Object |
getFieldValue(java.lang.String fieldName)
Returns the value of the declarationInstance 's
Field with the passed fieldName. |
protected java.lang.String[] |
getSurrogateeNameAndValue(java.lang.reflect.Field surrogateField,
java.lang.String suffix)
Gets the name and value for the surrogate field (either a fallback setting or default value) passed. |
protected void |
parse()
Will set default values for all names specified as public static final String constants
in declarationClass whoose names are not
excluded through DeclareConfiguration.excludedNames()
and end with DeclareConfiguration.defaultSuffix() . |
protected void |
setSettingName(java.lang.String fieldName)
Adds the value of the Field of
declarationClass that's referenced by the
passed fieldName as a setting name. |
Methods inherited from class com.emarsys.ecommon.prefs.config.declaration.GenericConfigurationDeclaration |
---|
getDefaults, getFallbacks, getName, getSettingNames, getType, setDefaultValue, setFallback, setName, setType |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected final java.lang.Object declarationInstance
protected final java.lang.Class<?> declarationClass
protected final DeclareConfiguration declarationAnnotation
protected java.util.List<java.lang.String> excludedNames
Constructor Detail |
---|
public ClassConfigurationDeclaration(java.lang.Object declarationInstance) throws ConfigurationException
Creates a new ClassConfigurationDeclaration
out of the passed "declaration object".
The passed Object
's type has to be annotated
with DeclareConfiguration
.
See parse()
for details on how the declarations
parts are retrieved from the declaration instance's type.
declarationInstance
-
ConfigurationException
Method Detail |
---|
public static boolean declaresConfiguration(java.lang.Class<?> clazz)
Class
declares a
Configuration
by checking if an DeclareConfiguration
Annotation
is present.
clazz
-
true
if the passed Class
has a
DeclareConfiguration
annotation present,
false
otherwise.protected void parse() throws ConfigurationException
public static final String
constants
in declarationClass
whoose names are not
excluded through DeclareConfiguration.excludedNames()
and end with DeclareConfiguration.defaultSuffix()
.
The same will be provided for fallback ISetting
s that have
constants ending with DeclareConfiguration.fallbackSuffix()
defined.
ConfigurationException
- - on any parsing errorprotected java.lang.Object getFieldValue(java.lang.String fieldName) throws java.lang.IllegalArgumentException, java.lang.SecurityException, java.lang.IllegalAccessException, java.lang.NoSuchFieldException
declarationInstance
's
Field
with the passed fieldName.
fieldName
-
java.lang.IllegalArgumentException
java.lang.SecurityException
java.lang.IllegalAccessException
java.lang.NoSuchFieldException
protected void setSettingName(java.lang.String fieldName)
Field
of
declarationClass
that's referenced by the
passed fieldName as a setting name.
fieldName
- protected java.lang.String[] getSurrogateeNameAndValue(java.lang.reflect.Field surrogateField, java.lang.String suffix) throws java.lang.Exception
for instance:
if the Field
representing MY_SETTING_DEFAULT together with
declarationAnnotation
's specified suffix for default values,
see DeclareConfiguration.defaultSuffix()
, will be passed the
method will return {"MY_SETTING", valueOf(MY_SETTING_DEFAULT) };
the same is analogously valid for MY_SETTING_FALLBACK.
surrogateField
- suffix
- specifies the surrogates suffix which
distinguished it from the real setting.
java.lang.Exception
protected java.util.List<java.lang.String> getExcludedNames()
protected ConfigurationDeclaration.DeclarationType getDeclarationType(java.lang.reflect.Field field)
Determines the DeclarationType
of the passed
Field
.
The type will be DeclarationType#UNKNOWN
for
any field that is not a String
constant
(public static final String
)
It will be DeclarationType#EXCLUDED
for any
string constant whose name is in the excludedNames
or DeclarationType#DEFAULT_VALUE
if the string constant's name ends with the
default suffix
or DeclarationType#FALLBACK_NAME
if the
string constant's name ends with the
fallback suffix
.
Finally if the string constants field name is neither
excluded nor a default or fallback definition then it
will be considered as an ISetting
's
name
.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |