Search in sources :

Example 1 with InstantiatorContextualGetter

use of org.simpleflatmapper.map.getter.InstantiatorContextualGetter in project SimpleFlatMapper by arnaudroger.

the class ConstantSourceFieldMapperFactoryImpl method getGetterInstantiator.

private <T, P> ContextualGetter<? super S, ? extends P> getGetterInstantiator(ClassMeta<P> classMeta, InstantiatorDefinition id, K key, ColumnDefinition<K, ?> columnDefinition, Collection<Type> types, MappingContextFactoryBuilder<?, ? extends FieldKey<?>> mappingContextFactoryBuilder) {
    Instantiator<? super T, ? extends P> instantiator = classMeta.getReflectionService().getInstantiatorFactory().getOneArgIdentityInstantiator(id, classMeta.getReflectionService().builderIgnoresNullValues());
    final Type paramType = id.getParameters()[0].getGenericType();
    ContextualGetter<? super S, ? extends T> subGetter = getterFactory.newGetter(paramType, key, mappingContextFactoryBuilder, columnDefinition);
    if (subGetter == null) {
        if (types.contains(paramType)) {
            // loop circuit cutter
            return null;
        }
        types.add(paramType);
        // converter?
        Type sourceType = key.getType(paramType);
        ContextualConverter converter = converterService.findConverter(sourceType, paramType, mappingContextFactoryBuilder, columnDefinition.properties());
        if (converter != null) {
            ContextualGetter sourceTypeGetter = getterFactory.newGetter(sourceType, key, mappingContextFactoryBuilder, columnDefinition);
            subGetter = new FieldMapperGetterWithConverter(converter, sourceTypeGetter);
        } else {
            subGetter = lookForInstantiatorGetter(classMeta.getReflectionService().<T>getClassMeta(paramType), key, columnDefinition, types, mappingContextFactoryBuilder);
        }
    }
    if (subGetter != null) {
        return new InstantiatorContextualGetter<T, S, P>(instantiator, subGetter);
    } else
        return null;
}
Also used : Type(java.lang.reflect.Type) CharacterContextualGetter(org.simpleflatmapper.map.getter.CharacterContextualGetter) BoxedFloatContextualGetter(org.simpleflatmapper.map.getter.BoxedFloatContextualGetter) BoxedByteContextualGetter(org.simpleflatmapper.map.getter.BoxedByteContextualGetter) BoxedBooleanContextualGetter(org.simpleflatmapper.map.getter.BoxedBooleanContextualGetter) ContextualGetter(org.simpleflatmapper.map.getter.ContextualGetter) FloatContextualGetter(org.simpleflatmapper.map.getter.FloatContextualGetter) BoxedIntContextualGetter(org.simpleflatmapper.map.getter.BoxedIntContextualGetter) BoxedDoubleContextualGetter(org.simpleflatmapper.map.getter.BoxedDoubleContextualGetter) InstantiatorContextualGetter(org.simpleflatmapper.map.getter.InstantiatorContextualGetter) IntContextualGetter(org.simpleflatmapper.map.getter.IntContextualGetter) BooleanContextualGetter(org.simpleflatmapper.map.getter.BooleanContextualGetter) ShortContextualGetter(org.simpleflatmapper.map.getter.ShortContextualGetter) DoubleContextualGetter(org.simpleflatmapper.map.getter.DoubleContextualGetter) LongContextualGetter(org.simpleflatmapper.map.getter.LongContextualGetter) BoxedShortContextualGetter(org.simpleflatmapper.map.getter.BoxedShortContextualGetter) ByteContextualGetter(org.simpleflatmapper.map.getter.ByteContextualGetter) BoxedLongContextualGetter(org.simpleflatmapper.map.getter.BoxedLongContextualGetter) BoxedCharacterContextualGetter(org.simpleflatmapper.map.getter.BoxedCharacterContextualGetter) InstantiatorContextualGetter(org.simpleflatmapper.map.getter.InstantiatorContextualGetter) ContextualConverter(org.simpleflatmapper.converter.ContextualConverter)

Aggregations

Type (java.lang.reflect.Type)1 ContextualConverter (org.simpleflatmapper.converter.ContextualConverter)1 BooleanContextualGetter (org.simpleflatmapper.map.getter.BooleanContextualGetter)1 BoxedBooleanContextualGetter (org.simpleflatmapper.map.getter.BoxedBooleanContextualGetter)1 BoxedByteContextualGetter (org.simpleflatmapper.map.getter.BoxedByteContextualGetter)1 BoxedCharacterContextualGetter (org.simpleflatmapper.map.getter.BoxedCharacterContextualGetter)1 BoxedDoubleContextualGetter (org.simpleflatmapper.map.getter.BoxedDoubleContextualGetter)1 BoxedFloatContextualGetter (org.simpleflatmapper.map.getter.BoxedFloatContextualGetter)1 BoxedIntContextualGetter (org.simpleflatmapper.map.getter.BoxedIntContextualGetter)1 BoxedLongContextualGetter (org.simpleflatmapper.map.getter.BoxedLongContextualGetter)1 BoxedShortContextualGetter (org.simpleflatmapper.map.getter.BoxedShortContextualGetter)1 ByteContextualGetter (org.simpleflatmapper.map.getter.ByteContextualGetter)1 CharacterContextualGetter (org.simpleflatmapper.map.getter.CharacterContextualGetter)1 ContextualGetter (org.simpleflatmapper.map.getter.ContextualGetter)1 DoubleContextualGetter (org.simpleflatmapper.map.getter.DoubleContextualGetter)1 FloatContextualGetter (org.simpleflatmapper.map.getter.FloatContextualGetter)1 InstantiatorContextualGetter (org.simpleflatmapper.map.getter.InstantiatorContextualGetter)1 IntContextualGetter (org.simpleflatmapper.map.getter.IntContextualGetter)1 LongContextualGetter (org.simpleflatmapper.map.getter.LongContextualGetter)1 ShortContextualGetter (org.simpleflatmapper.map.getter.ShortContextualGetter)1