package com.hammurapi.convert;

import java.util.concurrent.Callable;

import com.hammurapi.common.Context;

public class CallableConverterPart implements ConverterPart {

	@Override
	public <S, T> T convert(S source, Class<T> targetType, Context context, Converter master) throws ConversionException {
		if (source instanceof Callable) {
			try {
				Object value = ((Callable) source).call();
				return master.convert(value, targetType, context);				
			} catch (Exception e) {
				throw new ConversionException(e);
			}
			
		}
		return null;
	}

}
