/* Generated by camel build tools - do NOT edit this file! */
package org.fusesource.camel.component.sap.converter;

import org.apache.camel.CamelContext;
import org.apache.camel.CamelContextAware;
import org.apache.camel.DeferredContextBinding;
import org.apache.camel.Exchange;
import org.apache.camel.Ordered;
import org.apache.camel.TypeConversionException;
import org.apache.camel.TypeConverterLoaderException;
import org.apache.camel.TypeConverter;
import org.apache.camel.spi.BulkTypeConverters;
import org.apache.camel.spi.TypeConverterLoader;
import org.apache.camel.spi.TypeConverterRegistry;

/**
 * Generated by camel build tools - do NOT edit this file!
 */
@SuppressWarnings("unchecked")
@DeferredContextBinding
public final class CamelSapBulkConverterLoader implements TypeConverterLoader, BulkTypeConverters, CamelContextAware {

    private CamelContext camelContext;

    public CamelSapBulkConverterLoader() {
    }

    @Override
    public void setCamelContext(CamelContext camelContext) {
        this.camelContext = camelContext;
    }

    @Override
    public CamelContext getCamelContext() {
        return camelContext;
    }

    @Override
    public int size() {
        return 30;
    }

    @Override
    public void load(TypeConverterRegistry registry) throws TypeConverterLoaderException {
        registry.addBulkTypeConverters(this);
    }

    @Override
    public <T> T convertTo(Class<?> from, Class<T> to, Exchange exchange, Object value) throws TypeConversionException {
        try {
            Object obj = doConvertTo(from, to, exchange, value);
            if (obj == Void.class) {;
                return null;
            } else {
                return (T) obj;
            }
        } catch (TypeConversionException e) {
            throw e;
        } catch (Exception e) {
            throw new TypeConversionException(value, to, e);
        }
    }

    private Object doConvertTo(Class<?> from, Class<?> to, Exchange exchange, Object value) throws Exception {
        if (to == java.io.InputStream.class) {
            if (value instanceof org.fusesource.camel.component.sap.model.idoc.impl.DocumentImpl) {
                return org.fusesource.camel.component.sap.converter.DocumentConverter.toInputStream((org.fusesource.camel.component.sap.model.idoc.impl.DocumentImpl) value);
            }
            if (value instanceof org.fusesource.camel.component.sap.model.idoc.impl.DocumentListImpl) {
                return org.fusesource.camel.component.sap.converter.DocumentListConverter.toInputStream((org.fusesource.camel.component.sap.model.idoc.impl.DocumentListImpl) value);
            }
            if (value instanceof org.fusesource.camel.component.sap.model.rfc.impl.RequestImpl) {
                return org.fusesource.camel.component.sap.converter.RequestConverter.toInputStream((org.fusesource.camel.component.sap.model.rfc.impl.RequestImpl) value);
            }
            if (value instanceof org.fusesource.camel.component.sap.model.rfc.impl.ResponseImpl) {
                return org.fusesource.camel.component.sap.converter.ResponseConverter.toInputStream((org.fusesource.camel.component.sap.model.rfc.impl.ResponseImpl) value);
            }
            if (value instanceof org.fusesource.camel.component.sap.model.rfc.impl.StructureImpl) {
                return org.fusesource.camel.component.sap.converter.StructureConverter.toInputStream((org.fusesource.camel.component.sap.model.rfc.impl.StructureImpl) value);
            }
        } else if (to == java.io.OutputStream.class) {
            if (value instanceof org.fusesource.camel.component.sap.model.idoc.impl.DocumentImpl) {
                return org.fusesource.camel.component.sap.converter.DocumentConverter.toOutputStream((org.fusesource.camel.component.sap.model.idoc.impl.DocumentImpl) value);
            }
            if (value instanceof org.fusesource.camel.component.sap.model.idoc.impl.DocumentListImpl) {
                return org.fusesource.camel.component.sap.converter.DocumentListConverter.toOutputStream((org.fusesource.camel.component.sap.model.idoc.impl.DocumentListImpl) value);
            }
            if (value instanceof org.fusesource.camel.component.sap.model.rfc.impl.RequestImpl) {
                return org.fusesource.camel.component.sap.converter.RequestConverter.toOutputStream((org.fusesource.camel.component.sap.model.rfc.impl.RequestImpl) value);
            }
            if (value instanceof org.fusesource.camel.component.sap.model.rfc.impl.ResponseImpl) {
                return org.fusesource.camel.component.sap.converter.ResponseConverter.toOutputStream((org.fusesource.camel.component.sap.model.rfc.impl.ResponseImpl) value);
            }
            if (value instanceof org.fusesource.camel.component.sap.model.rfc.impl.StructureImpl) {
                return org.fusesource.camel.component.sap.converter.StructureConverter.toOutputStream((org.fusesource.camel.component.sap.model.rfc.impl.StructureImpl) value);
            }
        } else if (to == java.lang.String.class) {
            if (value instanceof org.fusesource.camel.component.sap.model.idoc.impl.DocumentImpl) {
                return org.fusesource.camel.component.sap.converter.DocumentConverter.toString((org.fusesource.camel.component.sap.model.idoc.impl.DocumentImpl) value);
            }
            if (value instanceof org.fusesource.camel.component.sap.model.idoc.impl.DocumentListImpl) {
                return org.fusesource.camel.component.sap.converter.DocumentListConverter.toString((org.fusesource.camel.component.sap.model.idoc.impl.DocumentListImpl) value);
            }
            if (value instanceof org.fusesource.camel.component.sap.model.rfc.impl.RequestImpl) {
                return org.fusesource.camel.component.sap.converter.RequestConverter.toString((org.fusesource.camel.component.sap.model.rfc.impl.RequestImpl) value);
            }
            if (value instanceof org.fusesource.camel.component.sap.model.rfc.impl.ResponseImpl) {
                return org.fusesource.camel.component.sap.converter.ResponseConverter.toString((org.fusesource.camel.component.sap.model.rfc.impl.ResponseImpl) value);
            }
            if (value instanceof org.fusesource.camel.component.sap.model.rfc.impl.StructureImpl) {
                return org.fusesource.camel.component.sap.converter.StructureConverter.toString((org.fusesource.camel.component.sap.model.rfc.impl.StructureImpl) value);
            }
        } else if (to == org.fusesource.camel.component.sap.model.idoc.Document.class) {
            if (value instanceof byte[]) {
                return org.fusesource.camel.component.sap.converter.DocumentConverter.toDocument((byte[]) value);
            }
            if (value instanceof java.io.InputStream) {
                return org.fusesource.camel.component.sap.converter.DocumentConverter.toDocument((java.io.InputStream) value);
            }
            if (value instanceof java.lang.String) {
                return org.fusesource.camel.component.sap.converter.DocumentConverter.toDocument((java.lang.String) value);
            }
        } else if (to == org.fusesource.camel.component.sap.model.idoc.DocumentList.class) {
            if (value instanceof byte[]) {
                return org.fusesource.camel.component.sap.converter.DocumentListConverter.toDocumentList((byte[]) value);
            }
            if (value instanceof java.io.InputStream) {
                return org.fusesource.camel.component.sap.converter.DocumentListConverter.toDocumentList((java.io.InputStream) value);
            }
            if (value instanceof java.lang.String) {
                return org.fusesource.camel.component.sap.converter.DocumentListConverter.toDocumentList((java.lang.String) value);
            }
        } else if (to == org.fusesource.camel.component.sap.model.rfc.Request.class) {
            if (value instanceof byte[]) {
                return org.fusesource.camel.component.sap.converter.RequestConverter.toRequest((byte[]) value);
            }
            if (value instanceof java.io.InputStream) {
                return org.fusesource.camel.component.sap.converter.RequestConverter.toRequest((java.io.InputStream) value);
            }
            if (value instanceof java.lang.String) {
                return org.fusesource.camel.component.sap.converter.RequestConverter.toRequest((java.lang.String) value);
            }
        } else if (to == org.fusesource.camel.component.sap.model.rfc.Response.class) {
            if (value instanceof byte[]) {
                return org.fusesource.camel.component.sap.converter.ResponseConverter.toResponse((byte[]) value);
            }
            if (value instanceof java.io.InputStream) {
                return org.fusesource.camel.component.sap.converter.ResponseConverter.toResponse((java.io.InputStream) value);
            }
            if (value instanceof java.lang.String) {
                return org.fusesource.camel.component.sap.converter.ResponseConverter.toResponse((java.lang.String) value);
            }
        } else if (to == org.fusesource.camel.component.sap.model.rfc.Structure.class) {
            if (value instanceof byte[]) {
                return org.fusesource.camel.component.sap.converter.StructureConverter.toStructure((byte[]) value);
            }
            if (value instanceof java.io.InputStream) {
                return org.fusesource.camel.component.sap.converter.StructureConverter.toStructure((java.io.InputStream) value);
            }
            if (value instanceof java.lang.String) {
                return org.fusesource.camel.component.sap.converter.StructureConverter.toStructure((java.lang.String) value);
            }
        }
        return null;
    }

    public TypeConverter lookup(Class<?> to, Class<?> from) {
        if (to == java.io.InputStream.class) {
            if (from == org.fusesource.camel.component.sap.model.idoc.impl.DocumentImpl.class) {
                return this;
            }
            if (from == org.fusesource.camel.component.sap.model.idoc.impl.DocumentListImpl.class) {
                return this;
            }
            if (from == org.fusesource.camel.component.sap.model.rfc.impl.RequestImpl.class) {
                return this;
            }
            if (from == org.fusesource.camel.component.sap.model.rfc.impl.ResponseImpl.class) {
                return this;
            }
            if (from == org.fusesource.camel.component.sap.model.rfc.impl.StructureImpl.class) {
                return this;
            }
        } else if (to == java.io.OutputStream.class) {
            if (from == org.fusesource.camel.component.sap.model.idoc.impl.DocumentImpl.class) {
                return this;
            }
            if (from == org.fusesource.camel.component.sap.model.idoc.impl.DocumentListImpl.class) {
                return this;
            }
            if (from == org.fusesource.camel.component.sap.model.rfc.impl.RequestImpl.class) {
                return this;
            }
            if (from == org.fusesource.camel.component.sap.model.rfc.impl.ResponseImpl.class) {
                return this;
            }
            if (from == org.fusesource.camel.component.sap.model.rfc.impl.StructureImpl.class) {
                return this;
            }
        } else if (to == java.lang.String.class) {
            if (from == org.fusesource.camel.component.sap.model.idoc.impl.DocumentImpl.class) {
                return this;
            }
            if (from == org.fusesource.camel.component.sap.model.idoc.impl.DocumentListImpl.class) {
                return this;
            }
            if (from == org.fusesource.camel.component.sap.model.rfc.impl.RequestImpl.class) {
                return this;
            }
            if (from == org.fusesource.camel.component.sap.model.rfc.impl.ResponseImpl.class) {
                return this;
            }
            if (from == org.fusesource.camel.component.sap.model.rfc.impl.StructureImpl.class) {
                return this;
            }
        } else if (to == org.fusesource.camel.component.sap.model.idoc.Document.class) {
            if (from == byte[].class) {
                return this;
            }
            if (from == java.io.InputStream.class) {
                return this;
            }
            if (from == java.lang.String.class) {
                return this;
            }
        } else if (to == org.fusesource.camel.component.sap.model.idoc.DocumentList.class) {
            if (from == byte[].class) {
                return this;
            }
            if (from == java.io.InputStream.class) {
                return this;
            }
            if (from == java.lang.String.class) {
                return this;
            }
        } else if (to == org.fusesource.camel.component.sap.model.rfc.Request.class) {
            if (from == byte[].class) {
                return this;
            }
            if (from == java.io.InputStream.class) {
                return this;
            }
            if (from == java.lang.String.class) {
                return this;
            }
        } else if (to == org.fusesource.camel.component.sap.model.rfc.Response.class) {
            if (from == byte[].class) {
                return this;
            }
            if (from == java.io.InputStream.class) {
                return this;
            }
            if (from == java.lang.String.class) {
                return this;
            }
        } else if (to == org.fusesource.camel.component.sap.model.rfc.Structure.class) {
            if (from == byte[].class) {
                return this;
            }
            if (from == java.io.InputStream.class) {
                return this;
            }
            if (from == java.lang.String.class) {
                return this;
            }
        }
        return null;
    }

}
