/** * getter 메소드를 생성하여 호출하고 값을 리턴 * * @param bean * @param beansPropertyName * @return * @throws Exception */ private Object callGetterMethod(BaseBean bean, String beansPropertyName) throws Exception { // bean.getClass().getDeclaredMethods()[0].getReturnType() return bean.getClass() .getMethod(getMethodName("get", beansPropertyName), new Class[0]) .invoke(bean, new Object[0]); }
/** * setter 메소드를 생성하여 호출 * * @param bean * @param beansPropertyName * @param columnValue * @throws Exception */ private void callSetterMethod(BaseBean bean, String beansPropertyName, Variant columnValue) throws Exception { // Class.getMethod('메소드명', '메소드에 넘겨줄 파라미터 타입들').invoke('실제 메소드를 호출할 인스턴스', '메소드에 넘겨줄 파라미터 값들'); bean.getClass() .getMethod(getMethodName("set", beansPropertyName), String.class) .invoke(bean, columnValue.getString()); }
/** * bean => dataset * * @param datasetList * @param bean * @param datasetName * @throws Exception */ public void beanToDataset(DatasetList datasetList, String datasetName, BaseBean bean) throws Exception { Dataset dataset = new Dataset(datasetName, PlatformResponse.CHARSET_EUC_KR, false, false); datasetList.addDataset(dataset); Map<String, String> datasetColumnNameMap = datasetColumnNameTable.get(bean.getClass().getName()); Object[] beanPropertyNameArray = datasetColumnNameMap.keySet().toArray(); for (Object beanPropertyName : beanPropertyNameArray) { dataset.addStringColumn(datasetColumnNameMap.get(beanPropertyName)); } Variant value = null; int rowIndex = dataset.appendRow(); for (Object beanPropertyName : beanPropertyNameArray) { value = new Variant(callGetterMethod(bean, (String) beanPropertyName)); dataset.setColumn(rowIndex, datasetColumnNameMap.get(beanPropertyName), value); } }