1 16 package com.ibatis.sqlmap.engine.exchange; 17 18 import com.ibatis.sqlmap.engine.mapping.parameter.ParameterMap; 19 import com.ibatis.sqlmap.engine.mapping.parameter.ParameterMapping; 20 import com.ibatis.sqlmap.engine.mapping.result.ResultMap; 21 import com.ibatis.sqlmap.engine.mapping.result.ResultMapping; 22 import com.ibatis.sqlmap.engine.scope.RequestScope; 23 import com.ibatis.common.beans.ProbeFactory; 24 25 import java.util.ArrayList ; 26 import java.util.List ; 27 import java.util.Map ; 28 29 32 public class ListDataExchange extends BaseDataExchange implements DataExchange { 33 34 protected ListDataExchange(DataExchangeFactory dataExchangeFactory) { 35 super(dataExchangeFactory); 36 } 37 38 public void initialize(Map properties) { 39 } 40 41 public Object [] getData(RequestScope request, ParameterMap parameterMap, Object parameterObject) { 42 ParameterMapping[] mappings = parameterMap.getParameterMappings(); 43 Object [] data = new Object [mappings.length]; 44 for (int i = 0; i < mappings.length; i++) { 45 String propName = mappings[i].getPropertyName(); 46 47 String [] propertyArray = propName.split("\\."); 49 50 if(propertyArray.length > 0) { 51 53 Object tempData = parameterObject; 54 55 for(int x=0; x<propertyArray.length; x++) { 56 57 int arrayStartIndex = propertyArray[x].indexOf('['); 59 60 if(arrayStartIndex == -1) { 61 62 tempData = ProbeFactory.getProbe().getObject(tempData,propertyArray[x]); 64 65 } else { 66 67 int index = Integer.parseInt(propertyArray[x].substring(arrayStartIndex + 1, propertyArray[x].length() - 1)); 68 tempData = ((List ) tempData).get(index); 69 70 } 71 72 } 73 74 data[i] = tempData; 75 76 } else { 77 78 int index = Integer.parseInt((propName.substring(propName.indexOf('[') + 1, propName.length() - 1))); 79 data[i] = ((List ) parameterObject).get(index); 80 81 } 82 83 } 84 return data; 85 } 86 87 public Object setData(RequestScope request, ResultMap resultMap, Object resultObject, Object [] values) { 88 ResultMapping[] mappings = resultMap.getResultMappings(); 89 List data = new ArrayList (); 90 for (int i = 0; i < mappings.length; i++) { 91 String propName = mappings[i].getPropertyName(); 92 int index = Integer.parseInt((propName.substring(1, propName.length() - 1))); 93 data.set(index, values[i]); 94 } 95 return data; 96 } 97 98 public Object setData(RequestScope request, ParameterMap parameterMap, Object parameterObject, Object [] values) { 99 ParameterMapping[] mappings = parameterMap.getParameterMappings(); 100 List data = new ArrayList (); 101 for (int i = 0; i < mappings.length; i++) { 102 if (mappings[i].isOutputAllowed()) { 103 String propName = mappings[i].getPropertyName(); 104 int index = Integer.parseInt((propName.substring(1, propName.length() - 1))); 105 data.set(index, values[i]); 106 } 107 } 108 109 return data; 110 } 111 112 } 113 | Popular Tags |