Class UnivalConvertor
- java.lang.Object
-
- sk.ipesoft.d2000.d2japi.annotations.UnivalConvertor
-
public class UnivalConvertor extends java.lang.Object
Convertor for translating from and to unival values.
-
-
Constructor Summary
Constructors Constructor Description UnivalConvertor(D2StructureDefinitionResolver resolver)
Create new instance bound toresolver
.
-
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 withdictionaryConvertor
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 alldictionaryConvertors
and write results as multi-converted column bound values.void
registerStructure(java.lang.Class<?> type)
Register user bean type for use indecodeStructure(UnivalRecord, Class)
andencodeStructure(List, Class)
.boolean
unregisterStructure(java.lang.Class<?> type)
Cancel registration of user bean type previously registered byregisterStructure(Class)
.
-
-
-
Constructor Detail
-
UnivalConvertor
public UnivalConvertor(D2StructureDefinitionResolver resolver)
Create new instance bound toresolver
.- 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 invalidvalue
thennull
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 fromtype
- class reference to registered type- Returns:
- new list of beans or
null
ifvalue
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 valuenull
is returned.- Type Parameters:
T
- annotated type of the bean- Parameters:
value
- structured valuerowIndex
- zero based index of rowtype
- 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 beanstype
- 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 withdictionaryConvertor
and write results as converted column bound values.- Type Parameters:
T
- registered type of beans- Parameters:
values
- list of beanstype
- reference to bean typedictionaryConvertor
- 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 alldictionaryConvertors
and write results as multi-converted column bound values.- Type Parameters:
T
- registered type of beans- Parameters:
values
- list of beanstype
- reference to bean typedictionaryConvertors
- list of dictionary convertors that converts values- Returns:
- the same instance of list
-
registerStructure
public void registerStructure(java.lang.Class<?> type)
Register user bean type for use indecodeStructure(UnivalRecord, Class)
andencodeStructure(List, Class)
.type
must be properly annotated withStructureDefinition
,ColumnValue
andColumnAttribute
.Note: Re-registration has not effect.
Warning: Validity of binding is NOT checked during registration process against structure definition resolver. It is rather checked during encoding/decoding process.
- Parameters:
type
- reference to user bean type.
-
unregisterStructure
public boolean unregisterStructure(java.lang.Class<?> type)
Cancel registration of user bean type previously registered byregisterStructure(Class)
.- Parameters:
type
- user bean type to unregister.- Returns:
true
if registration canceled successfully;false
iftype
hadn't been registered.
-
-