1 16 package net.sf.dozer.util.mapping.converters; 17 18 import java.util.HashMap ; 19 20 import net.sf.dozer.util.mapping.MappingException; 21 import net.sf.dozer.util.mapping.vo.TestCustomConverterHashMapObject; 22 import net.sf.dozer.util.mapping.vo.TestCustomConverterHashMapPrimeObject; 23 import net.sf.dozer.util.mapping.vo.TestObject; 24 import net.sf.dozer.util.mapping.vo.TestObjectPrime; 25 26 29 public class TestCustomHashMapConverter implements CustomConverter { 30 31 public Object convert(Object destination, Object source, Class destClass, Class sourceClass) { 32 33 if (source instanceof TestCustomConverterHashMapObject) { 34 TestCustomConverterHashMapPrimeObject dest = null; 35 TestCustomConverterHashMapObject testCustomConverterHashMapObject = (TestCustomConverterHashMapObject) source; 36 if (destination == null) { 37 dest = new TestCustomConverterHashMapPrimeObject(); 38 } else { 39 dest = (TestCustomConverterHashMapPrimeObject) destination; 40 } 41 HashMap map = new HashMap (); 42 map.put("object1", testCustomConverterHashMapObject.getTestObject()); 43 map.put("object2", testCustomConverterHashMapObject.getTestObjectPrime()); 44 dest.setTestObjects(map); 45 return dest; 46 } else if (source instanceof TestCustomConverterHashMapPrimeObject) { 47 TestCustomConverterHashMapObject dest = null; 48 49 TestCustomConverterHashMapPrimeObject testCustomConverterHashMapPrimeObject = (TestCustomConverterHashMapPrimeObject) source; 50 if (destination == null) { 51 dest = new TestCustomConverterHashMapObject(); 52 } else { 53 dest = (TestCustomConverterHashMapObject) destination; 54 } 55 dest.setTestObject((TestObject) testCustomConverterHashMapPrimeObject.getTestObjects().get("object1")); 56 dest.setTestObjectPrime((TestObjectPrime) testCustomConverterHashMapPrimeObject.getTestObjects().get("object2")); 57 return dest; 58 } else { 59 throw new MappingException("Converter TestCustomHashMapConverter used incorrectly. Arguments passed in were:" 60 + destination + " and " + source); 61 } 62 } 63 64 } 65 | Popular Tags |