Class UnivalConvertor



  • public class UnivalConvertor
    extends java.lang.Object
    Convertor for translating from and to unival values.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      <T> java.util.List<T> decodeStructure​(sk.ipesoft.d2000.base.UnivalRecord<?,?,?> value, java.lang.Class<T> type)
      Convert from unival record value to list of user-defined beans.
      <T> T decodeStructureRow​(sk.ipesoft.d2000.base.UnivalRecord<?,?,?> value, int rowIndex, java.lang.Class<T> type)
      Decode single row of structured value into single instance of user-defined bean.
      <T> sk.ipesoft.d2000.base.UnivalRecord<?,?,?> encodeEmptyStructure​(java.lang.Class<T> type)
      Create unival record value with zero rows.
      <T> sk.ipesoft.d2000.base.UnivalRecord<?,?,?> encodeStructure​(java.util.List<T> values, java.lang.Class<T> type)
      Covert list of beans to Unival record value.
      <T> java.util.List<T> fillConvertedValues​(java.util.List<T> values, java.lang.Class<T> type, Convertor dictionaryConvertor)
      Convert column bound values with dictionaryConvertor and write results as converted column bound values.
      <T> java.util.List<T> fillMulticonvertedValues​(java.util.List<T> values, java.lang.Class<T> type, java.util.List<Convertor> dictionaryConvertors)
      Convert column bound values with all dictionaryConvertors and write results as multi-converted column bound values.
      void registerStructure​(java.lang.Class<?> type)
      boolean unregisterStructure​(java.lang.Class<?> type)
      Cancel registration of user bean type previously registered by registerStructure(Class).
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • UnivalConvertor

        public UnivalConvertor​(D2StructureDefinitionResolver resolver)
        Create new instance bound to resolver.
        Parameters:
        resolver - cache for holding D2000 structure definition objects
    • Method Detail

      • decodeStructure

        public <T> java.util.List<T> decodeStructure​(sk.ipesoft.d2000.base.UnivalRecord<?,?,?> value,
                                                     java.lang.Class<T> type)
        Convert from unival record value to list of user-defined beans. Each row of structured value is converted to one bean. In case of invalid value then null is returned.

        Type of the beans can be registered prior this call, but would be registered automatically, if it hasn't been registered yet.

        Type Parameters:
        T - registered type of the beans
        Parameters:
        value - unival record value to translate from
        type - class reference to registered type
        Returns:
        new list of beans or null if value is invalid
      • decodeStructureRow

        public <T> T decodeStructureRow​(sk.ipesoft.d2000.base.UnivalRecord<?,?,?> value,
                                        int rowIndex,
                                        java.lang.Class<T> type)
        Decode single row of structured value into single instance of user-defined bean. In case of invalid value null is returned.
        Type Parameters:
        T - annotated type of the bean
        Parameters:
        value - structured value
        rowIndex - zero based index of row
        type - reference to bean type
        Returns:
        single bean
      • encodeEmptyStructure

        public <T> sk.ipesoft.d2000.base.UnivalRecord<?,?,?> encodeEmptyStructure​(java.lang.Class<T> type)
        Create unival record value with zero rows.

        Type of the beans can be registered prior this call, but would be registered automatically, if it hasn't been registered yet.

        Type Parameters:
        T - registered type of beans
        Parameters:
        type - reference to type of beans
        Returns:
        new instance of unival record value
      • encodeStructure

        public <T> sk.ipesoft.d2000.base.UnivalRecord<?,?,?> encodeStructure​(java.util.List<T> values,
                                                                             java.lang.Class<T> type)
        Covert list of beans to Unival record value. Each bean is converted to one row of record.

        Type of the beans MUST be registered with registerStructure(Class) prior this call.

        Type Parameters:
        T - registered type of beans
        Parameters:
        values - list of beans
        type - reference to type of beans
        Returns:
        new instance of unival record value
      • fillConvertedValues

        public <T> java.util.List<T> fillConvertedValues​(java.util.List<T> values,
                                                         java.lang.Class<T> type,
                                                         Convertor dictionaryConvertor)
        Convert column bound values with dictionaryConvertor and write results as converted column bound values.
        Type Parameters:
        T - registered type of beans
        Parameters:
        values - list of beans
        type - reference to bean type
        dictionaryConvertor - dictionary convertor that converts values
        Returns:
        the same instance of list
      • fillMulticonvertedValues

        public <T> java.util.List<T> fillMulticonvertedValues​(java.util.List<T> values,
                                                              java.lang.Class<T> type,
                                                              java.util.List<Convertor> dictionaryConvertors)
        Convert column bound values with all dictionaryConvertors and write results as multi-converted column bound values.
        Type Parameters:
        T - registered type of beans
        Parameters:
        values - list of beans
        type - reference to bean type
        dictionaryConvertors - list of dictionary convertors that converts values
        Returns:
        the same instance of list
      • unregisterStructure

        public boolean unregisterStructure​(java.lang.Class<?> type)
        Cancel registration of user bean type previously registered by registerStructure(Class).
        Parameters:
        type - user bean type to unregister.
        Returns:
        true if registration canceled successfully; false if type hadn't been registered.