1 16 package com.ibatis.sqlmap.engine.exchange; 17 18 import com.ibatis.sqlmap.engine.type.DomTypeMarker; 19 import com.ibatis.sqlmap.engine.type.TypeHandlerFactory; 20 21 import java.util.List ; 22 import java.util.Map ; 23 24 27 public class DataExchangeFactory { 28 29 private final DataExchange domDataExchange; 30 private final DataExchange listDataExchange; 31 private final DataExchange mapDataExchange; 32 private final DataExchange primitiveDataExchange; 33 private final DataExchange complexDataExchange; 34 35 private TypeHandlerFactory typeHandlerFactory; 36 37 41 public DataExchangeFactory(TypeHandlerFactory typeHandlerFactory) { 42 this.typeHandlerFactory = typeHandlerFactory; 43 domDataExchange = new DomDataExchange(this); 44 listDataExchange = new ListDataExchange(this); 45 mapDataExchange = new ComplexDataExchange(this); 46 primitiveDataExchange = new PrimitiveDataExchange(this); 47 complexDataExchange = new ComplexDataExchange(this); 48 } 49 50 54 public TypeHandlerFactory getTypeHandlerFactory() { 55 return typeHandlerFactory; 56 } 57 58 63 public DataExchange getDataExchangeForClass(Class clazz) { 64 DataExchange dataExchange = null; 65 if (clazz == null) { 66 dataExchange = complexDataExchange; 67 } else if (DomTypeMarker.class.isAssignableFrom(clazz)) { 68 dataExchange = domDataExchange; 69 } else if (List .class.isAssignableFrom(clazz)) { 70 dataExchange = listDataExchange; 71 } else if (Map .class.isAssignableFrom(clazz)) { 72 dataExchange = mapDataExchange; 73 } else if (typeHandlerFactory.getTypeHandler(clazz) != null) { 74 dataExchange = primitiveDataExchange; 75 } else { 76 dataExchange = new JavaBeanDataExchange(this); 77 } 78 return dataExchange; 79 } 80 81 } 82 | Popular Tags |