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
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected Stream<Triple<DataChangeType,
DataChangeTypeDetail, String>> _compareMultipleValues
(T[] value1, T[] value2) Compares the given multiple values and retrieves the changes as a stream ofTriple
s.protected Stream<Triple<DataChangeType,
DataChangeTypeDetail, String>> _compareSingleValues
(T value1, T value2) Compares the given single values and retrieves the changes as a stream ofTriple
s.protected AttributesImpl
_getValueAttributes
(Object value, DataContext context, boolean isEdition) Retrieves the attributes of the single value to SAXprotected boolean
_isMultiple
(Object value) Checks if the given value is considered as multiple for this element typeprotected boolean
Checks if the given value is considered as single for this element typeprotected boolean
_isValueFromXMLMultiple
(Element element) Checks if the value in the given node is marked as multipleprotected 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 Object
_singleValueToJSONForEdition
(T value, DataContext context) Convert the single value into a JSON object to use in edition modeprotected void
_singleValueToSAX
(ContentHandler contentHandler, String tagName, T value, Optional<ViewItem> viewItem, DataContext context, AttributesImpl attributes) Generates SAX events for the given single valueprotected boolean
Determine if the JSON format has to be used in edition mode for this element typeprotected Object
_valueToJSON
(Object value, DataContext context, BiFunction<T, DataContext, Object> singleValueToJSONFunction) Convert the value into a JSON object using the given functionprotected 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.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.compareValues
(Object value1, Object value2) Compares the given values and retrieves the changes as a stream ofTriple
s.protected T
convertValue
(Object value) Try to convert the given value, that is not of the managed typeGet the class managed by the implementationGet the class representing an array of managed class by the implementationboolean
isCompatible
(Object value) Checks if the value is compatible with the element typeparseConfiguration
(Configuration configuration) Parses the given configuration to get the typed valuevoid
service
(ServiceManager manager) Cast a typed value to a StringvalueFromXML
(Element parent, String name, Optional<Object> additionalData) Parses the given DOM node to get the typed valuevalueToJSONForClient
(Object value, DataContext context) Convert the value into a JSON object to use client sidevalueToJSONForEdition
(Object value, DataContext context) Convert the value into a JSON object to use in edition modevoid
valueToSAX
(ContentHandler contentHandler, String tagName, Object value, Optional<ViewItem> viewItem, DataContext context) Generates SAX events for the given valuevoid
valueToSAXForEdition
(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 Details
-
_jsonUtils
The JSON conversion utilities.
-
-
Constructor Details
-
AbstractElementType
public AbstractElementType()
-
-
Method Details
-
service
- Specified by:
service
in interfaceServiceable
- Throws:
ServiceException
-
toString
Description copied from interface:ElementType
Cast a typed value to a String- Specified by:
toString
in interfaceElementType<T>
- Parameters:
value
- the value to cast- Returns:
- the String representation of the value
-
valueToJSONForClient
Description copied from interface:ElementType
Convert the value into a JSON object to use client side- Specified by:
valueToJSONForClient
in interfaceElementType<T>
- Parameters:
value
- the value to convertcontext
- The context of the data to convert. Can not be null.- Returns:
- The value as JSON
-
valueToJSONForEdition
Description copied from interface:ElementType
Convert the value into a JSON object to use in edition mode- Specified by:
valueToJSONForEdition
in interfaceElementType<T>
- Parameters:
value
- the value to convertcontext
- The context of the data to convert. Can not be null.- Returns:
- The value as JSON
-
_valueToJSON
protected Object _valueToJSON(Object value, DataContext context, BiFunction<T, DataContext, Object> singleValueToJSONFunction) Convert the value into a JSON object using the given function- Parameters:
value
- the value to convertcontext
- The context of the data to convertsingleValueToJSONFunction
- the function to apply to each single value to convert it into a JSON object- Returns:
- The value as JSON
-
_singleValueToJSON
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
-
_singleValueToJSONForEdition
Convert the single value into a JSON object to use in edition mode- Parameters:
value
- the value to convertcontext
- The context of the data to convert- Returns:
- The value as JSON
-
parseConfiguration
Description copied from interface:ElementType
Parses the given configuration to get the typed value- Specified by:
parseConfiguration
in 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
Description copied from interface:ElementType
Parses the given DOM node to get the typed value- Specified by:
valueFromXML
in 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
-
_isValueFromXMLMultiple
Checks if the value in the given node is marked as multiple- Parameters:
element
- the DOM element- Returns:
true
if the value is marked as multiple,false
otherwise- Throws:
TransformerException
- if an error occurs while parsing the DOM node
-
_singleValueFromXML
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
-
valueToSAXForEdition
public void valueToSAXForEdition(ContentHandler contentHandler, String tagName, Object value, Optional<ViewItem> viewItem, DataContext context) throws SAXException Description copied from interface:ModelItemType
Generates 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:
valueToSAXForEdition
in interfaceModelItemType
- Parameters:
contentHandler
- theContentHandler
that 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 generation
-
valueToSAX
public void valueToSAX(ContentHandler contentHandler, String tagName, Object value, Optional<ViewItem> viewItem, DataContext context) throws SAXException Description copied from interface:ModelItemType
Generates SAX events for the given value- Specified by:
valueToSAX
in interfaceModelItemType
- Parameters:
contentHandler
- theContentHandler
that 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 generation
-
_valueToSAX
protected void _valueToSAX(ContentHandler contentHandler, String tagName, Object value, Optional<ViewItem> viewItem, DataContext context, boolean isEdition) throws SAXException Generates SAX events for the given value- Parameters:
contentHandler
- theContentHandler
that 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
-true
if SAX events are generated in edition mode,false
otherwise- Throws:
SAXException
- if an error occurs during the SAX events generation
-
_valueToSAXForEdition
protected void _valueToSAXForEdition(ContentHandler contentHandler, String tagName, Object value, Optional<ViewItem> viewItem, DataContext context, AttributesImpl attributes) throws SAXException Generates SAX events for the given value in edition mode. This default implementation generates SAX event using thevalueToJSONForClient(Object, DataContext)
method- Parameters:
contentHandler
- theContentHandler
that 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 generation
-
_valueToSAX
protected void _valueToSAX(ContentHandler contentHandler, String tagName, Object value, Optional<ViewItem> viewItem, DataContext context, AttributesImpl attributes) throws SAXException Generates SAX events for the given value- Parameters:
contentHandler
- theContentHandler
that 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 generation
-
_singleValueToSAX
protected void _singleValueToSAX(ContentHandler contentHandler, String tagName, T value, Optional<ViewItem> viewItem, DataContext context, AttributesImpl attributes) throws SAXException Generates SAX events for the given single value- Parameters:
contentHandler
- theContentHandler
that 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 generation
-
_getValueAttributes
Retrieves the attributes of the single value to SAX- Parameters:
value
- the single valuecontext
- The context of the data to SAXisEdition
-true
if SAX events are generated in edition mode,false
otherwise- Returns:
- the attributes
-
_useJSONForEdition
Determine if the JSON format has to be used in edition mode for this element type- Returns:
true
if the JSON format has to be used,false
otherwise
-
compareValues
public Stream<Triple<DataChangeType,DataChangeTypeDetail, compareValuesString>> (Object value1, Object value2) Description copied from interface:ElementType
Compares the given values and retrieves the changes as a stream ofTriple
s. ATriple
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)
- Specified by:
compareValues
in 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
- the general type of the change (added, modified or removed) as a
-
_isMultiple
Checks if the given value is considered as multiple for this element type- Parameters:
value
- the value to check- Returns:
true
if the value is multiple,false
otherwise
-
_isSingle
Checks if the given value is considered as single for this element type- Parameters:
value
- the value to check- Returns:
true
if the value is single,false
otherwise
-
_compareMultipleValues
protected Stream<Triple<DataChangeType,DataChangeTypeDetail, _compareMultipleValuesString>> (T[] value1, T[] value2) Compares the given multiple values and retrieves the changes as a stream ofTriple
s. TheTriple
s 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
- the general type of the change (added, modified or removed) as a
-
_compareSingleValues
protected Stream<Triple<DataChangeType,DataChangeTypeDetail, _compareSingleValuesString>> (T value1, T value2) Compares the given single values and retrieves the changes as a stream ofTriple
s. TheTriple
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 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
- the general type of the change (added, modified or removed) as a
-
isCompatible
Description copied from interface:ElementType
Checks if the value is compatible with the element type- Specified by:
isCompatible
in interfaceElementType<T>
- Parameters:
value
- the value to check- Returns:
true
if the value matches the current type,false
otherwise
-
castValue
Description copied from interface:ElementType
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.- Specified by:
castValue
in 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 given value can't be cast to the type
-
convertValue
Try to convert the given value, that is not of the managed type- Parameters:
value
- the value to convert- Returns:
- the converted value or null if it's not possible.
- Throws:
BadItemTypeException
- if the given value is not compatible with the current type
-
getManagedClass
Description copied from interface:ElementType
Get the class managed by the implementation- Specified by:
getManagedClass
in interfaceElementType<T>
- Returns:
- The class managed (T.class)
-
getManagedClassArray
Description copied from interface:ElementType
Get the class representing an array of managed class by the implementation- Specified by:
getManagedClassArray
in interfaceElementType<T>
- Returns:
- The class managed (T[].class)
-