org.simpleflatmapper.map.mapper.ContextualSourceFieldMapperImpl Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of sfm-map Show documentation
Show all versions of sfm-map Show documentation
Java library to map flat record - ResultSet, csv - to java object with minimum configuration and low footprint.
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 super S> mappingContextFactory;
private final SourceFieldMapper delegate;
public ContextualSourceFieldMapperImpl(MappingContextFactory super S> mappingContextFactory, SourceFieldMapper delegate) {
this.mappingContextFactory = requireNonNull("mappingContextFactory", mappingContextFactory);
this.delegate = requireNonNull("delegate", delegate);
}
public SourceFieldMapper getDelegate() {
return delegate;
}
public MappingContext super S> newMappingContext() {
return mappingContextFactory.newContext();
}
@Override
public T map(S source) throws MappingException {
MappingContext super S> context = mappingContextFactory.newContext();
context.handleSource(source);
return delegate.map(source, context);
}
@Override
public T map(S source, MappingContext super S> context) throws MappingException {
return delegate.map(source, context);
}
@Override
public void mapTo(S source, T target, MappingContext super S> context) throws Exception {
delegate.mapTo(source, target, context);
}
@Override
public String toString() {
return "ContextualSourceMapperImpl{" +
"mappingContextFactory=" + mappingContextFactory +
", delegate=" + delegate +
'}';
}
public MappingContextFactory super S> getMappingContextFactory() {
return mappingContextFactory;
}
}