Search in sources :

Example 1 with SetterOnGetter

use of org.simpleflatmapper.reflect.setter.SetterOnGetter in project SimpleFlatMapper by arnaudroger.

the class FieldMapperToAppendableFactory method setterFromFactory.

@SuppressWarnings("unchecked")
private <S, P> Setter<Appendable, ? super P> setterFromFactory(PropertyMapping<S, P, CsvColumnKey, FieldMapperColumnDefinition<CsvColumnKey>> pm) {
    Setter<Appendable, ? super P> setter = null;
    final SetterFactoryProperty setterFactoryProperty = pm.getColumnDefinition().lookFor(SetterFactoryProperty.class);
    if (setterFactoryProperty != null) {
        final SetterFactory<Appendable, PropertyMapping<S, P, CsvColumnKey, FieldMapperColumnDefinition<CsvColumnKey>>> setterFactory = (SetterFactory<Appendable, PropertyMapping<S, P, CsvColumnKey, FieldMapperColumnDefinition<CsvColumnKey>>>) setterFactoryProperty.getSetterFactory();
        setter = setterFactory.getSetter(pm);
    }
    if (setter == null) {
        if (!pm.getPropertyMeta().isSelf()) {
            final ClassMeta<P> classMeta = pm.getPropertyMeta().getPropertyClassMeta();
            if (classMeta instanceof ObjectClassMeta) {
                ObjectClassMeta<P> ocm = (ObjectClassMeta<P>) classMeta;
                if (ocm.getNumberOfProperties() == 1) {
                    PropertyMeta<P, ?> subProp = ocm.getFirstProperty();
                    Setter<Appendable, Object> subSetter = (Setter<Appendable, Object>) setterFromFactory(pm.propertyMeta(subProp));
                    if (subSetter != null) {
                        setter = new SetterOnGetter<Appendable, Object, P>(subSetter, (Getter<P, Object>) subProp.getGetter());
                    } else {
                        return new ObjectToStringSetter<P>(subProp.getGetter());
                    }
                }
            }
        }
    }
    return setter;
}
Also used : FieldMapperColumnDefinition(org.simpleflatmapper.map.property.FieldMapperColumnDefinition) CharacterGetter(org.simpleflatmapper.reflect.primitive.CharacterGetter) ShortGetter(org.simpleflatmapper.reflect.primitive.ShortGetter) LongGetter(org.simpleflatmapper.reflect.primitive.LongGetter) BooleanGetter(org.simpleflatmapper.reflect.primitive.BooleanGetter) Getter(org.simpleflatmapper.reflect.Getter) IntGetter(org.simpleflatmapper.reflect.primitive.IntGetter) FloatGetter(org.simpleflatmapper.reflect.primitive.FloatGetter) SetterOnGetter(org.simpleflatmapper.reflect.setter.SetterOnGetter) ByteGetter(org.simpleflatmapper.reflect.primitive.ByteGetter) DoubleGetter(org.simpleflatmapper.reflect.primitive.DoubleGetter) SetterFactory(org.simpleflatmapper.reflect.SetterFactory) SetterFactoryProperty(org.simpleflatmapper.map.property.SetterFactoryProperty) PropertyMapping(org.simpleflatmapper.map.mapper.PropertyMapping) CsvColumnKey(org.simpleflatmapper.csv.CsvColumnKey) Setter(org.simpleflatmapper.reflect.Setter) ObjectClassMeta(org.simpleflatmapper.reflect.meta.ObjectClassMeta)

Aggregations

CsvColumnKey (org.simpleflatmapper.csv.CsvColumnKey)1 PropertyMapping (org.simpleflatmapper.map.mapper.PropertyMapping)1 FieldMapperColumnDefinition (org.simpleflatmapper.map.property.FieldMapperColumnDefinition)1 SetterFactoryProperty (org.simpleflatmapper.map.property.SetterFactoryProperty)1 Getter (org.simpleflatmapper.reflect.Getter)1 Setter (org.simpleflatmapper.reflect.Setter)1 SetterFactory (org.simpleflatmapper.reflect.SetterFactory)1 ObjectClassMeta (org.simpleflatmapper.reflect.meta.ObjectClassMeta)1 BooleanGetter (org.simpleflatmapper.reflect.primitive.BooleanGetter)1 ByteGetter (org.simpleflatmapper.reflect.primitive.ByteGetter)1 CharacterGetter (org.simpleflatmapper.reflect.primitive.CharacterGetter)1 DoubleGetter (org.simpleflatmapper.reflect.primitive.DoubleGetter)1 FloatGetter (org.simpleflatmapper.reflect.primitive.FloatGetter)1 IntGetter (org.simpleflatmapper.reflect.primitive.IntGetter)1 LongGetter (org.simpleflatmapper.reflect.primitive.LongGetter)1 ShortGetter (org.simpleflatmapper.reflect.primitive.ShortGetter)1 SetterOnGetter (org.simpleflatmapper.reflect.setter.SetterOnGetter)1