All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.simpleflatmapper.map.mapper.ContextualSourceFieldMapperImpl Maven / Gradle / Ivy

Go to download

Java library to map flat record - ResultSet, csv - to java object with minimum configuration and low footprint.

The newest version!
package org.simpleflatmapper.map.mapper;

import org.simpleflatmapper.map.ContextualSourceFieldMapper;
import org.simpleflatmapper.map.SourceFieldMapper;
import org.simpleflatmapper.map.MappingContext;
import org.simpleflatmapper.map.context.MappingContextFactory;
import org.simpleflatmapper.map.MappingException;

import static org.simpleflatmapper.util.Asserts.requireNonNull;


public class ContextualSourceFieldMapperImpl implements ContextualSourceFieldMapper {
    private final MappingContextFactory mappingContextFactory;
    private final SourceFieldMapper delegate;

    public ContextualSourceFieldMapperImpl(MappingContextFactory mappingContextFactory, SourceFieldMapper delegate) {
        this.mappingContextFactory = requireNonNull("mappingContextFactory", mappingContextFactory);
        this.delegate = requireNonNull("delegate", delegate);
    }

    public SourceFieldMapper getDelegate() {
        return delegate;
    }

    public MappingContext newMappingContext() {
        return mappingContextFactory.newContext();
    }

    @Override
    public T map(S source) throws MappingException {
        MappingContext context = mappingContextFactory.newContext();
        context.handleSource(source);
        return delegate.map(source, context);
    }

    @Override
    public T map(S source, MappingContext context) throws MappingException {
        return delegate.map(source, context);
    }

    @Override
    public void mapTo(S source, T target, MappingContext context) throws Exception {
        delegate.mapTo(source, target, context);
    }

    @Override
    public String toString() {
        return "ContextualSourceMapperImpl{" +
                "mappingContextFactory=" + mappingContextFactory +
                ", delegate=" + delegate +
                '}';
    }

    public MappingContextFactory getMappingContextFactory() {
        return mappingContextFactory;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy