+ for (int col = 1; col < firstRow.length; col++) {
+ if (log.isTraceEnabled())
+ log.trace(" column " + col);
+ BeanWrapper bw = newBeanWrapper(clss);
+ Cell[] column = sheet.getColumn(col);
+ for (int row = 0; row < column.length; row++) {
+ Cell cell = column[row];
+
+ String propertyName;
+ if (row == 0)
+ propertyName = keyProperty;
+ else
+ propertyName = firstColumn[row].getContents();
+
+ Class<?> rowType = bw.getPropertyType(propertyName);
+ if (log.isTraceEnabled())
+ log.trace(" " + propertyName + " rowType="
+ + rowType.getName());
+ if (Map.class.isAssignableFrom(rowType)) {
+ if (log.isTraceEnabled())
+ log.trace(" start building map " + propertyName);
+ row++;
+ Map<Object, Object> map = new HashMap<Object, Object>();
+ String firstColContents = firstColumn[row].getContents();
+ mapRows: for (; row < column.length; row++) {
+ cell = column[row];
+ Object key = firstColContents;
+ if (log.isTraceEnabled())
+ log.trace(" row=" + row + ", firstColContents="
+ + firstColContents + ", key=" + key
+ + ", type=" + cell.getType());
+ Object cellValue = getCellValue(cell);
+ map.put(key, cellValue);
+
+ // 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) {
+ bw.setPropertyValue(propertyName, map);
+ if (log.isTraceEnabled())
+ log.trace(" set map " + propertyName
+ + " of size " + map.size());
+ break mapRows;// map is over
+ }
+ }
+ } else {
+ loadCell(cell, bw, propertyName, keyProperty, row,
+ references);
+ }
+
+ }
+ saveOrUpdate(bw.getPropertyValue(keyProperty), bw
+ .getWrappedInstance(), clss);
+ // tempRefs.get(sheet.getName()).add(bw.getWrappedInstance());
+ registerInTabularView(sheet.getName(), bw.getWrappedInstance());
+ }// columns
+ }
+
+ 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]));
+ }
+ 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 = 0; col < currentRow.length
+ && col < subKeys.size(); col++) {
+ Object subKey = subKeys.get(col);
+ 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) {
+ 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]));
+ }
+ }