Package org.ametys.core.model.type
Class AbstractElementType<T>
- java.lang.Object
-
- org.ametys.runtime.plugin.component.AbstractLogEnabled
-
- org.ametys.core.model.type.AbstractModelItemType
-
- org.ametys.core.model.type.AbstractElementType<T>
-
- Type Parameters:
T- Type of the element value
- All Implemented Interfaces:
ElementType<T>,ModelItemType,LogEnabled,PluginAware,Component,Serviceable
- Direct Known Subclasses:
AbstractBinaryElementType,AbstractBooleanElementType,AbstractContentElementType,AbstractDateElementType,AbstractDateTimeElementType,AbstractDoubleElementType,AbstractFileElementType,AbstractGeocodeElementType,AbstractLongElementType,AbstractMultilingualStringElementType,AbstractReferenceElementType,AbstractRichTextElementType,AbstractStringElementType,AbstractUserElementType
public abstract class AbstractElementType<T> extends AbstractModelItemType implements ElementType<T>, Component, Serviceable
Abstract class for element types
-
-
Field Summary
Fields Modifier and Type Field Description protected JSONUtils_jsonUtilsThe JSON conversion utilities.private Class<T>_typeprivate Class<T[]>_typeArray
-
Constructor Summary
Constructors Constructor Description AbstractElementType()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected Stream<Triple<DataChangeType,DataChangeTypeDetail,String>>_compareMultipleValues(T[] value1, T[] value2)Compares the given multiple values and retrieves the changes as a stream ofTriples.protected Stream<Triple<DataChangeType,DataChangeTypeDetail,String>>_compareSingleValues(T value1, T value2)Compares the given single values and retrieves the changes as a stream ofTriples.private boolean_containsAll(T[] list1, T[] list2)Check if list1 contains all elements of list2 [A, B, C], [A, A, B, C] will return false [A, A, B, C], [A, A, A, B, C] will return false [A, A, B, C], [A, B, C] will return true [A, B, C, D], [A, B, C] will return trueprotected AttributesImpl_getValueAttributes(Object value, DataContext context, boolean isEdition)Retrieves the attributes of the single value to SAXprotected boolean_isValueFromXMLMultiple(Element element)Checks if the value in the given node is marked as multipleprivate T[]_removeAllOnce(T[] list1, T[] list2)Remove once all elements from list2 in list1 [A, A, B, C], [A, B] will result [A, C]protected T_singleValueFromXML(Element element, Optional<Object> additionalData)Retrieves a single typed value from the given DOM nodeprotected Object_singleValueToJSON(T value, DataContext context)Convert the single value into a JSON objectprotected void_singleValueToSAX(ContentHandler contentHandler, String tagName, T value, Optional<ViewItem> viewItem, DataContext context, AttributesImpl attributes)Generates SAX events for the given single valueprotected boolean_useJSONForEdition()Determine if the JSON format has to be used in edition mode for this element typeprotected void_valueToSAX(ContentHandler contentHandler, String tagName, Object value, Optional<ViewItem> viewItem, DataContext context, boolean isEdition)Generates SAX events for the given valueprotected void_valueToSAX(ContentHandler contentHandler, String tagName, Object value, Optional<ViewItem> viewItem, DataContext context, AttributesImpl attributes)Generates SAX events for the given valueprotected void_valueToSAXForEdition(ContentHandler contentHandler, String tagName, Object value, Optional<ViewItem> viewItem, DataContext context, AttributesImpl attributes)Generates SAX events for the given value in edition mode.TcastValue(Object value)Cast the given value to an object of the corresponding type.
It may be an untyped String value, or another Object, depending of what the type is actually compatible with.Stream<Triple<DataChangeType,DataChangeTypeDetail,String>>compareValues(Object value1, Object value2)Compares the given values and retrieves the changes as a stream ofTriples.TconvertValue(Object value)Try to convert the given value.Class<T>getManagedClass()Get the class managed by the implementationClass<T[]>getManagedClassArray()Get the class representing an array of managed class by the implementationbooleanisCompatible(Object value)Checks if the value is compatible with the element typeTparseConfiguration(Configuration configuration)Parses the given configuration to get the typed valuevoidservice(ServiceManager manager)StringtoString(T value)Cast a typed value to a StringObjectvalueFromXML(Element parent, String name, Optional<Object> additionalData)Parses the given DOM node to get the typed valueObjectvalueToJSONForClient(Object value, DataContext context)Convert the value into a JSON object to use client sidevoidvalueToSAX(ContentHandler contentHandler, String tagName, Object value, Optional<ViewItem> viewItem, DataContext context)Generates SAX events for the given valuevoidvalueToSAXForEdition(ContentHandler contentHandler, String tagName, Object value, Optional<ViewItem> viewItem, DataContext context)Generates SAX events for the given value in edition mode.-
Methods inherited from class org.ametys.core.model.type.AbstractModelItemType
_getContextAttributes, getId, setPluginInfo
-
Methods inherited from class org.ametys.runtime.plugin.component.AbstractLogEnabled
getLogger, setLogger
-
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.type.ElementType
fromJSONForClient, isSimple
-
Methods inherited from interface org.ametys.runtime.model.type.ModelItemType
getId, valueToSAX
-
Methods inherited from interface org.ametys.runtime.plugin.component.PluginAware
setPluginInfo
-
-
-
-
Field Detail
-
_jsonUtils
protected JSONUtils _jsonUtils
The JSON conversion utilities.
-
_typeArray
private Class<T[]> _typeArray
-
-
Constructor Detail
-
AbstractElementType
public AbstractElementType()
-
-
Method Detail
-
service
public void service(ServiceManager manager) throws ServiceException
- Specified by:
servicein interfaceServiceable- Throws:
ServiceException
-
toString
public String toString(T value)
Description copied from interface:ElementTypeCast a typed value to a String- Specified by:
toStringin interfaceElementType<T>- Parameters:
value- the value to cast- Returns:
- the String representation of the value
-
valueToJSONForClient
public Object valueToJSONForClient(Object value, DataContext context)
Description copied from interface:ElementTypeConvert the value into a JSON object to use client side- Specified by:
valueToJSONForClientin interfaceElementType<T>- Parameters:
value- the value to convertcontext- The context of the data to convert- Returns:
- The value as JSON
-
_singleValueToJSON
protected Object _singleValueToJSON(T value, DataContext context)
Convert the single value into a JSON object- Parameters:
value- the value to convertcontext- The context of the data to convert- Returns:
- The value as JSON
-
parseConfiguration
public T parseConfiguration(Configuration configuration) throws ConfigurationException
Description copied from interface:ElementTypeParses the given configuration to get the typed value- Specified by:
parseConfigurationin interfaceElementType<T>- Parameters:
configuration- the configuration to parse- Returns:
- The typed value in the configuration
- Throws:
ConfigurationException- if an error occurs while parsing the configuration
-
valueFromXML
public Object valueFromXML(Element parent, String name, Optional<Object> additionalData) throws TransformerException, IOException
Description copied from interface:ElementTypeParses the given DOM node to get the typed value- Specified by:
valueFromXMLin interfaceElementType<T>- Parameters:
parent- the DOM element containing the valuename- the name of the item to readadditionalData- additional data needed to get the typed value- Returns:
- the value
- Throws:
TransformerException- if an error occurs while parsing the DOM nodeIOException- if an error occurs while parsing a value using the I/O API
-
_isValueFromXMLMultiple
protected boolean _isValueFromXMLMultiple(Element element) throws TransformerException
Checks if the value in the given node is marked as multiple- Parameters:
element- the DOM element- Returns:
trueif the value is marked as multiple,falseotherwise- Throws:
TransformerException- if an error occurs while parsing the DOM node
-
_singleValueFromXML
protected T _singleValueFromXML(Element element, Optional<Object> additionalData) throws TransformerException, IOException
Retrieves a single typed value from the given DOM node- Parameters:
element- the DOM element containing the single valueadditionalData- additional data needed to get the typed value- Returns:
- the value
- Throws:
TransformerException- if an error occurs while parsing the DOM nodeIOException- if an error occurs while parsing a value using the I/O API
-
valueToSAXForEdition
public void valueToSAXForEdition(ContentHandler contentHandler, String tagName, Object value, Optional<ViewItem> viewItem, DataContext context) throws SAXException, IOException
Description copied from interface:ModelItemTypeGenerates SAX events for the given value in edition mode. This method exist for legacy purposes because some types have to be saxed as JSON- Specified by:
valueToSAXForEditionin interfaceModelItemType- Parameters:
contentHandler- theContentHandlerthat will receive the SAX eventstagName- the tag name of the SAX event to generate.value- the value to SAXviewItem- The optional view item corresponding item that is currently saxed. This view item gives context for the SAX event that will be generated here.context- The context of the data to SAX- Throws:
SAXException- if an error occurs during the SAX events generationIOException- if an error occurs while reading a value using the I/O API
-
valueToSAX
public void valueToSAX(ContentHandler contentHandler, String tagName, Object value, Optional<ViewItem> viewItem, DataContext context) throws SAXException, IOException
Description copied from interface:ModelItemTypeGenerates SAX events for the given value- Specified by:
valueToSAXin interfaceModelItemType- Parameters:
contentHandler- theContentHandlerthat will receive the SAX eventstagName- the tag name of the SAX event to generate.value- the value to SAXviewItem- The optional view item corresponding item that is currently saxed. This view item gives context for the SAX event that will be generated here.context- The context of the data to SAX- Throws:
SAXException- if an error occurs during the SAX events generationIOException- if an error occurs while reading a value using the I/O API
-
_valueToSAX
protected void _valueToSAX(ContentHandler contentHandler, String tagName, Object value, Optional<ViewItem> viewItem, DataContext context, boolean isEdition) throws SAXException, IOException
Generates SAX events for the given value- Parameters:
contentHandler- theContentHandlerthat will receive the SAX eventstagName- the tag name of the SAX event to generate.value- the value to SAXviewItem- The optional view item corresponding item that is currently saxed. This view item gives context for the SAX event that will be generated here.context- The context of the data to SAXisEdition-trueif SAX events are generated in edition mode,falseotherwise- Throws:
SAXException- if an error occurs during the SAX events generationIOException- if an error occurs while reading a value using the I/O API
-
_valueToSAXForEdition
protected void _valueToSAXForEdition(ContentHandler contentHandler, String tagName, Object value, Optional<ViewItem> viewItem, DataContext context, AttributesImpl attributes) throws SAXException, IOException
Generates SAX events for the given value in edition mode. This default implementation generates SAX event using thevalueToJSONForClient(Object, DataContext)method- Parameters:
contentHandler- theContentHandlerthat will receive the SAX eventstagName- the tag name of the SAX event to generate.value- the value to SAXviewItem- The optional view item corresponding item that is currently saxed. This view item gives context for the SAX event that will be generated here.context- The context of the data to SAXattributes- the attributes for the SAX events to generate- Throws:
SAXException- if an error occurs during the SAX events generationIOException- if an error occurs while reading a value using the I/O API
-
_valueToSAX
protected void _valueToSAX(ContentHandler contentHandler, String tagName, Object value, Optional<ViewItem> viewItem, DataContext context, AttributesImpl attributes) throws SAXException, IOException
Generates SAX events for the given value- Parameters:
contentHandler- theContentHandlerthat will receive the SAX eventstagName- the tag name of the SAX event to generate.value- the value to SAXviewItem- The optional view item corresponding item that is currently saxed. This view item gives context for the SAX event that will be generated here.context- The context of the data to SAXattributes- the attributes for the SAX events to generate- Throws:
SAXException- if an error occurs during the SAX events generationIOException- if an error occurs while reading a value using the I/O API
-
_singleValueToSAX
protected void _singleValueToSAX(ContentHandler contentHandler, String tagName, T value, Optional<ViewItem> viewItem, DataContext context, AttributesImpl attributes) throws SAXException, IOException
Generates SAX events for the given single value- Parameters:
contentHandler- theContentHandlerthat will receive the SAX eventstagName- the tag name of the SAX event to generate.value- the single value to SAXattributes- the attributes for the SAX event to generateviewItem- The optional view item corresponding item that is currently saxed. This view item gives context for the SAX event that will be generated here.context- The context of the data to SAX- Throws:
SAXException- if an error occurs during the SAX events generationIOException- if an error occurs while reading a value using the I/O API
-
_getValueAttributes
protected AttributesImpl _getValueAttributes(Object value, DataContext context, boolean isEdition)
Retrieves the attributes of the single value to SAX- Parameters:
value- the single valuecontext- The context of the data to SAXisEdition-trueif SAX events are generated in edition mode,falseotherwise- Returns:
- the attributes
-
_useJSONForEdition
protected boolean _useJSONForEdition()
Determine if the JSON format has to be used in edition mode for this element type- Returns:
trueif the JSON format has to be used,falseotherwise
-
compareValues
public Stream<Triple<DataChangeType,DataChangeTypeDetail,String>> compareValues(Object value1, Object value2) throws IOException
Description copied from interface:ElementTypeCompares the given values and retrieves the changes as a stream ofTriples. ATriplecontains:- the general type of the change (added, modified or removed) as a
DataChangeType, - some details about this change if possible (after or before for a date, more or less for a number, ...) as a
DataChangeTypeDetail - The data concerned by this change if not the element itself (or an empty String)
- Specified by:
compareValuesin interfaceElementType<T>- Parameters:
value1- the 1st valuevalue2- the 2nd value- Returns:
- the changes between the two given values as a stream of
Triple. Retrieves an empty stream if there is no change - Throws:
IOException- if an error occurs while comparing values using the I/O API
- the general type of the change (added, modified or removed) as a
-
_compareMultipleValues
protected Stream<Triple<DataChangeType,DataChangeTypeDetail,String>> _compareMultipleValues(T[] value1, T[] value2) throws IOException
Compares the given multiple values and retrieves the changes as a stream ofTriples. TheTriples contains:- the general type of the change (added, modified or removed) as a
DataChangeType, - some details about this change if possible (after or before for a date, more or less for a number, ...) as a
DataChangeTypeDetail - The data concerned by this change if not the element itself (or an empty String)
- Parameters:
value1- the 1st multiple valuevalue2- the 2nd multiple value- Returns:
- the changes between the two given multiple values as a stream of
Triple. Retrieves an empty stream if there is no change - Throws:
IOException- if an error occurs while comparing values using the I/O API
- the general type of the change (added, modified or removed) as a
-
_compareSingleValues
protected Stream<Triple<DataChangeType,DataChangeTypeDetail,String>> _compareSingleValues(T value1, T value2) throws IOException
Compares the given single values and retrieves the changes as a stream ofTriples. TheTriplecontains:- the general type of the change (added, modified or removed) as a
DataChangeType, - some details about this change if possible (after or before for a date, more or less for a number, ...) as a
DataChangeTypeDetail - The data concerned by this change if not the element itself (or an empty String)
- Parameters:
value1- the 1st single valuevalue2- the 2nd single value- Returns:
- the changes between the two given single values as a stream of
Triple. Retrieves an empty stream if there is no change - Throws:
IOException- if an error occurs while comparing values using the I/O API
- the general type of the change (added, modified or removed) as a
-
_removeAllOnce
private T[] _removeAllOnce(T[] list1, T[] list2)
Remove once all elements from list2 in list1 [A, A, B, C], [A, B] will result [A, C]- Parameters:
list1- origin listlist2- list of objects to remove- Returns:
- a new list with removed objects
-
_containsAll
private boolean _containsAll(T[] list1, T[] list2)
Check if list1 contains all elements of list2 [A, B, C], [A, A, B, C] will return false [A, A, B, C], [A, A, A, B, C] will return false [A, A, B, C], [A, B, C] will return true [A, B, C, D], [A, B, C] will return true- Parameters:
list1- complete listlist2- elements to check- Returns:
- true if all elements in list2 are once in list1
-
isCompatible
public boolean isCompatible(Object value)
Description copied from interface:ElementTypeChecks if the value is compatible with the element type- Specified by:
isCompatiblein interfaceElementType<T>- Parameters:
value- the value to check- Returns:
trueif the value matches the current type,falseotherwise
-
castValue
public T castValue(Object value) throws BadItemTypeException
Description copied from interface:ElementTypeCast the given value to an object of the corresponding type.
It may be an untyped String value, or another Object, depending of what the type is actually compatible with.- Specified by:
castValuein interfaceElementType<T>- Parameters:
value- the value to cast- Returns:
- An object of the parameterized type representing the given value. Returns null if value cannot be cast
- Throws:
BadItemTypeException- if the String value can't be cast to the type
-
convertValue
public T convertValue(Object value)
Try to convert the given value.- Parameters:
value- the value to convert- Returns:
- the converted value or null if it's not possible.
-
getManagedClass
public Class<T> getManagedClass()
Description copied from interface:ElementTypeGet the class managed by the implementation- Specified by:
getManagedClassin interfaceElementType<T>- Returns:
- The class managed (T.class)
-
getManagedClassArray
public Class<T[]> getManagedClassArray()
Description copied from interface:ElementTypeGet the class representing an array of managed class by the implementation- Specified by:
getManagedClassArrayin interfaceElementType<T>- Returns:
- The class managed (T[].class)
-
-