1 16 package org.springframework.binding.convert.support; 17 18 import org.springframework.binding.convert.ConversionContext; 19 import org.springframework.binding.convert.ConversionException; 20 import org.springframework.binding.convert.Converter; 21 22 27 public abstract class AbstractConverter implements Converter { 28 29 38 public Object convert(Object source) throws ConversionException { 39 return convert(source, getTargetClasses()[0], null); 40 } 41 42 52 public Object convert(Object source, Class targetClass) throws ConversionException { 53 return convert(source, targetClass, null); 54 } 55 56 67 public Object convert(Object source, ConversionContext context) throws ConversionException { 68 return convert(source, getTargetClasses()[0], context); 69 } 70 71 public Object convert(Object source, Class targetClass, ConversionContext context) throws ConversionException { 72 try { 73 return doConvert(source, targetClass, context); 74 } catch (ConversionException e) { 75 throw e; 76 } catch (Throwable e) { 77 if (targetClass == null) { 78 targetClass = getTargetClasses()[0]; 79 } 80 throw new ConversionException(source, targetClass, e); 81 } 82 } 83 84 95 protected abstract Object doConvert(Object source, Class targetClass, ConversionContext context) throws Exception ; 96 97 } | Popular Tags |