+ protected void loadAsObject(BeanWrapper bw, Sheet sheet,
+ List<Reference> references) {
+ Cell[] firstColumn = sheet.getColumn(0);
+ for (int row = 0; row < firstColumn.length; row++) {
+ if (log.isTraceEnabled())
+ log.trace(" row " + row);
+ Cell[] currentRow = sheet.getRow(row);
+ String propertyName = firstColumn[row].getContents();
+ Class<?> rowType = bw.getPropertyType(propertyName);
+ if (Map.class.isAssignableFrom(rowType)) {
+ Map<Object, Object> map = new HashMap<Object, Object>();
+ if (currentRow.length == 1
+ || currentRow[1].getContents().trim().equals("")) {
+ // simple map
+ } else {
+ // map of maps
+ List<Object> subKeys = new ArrayList<Object>();
+ for (int col = 1; col < currentRow.length; col++) {
+ subKeys.add(getCellValue(currentRow[col]));
+ }
+ if (log.isTraceEnabled())
+ log.trace(" subKeys=" + subKeys);
+ row++;
+ String firstColContents = firstColumn[row].getContents();
+ mapRows: for (; row < firstColumn.length; row++) {
+ currentRow = sheet.getRow(row);
+
+ Object key = firstColContents;
+ Map<Object, Object> subMap = new HashMap<Object, Object>();
+
+ for (int col = 1; col < currentRow.length
+ && col < subKeys.size() + 1; col++) {
+ Object subKey = subKeys.get(col - 1);
+ Cell cell = currentRow[col];
+ if (log.isTraceEnabled())
+ log.trace(" row=" + row
+ + ", firstColContents="
+ + firstColContents + ", subKey="
+ + subKey + ", type=" + cell.getType());
+ Object cellValue = getCellValue(cell);
+ subMap.put(subKey, cellValue);
+ }
+ map.put(key, subMap);
+
+ // check next row too see if one should break
+ if (row < firstColumn.length - 1)
+ firstColContents = firstColumn[row + 1]
+ .getContents();
+ if (bw.isWritableProperty(firstColContents)
+ || firstColContents.trim().equals("")
+ || row == firstColumn.length - 1) {
+ log.trace(map);
+ bw.setPropertyValue(propertyName, map);
+ if (log.isTraceEnabled())
+ log.trace(" set map " + propertyName
+ + " of size " + map.size());
+ break mapRows;// map is over
+ }
+ }
+
+ }
+ } else if (List.class.isAssignableFrom(rowType)) {
+ throw new UnsupportedOperationException();
+ } else {
+ bw.setPropertyValue(propertyName, getCellValue(currentRow[1]));
+ }
+ }
+ }
+