Class 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 Details

  • Constructor Details

  • Method Details

    • service

      public void service(ServiceManager manager) throws ServiceException
      Specified by:
      service in interface Serviceable
      Throws:
      ServiceException
    • toString

      public String toString(T value)
      Description copied from interface: ElementType
      Cast a typed value to a String
      Specified by:
      toString in interface ElementType<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: ElementType
      Convert the value into a JSON object to use client side
      Specified by:
      valueToJSONForClient in interface ElementType<T>
      Parameters:
      value - the value to convert
      context - The context of the data to convert. Can not be null.
      Returns:
      The value as JSON
    • valueToJSONForEdition

      public Object valueToJSONForEdition(Object value, DataContext context)
      Description copied from interface: ElementType
      Convert the value into a JSON object to use in edition mode
      Specified by:
      valueToJSONForEdition in interface ElementType<T>
      Parameters:
      value - the value to convert
      context - 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 convert
      context - The context of the data to convert
      singleValueToJSONFunction - the function to apply to each single value to convert it into a JSON object
      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 convert
      context - The context of the data to convert
      Returns:
      The value as JSON
    • _singleValueToJSONForEdition

      protected Object _singleValueToJSONForEdition(T value, DataContext context)
      Convert the single value into a JSON object to use in edition mode
      Parameters:
      value - the value to convert
      context - 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 interface ElementType<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)
      Description copied from interface: ElementType
      Parses the given DOM node to get the typed value
      Specified by:
      valueFromXML in interface ElementType<T>
      Parameters:
      parent - the DOM element containing the value
      name - the name of the item to read
      additionalData - additional data needed to get the typed value
      Returns:
      the value
    • _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:
      true if the value is marked as multiple, false otherwise
      Throws:
      TransformerException - if an error occurs while parsing the DOM node
    • _singleValueFromXML

      protected T _singleValueFromXML(Element element, Optional<Object> additionalData)
      Retrieves a single typed value from the given DOM node
      Parameters:
      element - the DOM element containing the single value
      additionalData - 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 interface ModelItemType
      Parameters:
      contentHandler - the ContentHandler that will receive the SAX events
      tagName - the tag name of the SAX event to generate.
      value - the value to SAX
      viewItem - 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 interface ModelItemType
      Parameters:
      contentHandler - the ContentHandler that will receive the SAX events
      tagName - the tag name of the SAX event to generate.
      value - the value to SAX
      viewItem - 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 - the ContentHandler that will receive the SAX events
      tagName - the tag name of the SAX event to generate.
      value - the value to SAX
      viewItem - 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
      isEdition - 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 the valueToJSONForClient(Object, DataContext) method
      Parameters:
      contentHandler - the ContentHandler that will receive the SAX events
      tagName - the tag name of the SAX event to generate.
      value - the value to SAX
      viewItem - 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
      attributes - 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 - the ContentHandler that will receive the SAX events
      tagName - the tag name of the SAX event to generate.
      value - the value to SAX
      viewItem - 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
      attributes - 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 - the ContentHandler that will receive the SAX events
      tagName - the tag name of the SAX event to generate.
      value - the single value to SAX
      attributes - the attributes for the SAX event to generate
      viewItem - 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

      protected AttributesImpl _getValueAttributes(Object value, DataContext context, boolean isEdition)
      Retrieves the attributes of the single value to SAX
      Parameters:
      value - the single value
      context - The context of the data to SAX
      isEdition - true if SAX events are generated in edition mode, false otherwise
      Returns:
      the attributes
    • _useJSONForEdition

      protected boolean _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

      Description copied from interface: ElementType
      Compares the given values and retrieves the changes as a stream of Triples. A Triple 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 interface ElementType<T>
      Parameters:
      value1 - the 1st value
      value2 - 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
    • _isMultiple

      protected boolean _isMultiple(Object value)
      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

      protected boolean _isSingle(Object value)
      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

      Compares the given multiple values and retrieves the changes as a stream of Triples. The Triples 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 value
      value2 - 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
    • _compareSingleValues

      Compares the given single values and retrieves the changes as a stream of Triples. The Triple 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 value
      value2 - 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
    • isCompatible

      public boolean isCompatible(Object value)
      Description copied from interface: ElementType
      Checks if the value is compatible with the element type
      Specified by:
      isCompatible in interface ElementType<T>
      Parameters:
      value - the value to check
      Returns:
      true if the value matches the current type, false otherwise
    • castValue

      public T castValue(Object value) throws BadItemTypeException
      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 interface ElementType<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

      protected T convertValue(Object value) throws BadItemTypeException
      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

      public Class<T> getManagedClass()
      Description copied from interface: ElementType
      Get the class managed by the implementation
      Specified by:
      getManagedClass in interface ElementType<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 interface ElementType<T>
      Returns:
      The class managed (T[].class)