Package org.ametys.runtime.model
Class ElementDefinition<T>
- java.lang.Object
-
- org.ametys.runtime.model.AbstractModelItem
-
- org.ametys.runtime.model.ElementDefinition<T>
-
- Type Parameters:
T- Type of the element value
- All Implemented Interfaces:
Comparable<ModelItem>,ModelItem,Labelable,ModifiableLabelable
- Direct Known Subclasses:
AttributeDefinition,ServiceParameter,ViewParameter
public class ElementDefinition<T> extends AbstractModelItem
The definition of a single model item (parameter, attribute)
-
-
Field Summary
Fields Modifier and Type Field Description protected org.slf4j.Logger_loggerThe definition loggerstatic StringCONFIG_DEFAULT_VALUE_TYPEconfig type for default values-
Fields inherited from class org.ametys.runtime.model.AbstractModelItem
__serviceManager
-
Fields inherited from interface org.ametys.runtime.model.ModelItem
ITEM_PATH_SEPARATOR
-
-
Constructor Summary
Constructors Constructor Description ElementDefinition()Default constructor.ElementDefinition(String name, boolean isMultiple, ElementType<T> type)Constructor used to create simple models and itemsElementDefinition(ElementDefinition<T> definitionToCopy)Constructor by copying an existingElementDefinition.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected T_getDefaultValue(String defaultValueType, Object parsedDefaultValue)Retrieves the default value from the parsed one, according to the type of the default valueprotected List<Pair<String,Object>>_getParsedDefaultValues()Retrieves the parsed default valuesprotected Map<String,Object>_toJSON(DefinitionContext context)Converts the model item in a JSON mapStringgetCustomEnumerator()Retrieves the custom enumerator's class nameStringgetCustomValidator()Retrieves the custom validator's class name<X> XgetDefaultValue()Retrieves the default value, as an object corresponding to the definition's type and cardinality Retrievesnullif no default value is defined for this definitionEnumerator<T>getEnumerator()Retrieves the enumerator.ConfigurationgetEnumeratorConfiguration()Retrieves the custom enumerator's configurationElementType<T>getType()Retrieves the type.ValidatorgetValidator()Retrieves the validator.ConfigurationgetValidatorConfiguration()Retrieves the custom validator's configuraitonbooleanisMultiple()Test if the element is multiple.static ElementDefinitionof(String name, boolean isMultiple, String typeId, String availableTypesExtensionPoint)Creates anElementDefinitionvoidsetCustomEnumerator(String customEnumerator)Set the custom enumerator's class namevoidsetCustomValidator(String customValidator)Set the custom validator's class namevoidsetDefaultValue(T defaultValue)Set a default value to the definition The default value is single, classic default valuevoidsetEnumerator(Enumerator<T> enumerator)Set the enumerator.voidsetEnumeratorConfiguration(Configuration enumeratorConfiguration)Set the custom enumerator's configurationvoidsetMultiple(boolean isMultiple)Set the element multiple status.voidsetParsedDefaultValues(List<Pair<String,Object>> parsedDefaultValues)Set the parsed default values.voidsetType(ModelItemType type)Set the type.voidsetValidator(Validator validator)Set the validator.voidsetValidatorConfiguration(Configuration validatorConfiguration)Set the custom validator's configurationvoidtoSAX(ContentHandler contentHandler, DefinitionContext context)Generates SAX events for the model item-
Methods inherited from class org.ametys.runtime.model.AbstractModelItem
_shouldJSONBeEmpty, _widgetParameterToSAX, _widgetToSAX, addItemChecker, compareTo, equals, getDescription, getDisableConditions, getItemCheckers, getLabel, getModel, getName, getParent, getPath, getPluginName, getWidget, getWidgetParameters, hashCode, setDescription, setDisableConditions, setLabel, setModel, setName, setParent, setPluginName, setServiceManager, setWidget, setWidgetParameters, toJSON, toString
-
-
-
-
Field Detail
-
CONFIG_DEFAULT_VALUE_TYPE
public static final String CONFIG_DEFAULT_VALUE_TYPE
config type for default values- See Also:
- Constant Field Values
-
_logger
protected org.slf4j.Logger _logger
The definition logger
-
-
Constructor Detail
-
ElementDefinition
public ElementDefinition()
Default constructor.
-
ElementDefinition
public ElementDefinition(String name, boolean isMultiple, ElementType<T> type)
Constructor used to create simple models and items- Parameters:
name- the name of the definitionisMultiple- the element multiple statustype- the type of the definition
-
ElementDefinition
public ElementDefinition(ElementDefinition<T> definitionToCopy)
Constructor by copying an existingElementDefinition.- Parameters:
definitionToCopy- TheElementDefinitionto copy
-
-
Method Detail
-
getType
public ElementType<T> getType()
Description copied from interface:ModelItemRetrieves the type.- Returns:
- the type.
-
setType
public void setType(ModelItemType type)
Description copied from interface:ModelItemSet the type.- Parameters:
type- the type.
-
getEnumerator
public Enumerator<T> getEnumerator()
Retrieves the enumerator.- Returns:
- the enumerator or
nullif none is defined.
-
setEnumerator
public void setEnumerator(Enumerator<T> enumerator)
Set the enumerator.- Parameters:
enumerator- the enumerator.
-
getCustomEnumerator
public String getCustomEnumerator()
Retrieves the custom enumerator's class name- Returns:
- the custom enumerator's class name
-
setCustomEnumerator
public void setCustomEnumerator(String customEnumerator)
Set the custom enumerator's class name- Parameters:
customEnumerator- the custom enumerator's class name
-
getEnumeratorConfiguration
public Configuration getEnumeratorConfiguration()
Retrieves the custom enumerator's configuration- Returns:
- the custom enumerator's configuration
-
setEnumeratorConfiguration
public void setEnumeratorConfiguration(Configuration enumeratorConfiguration)
Set the custom enumerator's configuration- Parameters:
enumeratorConfiguration- the custom enumerator's configuration
-
getValidator
public Validator getValidator()
Retrieves the validator.- Returns:
- the validator or
nullif none is defined.
-
setValidator
public void setValidator(Validator validator)
Set the validator.- Parameters:
validator- the validator.
-
getCustomValidator
public String getCustomValidator()
Retrieves the custom validator's class name- Returns:
- the custom validator's class name
-
setCustomValidator
public void setCustomValidator(String customValidator)
Set the custom validator's class name- Parameters:
customValidator- the custom validator's class name
-
getValidatorConfiguration
public Configuration getValidatorConfiguration()
Retrieves the custom validator's configuraiton- Returns:
- the custom validator's configuration
-
setValidatorConfiguration
public void setValidatorConfiguration(Configuration validatorConfiguration)
Set the custom validator's configuration- Parameters:
validatorConfiguration- the custom validator's configuration
-
getDefaultValue
public <X> X getDefaultValue()
Retrieves the default value, as an object corresponding to the definition's type and cardinality Retrievesnullif no default value is defined for this definition- Type Parameters:
X- The type of the default value- Returns:
- the default value.
-
_getDefaultValue
protected T _getDefaultValue(String defaultValueType, Object parsedDefaultValue)
Retrieves the default value from the parsed one, according to the type of the default value- Parameters:
parsedDefaultValue- the parsed default value (can be anI18nizableText, a config parameter name, ... depending on the default value type)defaultValueType- the type of the default value- Returns:
- the default value.
-
setParsedDefaultValues
public void setParsedDefaultValues(List<Pair<String,Object>> parsedDefaultValues)
Set the parsed default values. If the definition is not multiple, the list should contain only one element A parsed default value is described by its type and an object depending on the type- Parameters:
parsedDefaultValues- the parsed default values.
-
setDefaultValue
public void setDefaultValue(T defaultValue)
Set a default value to the definition The default value is single, classic default value- Parameters:
defaultValue- the default value to set
-
_getParsedDefaultValues
protected List<Pair<String,Object>> _getParsedDefaultValues()
Retrieves the parsed default values- Returns:
- the parsed default values
-
isMultiple
public boolean isMultiple()
Test if the element is multiple.- Returns:
trueif the metadata is multiple.
-
setMultiple
public void setMultiple(boolean isMultiple)
Set the element multiple status.- Parameters:
isMultiple- the element multiple status.
-
_toJSON
protected Map<String,Object> _toJSON(DefinitionContext context) throws ProcessingException
Description copied from class:AbstractModelItemConverts the model item in a JSON map- Overrides:
_toJSONin classAbstractModelItem- Parameters:
context- the context of the definition- Returns:
- The model item as a JSON map
- Throws:
ProcessingException- If an error occurs when converting the model item
-
toSAX
public void toSAX(ContentHandler contentHandler, DefinitionContext context) throws SAXException
Description copied from interface:ModelItemGenerates SAX events for the model item- Specified by:
toSAXin interfaceModelItem- Overrides:
toSAXin classAbstractModelItem- Parameters:
contentHandler- theContentHandlerthat will receive the SAX eventscontext- the context of the definition- Throws:
SAXException- if an error occurs during the SAX events generation
-
of
public static ElementDefinition of(String name, boolean isMultiple, String typeId, String availableTypesExtensionPoint) throws UnknownTypeException, BadItemTypeException, ServiceException
Creates anElementDefinition- Parameters:
name- the definition's nameisMultiple- the definition's cardinalitytypeId- the definition's type identifieravailableTypesExtensionPoint- the role of the extension point containing all available types for thisElementDefinition- Returns:
- the created
ElementDefinition - Throws:
UnknownTypeException- if the given type identifier is not available in the extension pointBadItemTypeException- if the given type identifier can not be used for anElementDefinitionServiceException- if an error occurs while getting the extension point of available types
-
-