// 
// Decompiled by Procyon v0.6.0
// 

package org.bson.codecs.pojo;

import org.bson.codecs.EncoderContext;
import org.bson.BsonWriter;
import org.bson.codecs.configuration.CodecConfigurationException;
import org.bson.codecs.DecoderContext;
import org.bson.BsonReader;

final class AutomaticPojoCodec<T> extends PojoCodec<T>
{
    private final PojoCodec<T> pojoCodec;
    
    AutomaticPojoCodec(final PojoCodec<T> pojoCodec) {
        this.pojoCodec = pojoCodec;
    }
    
    @Override
    public T decode(final BsonReader reader, final DecoderContext decoderContext) {
        try {
            return this.pojoCodec.decode(reader, decoderContext);
        }
        catch (final CodecConfigurationException e) {
            throw new CodecConfigurationException(String.format("An exception occurred when decoding using the AutomaticPojoCodec.%nDecoding into a '%s' failed with the following exception:%n%n%s%n%nA custom Codec or PojoCodec may need to be explicitly configured and registered to handle this type.", this.pojoCodec.getEncoderClass().getSimpleName(), e.getMessage()), e);
        }
    }
    
    @Override
    public void encode(final BsonWriter writer, final T value, final EncoderContext encoderContext) {
        try {
            this.pojoCodec.encode(writer, value, encoderContext);
        }
        catch (final CodecConfigurationException e) {
            throw new CodecConfigurationException(String.format("An exception occurred when encoding using the AutomaticPojoCodec.%nEncoding a %s: '%s' failed with the following exception:%n%n%s%n%nA custom Codec or PojoCodec may need to be explicitly configured and registered to handle this type.", this.getEncoderClass().getSimpleName(), value, e.getMessage()), e);
        }
    }
    
    @Override
    public Class<T> getEncoderClass() {
        return this.pojoCodec.getEncoderClass();
    }
    
    @Override
    ClassModel<T> getClassModel() {
        return this.pojoCodec.getClassModel();
    }
    
    @Override
    DiscriminatorLookup getDiscriminatorLookup() {
        return this.pojoCodec.getDiscriminatorLookup();
    }
}
