Package org.ametys.runtime.config
Class ConfigManager
- java.lang.Object
-
- org.ametys.runtime.config.ConfigManager
-
- All Implemented Interfaces:
Model
,ModelItemContainer
,Initializable
,Contextualizable
,Serviceable
public final class ConfigManager extends Object implements Model, Contextualizable, Serviceable, Initializable
This manager handle the parameters of the application that have to be stored by the plugins.
-
-
Field Summary
Fields Modifier and Type Field Description private static ConfigManager
__manager
private List<ModelItem>
_categorizedDefinitions
private ConfigParameterTypeExtensionPoint
_configParameterTypeEP
private Map<String,ConfigParameterDefinitionWrapper>
_configParameterWrappers
private Context
_context
private Map<String,ConfigParameterInfo>
_declaredParamCheckers
private Map<String,ConfigParameterInfo>
_declaredParams
private ThreadSafeComponentManager<Enumerator>
_enumeratorManager
private Map<String,ElementDefinition>
_flatDefinitions
private boolean
_isComplete
private boolean
_isInitialized
private org.slf4j.Logger
_logger
private ThreadSafeComponentManager<ItemChecker>
_parameterCheckerManager
private Map<String,ConfigParameterCheckerDescriptor>
_parameterCheckers
private ServiceManager
_serviceManager
private org.slf4j.Logger
_threadSafeComponentLogger
private Collection<String>
_usedParamIds
private ThreadSafeComponentManager<Validator>
_validatorManager
-
Constructor Summary
Constructors Modifier Constructor Description private
ConfigManager()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private void
_addParameterCheckersToModelItems()
private void
_categorizeParameters()
private void
_declareParameterCheckers(Map<String,ConfigParameterInfo> parameterCheckers)
private void
_declareParameters(Map<String,ConfigParameterInfo> parameters)
private Map<String,DefinitionAndValue>
_getDefinitionAndResolvedValues(Map<String,Object> values, Map<String,DefinitionAndValue> oldDefinitionAndValues)
private Map<String,DefinitionAndValue>
_getDefinitionAndValues(Map<String,Object> values)
private ModelItemGroup
_getModelItemGroup(List<ModelItem> items, I18nizableText itemGroupLabel)
private void
_parseParameterCheckers(ConfigParameterCheckerParser parameterCheckerParser)
private void
_parseParameters(ConfigParameterDefinitionParser definitionParser)
private Object
_resolveValue(ElementDefinition definition, Object value, Map<String,DefinitionAndValue> oldDefinitionAndValues)
private void
_saxConfigurationFile(String fileName, Map<String,DefinitionAndValue> definitionAndValues)
private void
_saxParameters(TransformerHandler handler, Map<String,Object> values)
private void
_validateParametersForReading()
void
addFeatureConfig(String featureId, Map<String,ConfigParameterInfo> parameters, Map<String,ConfigParameterInfo> parameterCheckers, Collection<String> parameterReferences)
Registers a new parameter or references a globalConfig parameter.void
addPluginConfig(String pluginName, Map<String,ConfigParameterInfo> parameters, Map<String,ConfigParameterInfo> parameterCheckers)
Registers new available parameters.void
contextualize(Context context)
void
dispose()
Dispose the manager before restarting itboolean
evaluateDisableConditions(DisableConditions disableConditions, Map<String,Object> values)
Recursively evaluate theDisableConditions
against the configuration valuesCollection<ElementDefinition>
getConfigurationParameters()
Retrieves all configuration parametersString
getFamilyId()
Retrieves the Family Id (for example the extension point) Each model Id have to be unique in it's family IdString
getId()
Retrieves the model id (an id must be unique in the familyModel.getFamilyId()
static ConfigManager
getInstance()
Returns the shared instance of the ConfigManagerModelItem
getModelItem(String itemPath)
Retrieves the model item at given pathCollection<ModelItem>
getModelItems()
Retrieves all the model items of this containerMap<String,DefinitionAndValue>
getOldDefinitionAndValues()
Retrieves old definition and values if the configuration is not well initializedConfigParameterCheckerDescriptor
getParameterChecker(String id)
Gets the parameter checker with its idView
getView(I18nUtils i18nUtils)
Retrieves the view of Configurationvoid
initialize()
boolean
isComplete()
Returns true if the model is initialized and all parameters are valuedboolean
isEmpty()
Returns true if the config file does not existvoid
parseAndValidate()
Ends the initialization of the config parameters, by checking against the already valued parameters.
If at least one parameter has no value, the application won't start.String
resolveValueForParameterChecker(String parameterName, Object value, Map<String,DefinitionAndValue> oldDefinitionAndValues)
Resolve the given value for the parameter checkMap<String,List<I18nizableText>>
save(Map<String,Object> values, String fileName)
Update the configuration file with the given values
Values are untyped (all are of type String) and might be null.void
service(ServiceManager manager)
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.ametys.runtime.model.ModelItemContainer
getChild, hasModelItem
-
-
-
-
Field Detail
-
__manager
private static ConfigManager __manager
-
_logger
private org.slf4j.Logger _logger
-
_threadSafeComponentLogger
private org.slf4j.Logger _threadSafeComponentLogger
-
_serviceManager
private ServiceManager _serviceManager
-
_validatorManager
private ThreadSafeComponentManager<Validator> _validatorManager
-
_enumeratorManager
private ThreadSafeComponentManager<Enumerator> _enumeratorManager
-
_parameterCheckerManager
private ThreadSafeComponentManager<ItemChecker> _parameterCheckerManager
-
_declaredParams
private Map<String,ConfigParameterInfo> _declaredParams
-
_declaredParamCheckers
private Map<String,ConfigParameterInfo> _declaredParamCheckers
-
_usedParamIds
private Collection<String> _usedParamIds
-
_configParameterWrappers
private Map<String,ConfigParameterDefinitionWrapper> _configParameterWrappers
-
_parameterCheckers
private Map<String,ConfigParameterCheckerDescriptor> _parameterCheckers
-
_categorizedDefinitions
private List<ModelItem> _categorizedDefinitions
-
_flatDefinitions
private Map<String,ElementDefinition> _flatDefinitions
-
_isInitialized
private boolean _isInitialized
-
_isComplete
private boolean _isComplete
-
_configParameterTypeEP
private ConfigParameterTypeExtensionPoint _configParameterTypeEP
-
-
Constructor Detail
-
ConfigManager
private ConfigManager()
-
-
Method Detail
-
getInstance
public static ConfigManager getInstance()
Returns the shared instance of the ConfigManager- Returns:
- the shared instance of the ConfigManager
-
contextualize
public void contextualize(Context context)
- Specified by:
contextualize
in interfaceContextualizable
-
service
public void service(ServiceManager manager) throws ServiceException
- Specified by:
service
in interfaceServiceable
- Throws:
ServiceException
-
initialize
public void initialize()
- Specified by:
initialize
in interfaceInitializable
-
addPluginConfig
public void addPluginConfig(String pluginName, Map<String,ConfigParameterInfo> parameters, Map<String,ConfigParameterInfo> parameterCheckers)
Registers new available parameters. The addFeatureConfig() method allows to select which ones are actually useful.- Parameters:
pluginName
- the name of the plugin defining the parametersparameters
- the configuration parameters definitionparameterCheckers
- the parameters checkers definition
-
addFeatureConfig
public void addFeatureConfig(String featureId, Map<String,ConfigParameterInfo> parameters, Map<String,ConfigParameterInfo> parameterCheckers, Collection<String> parameterReferences)
Registers a new parameter or references a globalConfig parameter.- Parameters:
featureId
- the id of the feature defining the parametersparameters
- the configuration parameters definitionparameterCheckers
- the parameters checkers definitionparameterReferences
- references to already defined parameters
-
_declareParameters
private void _declareParameters(Map<String,ConfigParameterInfo> parameters)
-
_declareParameterCheckers
private void _declareParameterCheckers(Map<String,ConfigParameterInfo> parameterCheckers)
-
parseAndValidate
public void parseAndValidate()
Ends the initialization of the config parameters, by checking against the already valued parameters.
If at least one parameter has no value, the application won't start.
-
_parseParameters
private void _parseParameters(ConfigParameterDefinitionParser definitionParser)
-
_parseParameterCheckers
private void _parseParameterCheckers(ConfigParameterCheckerParser parameterCheckerParser)
-
_categorizeParameters
private void _categorizeParameters()
-
_addParameterCheckersToModelItems
private void _addParameterCheckersToModelItems()
-
_getModelItemGroup
private ModelItemGroup _getModelItemGroup(List<ModelItem> items, I18nizableText itemGroupLabel)
-
_validateParametersForReading
private void _validateParametersForReading()
-
save
public Map<String,List<I18nizableText>> save(Map<String,Object> values, String fileName) throws Exception
Update the configuration file with the given values
Values are untyped (all are of type String) and might be null.- Parameters:
values
- A map (key, value).fileName
- the configuration file absolute path- Returns:
- errors The fields in error
- Throws:
Exception
- If an error occurred while saving values
-
getOldDefinitionAndValues
public Map<String,DefinitionAndValue> getOldDefinitionAndValues()
Retrieves old definition and values if the configuration is not well initialized- Returns:
- the old definition and values pairs
-
_getDefinitionAndResolvedValues
private Map<String,DefinitionAndValue> _getDefinitionAndResolvedValues(Map<String,Object> values, Map<String,DefinitionAndValue> oldDefinitionAndValues)
-
resolveValueForParameterChecker
public String resolveValueForParameterChecker(String parameterName, Object value, Map<String,DefinitionAndValue> oldDefinitionAndValues)
Resolve the given value for the parameter check- Parameters:
parameterName
- name of the parameter to resolvevalue
- the value to resolveoldDefinitionAndValues
- the old definition and values if the configuration is not initialized- Returns:
- the resolved value as a String
-
_resolveValue
private Object _resolveValue(ElementDefinition definition, Object value, Map<String,DefinitionAndValue> oldDefinitionAndValues)
-
_saxConfigurationFile
private void _saxConfigurationFile(String fileName, Map<String,DefinitionAndValue> definitionAndValues) throws TransformerFactoryConfigurationError, Exception
-
_saxParameters
private void _saxParameters(TransformerHandler handler, Map<String,Object> values) throws SAXException
- Throws:
SAXException
-
evaluateDisableConditions
public boolean evaluateDisableConditions(DisableConditions disableConditions, Map<String,Object> values)
Recursively evaluate theDisableConditions
against the configuration values- Parameters:
disableConditions
- the disable conditions to evaluatevalues
- the configuration values- Returns:
- true if the disable conditions are true, false otherwise
-
_getDefinitionAndValues
private Map<String,DefinitionAndValue> _getDefinitionAndValues(Map<String,Object> values)
-
getModelItem
public ModelItem getModelItem(String itemPath) throws UndefinedItemPathException
Description copied from interface:ModelItemContainer
Retrieves the model item at given path- Specified by:
getModelItem
in interfaceModelItemContainer
- Parameters:
itemPath
- the item path- Returns:
- the model item.
- Throws:
UndefinedItemPathException
- if there is no item defined at the given path
-
getConfigurationParameters
public Collection<ElementDefinition> getConfigurationParameters()
Retrieves all configuration parameters- Returns:
- all configuration parameters
-
getModelItems
public Collection<ModelItem> getModelItems()
Description copied from interface:ModelItemContainer
Retrieves all the model items of this container- Specified by:
getModelItems
in interfaceModelItemContainer
- Returns:
- the model items
-
getView
public View getView(I18nUtils i18nUtils)
Retrieves the view of Configuration- Parameters:
i18nUtils
- the i18nUtils to use categories's sorting- Returns:
- the configuration's view
-
getParameterChecker
public ConfigParameterCheckerDescriptor getParameterChecker(String id)
Gets the parameter checker with its id- Parameters:
id
- the id of the parameter checker to get- Returns:
- the associated parameter checker descriptor
-
isComplete
public boolean isComplete()
Returns true if the model is initialized and all parameters are valued- Returns:
- true if the model is initialized and all parameters are valued
-
isEmpty
public boolean isEmpty()
Returns true if the config file does not exist- Returns:
- true if the config file does not exist
-
dispose
public void dispose()
Dispose the manager before restarting it
-
getId
public String getId()
Description copied from interface:Model
Retrieves the model id (an id must be unique in the familyModel.getFamilyId()
-
getFamilyId
public String getFamilyId()
Description copied from interface:Model
Retrieves the Family Id (for example the extension point) Each model Id have to be unique in it's family Id- Specified by:
getFamilyId
in interfaceModel
- Returns:
- content point (for example "org.ametys.cms.contenttype.ContentTypeExtensionPoint" for a content)
-
-