package com.vaadin.data.util.converter;

import java.util.Date;

public class DefaultConverterFactory implements ConverterFactory {

    public <SOURCE, TARGET> Converter<SOURCE, TARGET> createConverter(
            Class<SOURCE> sourceType, Class<TARGET> targetType) {
        Converter<SOURCE, TARGET> converter = findConverter(sourceType,
                targetType);
        if (converter != null) {
            System.out.println(getClass().getName() + " created a "
                    + converter.getClass());
            return converter;
        }

        // Try to find a reverse converter
        Converter<TARGET, SOURCE> reverseConverter = findConverter(targetType,
                sourceType);
        if (reverseConverter != null) {
            System.out.println(getClass().getName() + " created a reverse "
                    + reverseConverter.getClass());
            return new ReverseConverter<SOURCE, TARGET>(reverseConverter);
        }

        System.out.println(getClass().getName()
                + " could not find a converter for " + sourceType.getName()
                + " to " + targetType.getName() + " conversion");
        return null;

    }

    protected <SOURCE, TARGET> Converter<SOURCE, TARGET> findConverter(
            Class<SOURCE> sourceType, Class<TARGET> targetType) {
        if (targetType == String.class) {
            // TextField converters and more
            Converter<SOURCE, TARGET> converter = (Converter<SOURCE, TARGET>) createStringConverter(sourceType);
            if (converter != null) {
                return converter;
            }
        } else if (targetType == Date.class) {
            // DateField converters and more
            Converter<SOURCE, TARGET> converter = (Converter<SOURCE, TARGET>) createDateConverter(sourceType);
            if (converter != null) {
                return converter;
            }
        }

        return null;

    }

    protected Converter<?, Date> createDateConverter(Class<?> sourceType) {
        if (Long.class.isAssignableFrom(sourceType)) {
            return new LongToDateConverter();
        } else {
            return null;
        }
    }

    protected Converter<?, String> createStringConverter(Class<?> sourceType) {
        if (Double.class.isAssignableFrom(sourceType)) {
            return new DoubleToStringConverter();
        } else if (Integer.class.isAssignableFrom(sourceType)) {
            return new IntegerToStringConverter();
        } else if (Boolean.class.isAssignableFrom(sourceType)) {
            return new BooleanToStringConverter();
        } else if (Number.class.isAssignableFrom(sourceType)) {
            return new NumberToStringConverter();
        } else if (Date.class.isAssignableFrom(sourceType)) {
            return new DateToStringConverter();
        } else {
            return null;
        }
    }

}

@@ -59,16 +59,50 @@
 l.Date;%0D
+%0Aimport java.util.logging.Logger;%0D
 %0A%0D%0Apubli
@@ -162,24 +162,138 @@
 actory %7B%0D%0A%0D%0A
+    private final static Logger log = Logger%0D%0A            .getLogger(DefaultConverterFactory.class.getName());%0D%0A%0D%0A
     public %3C
@@ -568,34 +568,26 @@
         
-System.out.println
+log.finest
 (getClas
@@ -914,34 +914,26 @@
         
-System.out.println
+log.finest
 (getClas
@@ -1125,26 +1125,18 @@
     
-System.out.println
+log.finest
 (get
@@ -1152,33 +1152,16 @@
 etName()
-%0D%0A               
  + %22 cou
@@ -1189,16 +1189,33 @@
 er for %22
+%0D%0A               
  + sourc
@@ -1229,33 +1229,16 @@
 etName()
-%0D%0A               
  + %22 to 
@@ -1257,24 +1257,41 @@
 pe.getName()
+%0D%0A               
  + %22 convers

Use Logger for debug messages in DefaultConverterFactory.