Class AbstractElementType<T>

    • Method Detail

      • 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
      • _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
      • _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
      • valueToSAXForEdition

        public void valueToSAXForEdition​(ContentHandler contentHandler,
                                         String tagName,
                                         Object value,
                                         Optional<ViewItem> viewItem,
                                         DataContext context)
                                  throws SAXException,
                                         IOException
        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
        IOException - 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: 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
        IOException - 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 - 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
        IOException - 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 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
        IOException - 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 - 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
        IOException - 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 - 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
        IOException - 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 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
      • _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 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
        Throws:
        IOException - if an error occurs while comparing values using the I/O API
      • _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 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
        Throws:
        IOException - if an error occurs while comparing values using the I/O API
      • _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 list
        list2 - 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 list
        list2 - elements to check
        Returns:
        true if all elements in list2 are once in list1
      • 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 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.