KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > calipso > reportgenerator > reportmanager > DimensionValueTreeBuilder


1 package com.calipso.reportgenerator.reportmanager;
2 import com.calipso.reportgenerator.reportmanager.ReportData;
3 import com.calipso.reportgenerator.common.ReportQuery;
4 import com.calipso.reportgenerator.common.QueryDimension;
5 import com.calipso.reportgenerator.common.DimensionValueNode;
6 import java.util.ArrayList JavaDoc;
7 import java.util.Iterator JavaDoc;
8 import java.util.List JavaDoc;
9 import java.util.Map JavaDoc;
10 /**
11  * Esta clase se encarga de generar la estructura de nodos para poder dibujar y cargar los datos en las tablas
12  */

13
14 public class DimensionValueTreeBuilder {
15   private ReportData reportData;
16
17   /**
18    * Crea un objeto DimensionValueTreeBuilder a partir fde un ReportResult
19    * @param reportData
20    */

21   public DimensionValueTreeBuilder(ReportData reportData) {
22     setReportData(reportData);
23     initCubeProccess();
24   }
25   /**
26    *
27    */

28   private void initCubeProccess() {
29     List JavaDoc rows = getReportData().getQuery().getRowDimensions();
30     List JavaDoc cols = getReportData().getQuery().getColumnDimensions();
31     ArrayList JavaDoc prevDimensions;
32     ArrayList JavaDoc values;
33     prevDimensions = new ArrayList JavaDoc();
34     values = new ArrayList JavaDoc();
35     rowsRoot = new DimensionValueNode("ROWS");
36     rowsRoot.setDimensionCount(rows.size());
37     if (rows.size() > 0) {
38       fillSubNodes(rowsRoot, rows, prevDimensions, values, -1);
39     }
40     columnsRoot = new DimensionValueNode("COLUMNS");
41     columnsRoot.setDimensionCount(cols.size());
42     prevDimensions = new ArrayList JavaDoc();
43     values = new ArrayList JavaDoc();
44     if (cols.size() > 0) {
45       fillSubNodes(columnsRoot, cols, prevDimensions, values, rows.size() -1);
46     }
47   }
48   private DimensionValueNode rowsRoot;
49   private DimensionValueNode columnsRoot;
50   public DimensionValueNode getRowsRoot(){
51     return rowsRoot;
52   }
53
54   public DimensionValueNode getColumnsRoot(){
55     return columnsRoot;
56   }
57
58   private void fillSubNodes(DimensionValueNode parentNode, List JavaDoc dimensions, ArrayList JavaDoc prevDimensions, ArrayList JavaDoc prevDimensionValues, int index){
59     index++;
60     int currentDimension = index /*((QueryDimension)dimensions.get(prevDimensions.size())).getIndex()*/;
61     Iterator JavaDoc iterator = getReportData().valuesFor(currentDimension, arrayListToIntArray(prevDimensions), prevDimensionValues.toArray());
62     boolean lastDimension = prevDimensions.size() == dimensions.size() -1;
63     while (iterator.hasNext()){
64       Map.Entry JavaDoc current = (Map.Entry JavaDoc) iterator.next();
65       Object JavaDoc currentValue = current.getKey();
66       DimensionValueNode currentNode = new DimensionValueNode(currentValue, parentNode);
67       currentNode.setDimensionIndex(prevDimensions.size());
68       currentNode.setDimensionCount(parentNode.getDimensionCount() -1);
69       parentNode.addSubNode(currentNode);
70       prevDimensions.add(new Integer JavaDoc(currentDimension));
71 // prevDimensionValues.add(this.getReportData().getDefinition().getDimensionFromIndex(currentDimension).getVisualValue(currentValue));
72
prevDimensionValues.add(currentValue);
73       if (!lastDimension){
74         fillSubNodes(currentNode, dimensions, prevDimensions, prevDimensionValues, index);
75       }
76       prevDimensions.remove(prevDimensions.size()-1);
77       prevDimensionValues.remove(prevDimensionValues.size()-1);
78     }
79   }
80
81   private int[] arrayListToIntArray(ArrayList JavaDoc list){
82     int[] result = new int[list.size()];
83     for (int i = 0; i < list.size(); i++){
84       result[i] = ((Integer JavaDoc)list.get(i)).intValue();
85     }
86     return result;
87   }
88
89
90   public ReportData getReportData() {
91     return reportData;
92   }
93
94   public ReportQuery getQuery(){
95     return getReportData().getQuery();
96   }
97
98   public void setReportData(ReportData reportData) {
99     this.reportData = reportData;
100   }
101 }
Popular Tags