- if (log.isDebugEnabled())
- log
- .debug("Instantiate objects of sheet "
- + sheet.getName());
-
- Cell[] firstRow = sheet.getRow(0);
-
- // TODO: ability to map sheet names and class names
- String className = sheet.getName();
- Class<?> clss = classLoader.loadClass(className);
- model.put(clss, new HashMap<Object, Object>());
-
- tempRefs.put(sheet.getName(), new ArrayList<Object>());
-
- String keyProperty = firstRow[0].getContents();
- for (int i = 1; i < sheet.getRows(); i++) {
- if (log.isTraceEnabled())
- log.trace(" row " + i);
-
- Cell[] currentRow = sheet.getRow(i);
- BeanWrapper bw = new BeanWrapperImpl(clss);
- for (int j = 0; j < firstRow.length; j++) {
- String pName = firstRow[j].getContents();
-
- Cell cell = currentRow[j];
- if (cell instanceof FormulaCell) {
- String formula = ((FormulaCell) cell).getFormula();
- int index = formula.indexOf('!');
- String targetSheet = formula.substring(0, index);
- // assume no double letters
- Integer targetRow = Integer.parseInt(formula
- .substring(index + 2));
- links.add(new Link(bw.getWrappedInstance(), pName,
- targetSheet, targetRow));
-
- if (log.isTraceEnabled())
- log.debug(" formula: " + formula
- + " | content: " + cell.getContents()
- + " | targetSheet=" + targetSheet
- + ", targetRow=" + targetRow);
- } else {
- bw.setPropertyValue(pName, cell.getContents());
-
- if (log.isTraceEnabled())
- log.debug(" " + pName + "="
- + cell.getContents());
- }
- }// properties set
-
- model.get(clss).put(bw.getPropertyValue(keyProperty),
- bw.getWrappedInstance());
- tempRefs.get(sheet.getName()).add(bw.getWrappedInstance());
+ loadSheet(sheet, references, tempRefs);
+ }
+ } catch (Exception e) {
+ throw new ArgeoServerException("Cannot load workbook", e);
+ }
+ }
+
+ protected void loadSheet(Sheet sheet, List<Reference> references,
+ Map<String, List<Object>> tempRefs) throws JXLException {
+ if (log.isTraceEnabled())
+ log.debug("Instantiate sheet " + sheet.getName());
+
+ Cell[] firstRow = sheet.getRow(0);
+
+ Class<?> clss = findClassToInstantiate(sheet);
+ model.put(clss, new TreeMap<Object, Object>());
+
+ tempRefs.put(sheet.getName(), new ArrayList<Object>());
+
+ String keyProperty = firstRow[0].getContents();
+ for (int row = 1; row < sheet.getRows(); row++) {
+ if (log.isTraceEnabled())
+ log.trace(" row " + row);
+
+ Cell[] currentRow = sheet.getRow(row);
+ BeanWrapper bw = new BeanWrapperImpl(clss);
+ cells: for (int col = 0; col < firstRow.length; col++) {
+ String pName = firstRow[col].getContents();
+
+ if (col < currentRow.length) {
+ Cell cell = currentRow[col];
+ if (overrideCell(cell, bw, pName, keyProperty, row,
+ references, tempRefs))
+ continue cells;
+ loadCell(cell, bw, pName, keyProperty, row, references);