Source Code Cross Referenced for DataVectorBuilder.java in  » Report » jmagallanes-1.0 » com » calipso » reportgenerator » reportmanager » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Report » jmagallanes 1.0 » com.calipso.reportgenerator.reportmanager 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package com.calipso.reportgenerator.reportmanager;
002:
003:        import com.calipso.reportgenerator.reportmanager.ReportData;
004:        import com.calipso.reportgenerator.common.QueryDimension;
005:        import com.calipso.reportgenerator.common.ReportQuery;
006:        import com.calipso.reportgenerator.common.DimensionValueNode;
007:        import com.calipso.reportgenerator.common.HeaderTableModel;
008:        import com.calipso.reportgenerator.reportcalculator.SharedFloat;
009:
010:        import javax.swing.table.TableModel;
011:        import javax.swing.table.DefaultTableModel;
012:        import java.util.Vector;
013:        import java.util.Collection;
014:        import java.util.Iterator;
015:        import java.io.Serializable;
016:
017:        public class DataVectorBuilder implements  Serializable {
018:
019:            private DimensionValueNode rowsRoot;
020:            private DimensionValueNode colsRoot;
021:            private ReportData reportData;
022:            private Vector dataVector;
023:            private boolean withTotals;
024:            private int rowCount;
025:            private int colCount;
026:            private int[] metrics;
027:            private int[] groupingDimensions;
028:            private Float tempFloat = new Float(0);
029:
030:            public DataVectorBuilder(DimensionValueNode rowsRoot,
031:                    DimensionValueNode colsRoot, ReportQuery reportQuery,
032:                    ReportData reportData, boolean withTotals) {
033:                this .rowsRoot = rowsRoot;
034:                this .colsRoot = colsRoot;
035:                this .reportData = reportData;
036:                this .withTotals = withTotals;
037:                this .metrics = reportQuery.getCubeVisibleMetricFields();
038:                getDataVector();
039:            }
040:
041:            public Vector getDataVector() {
042:                if (dataVector == null) {
043:                    dataVector = new Vector();
044:                    fill();
045:                }
046:                return dataVector;
047:            }
048:
049:            private void fill() {
050:                DimensionNodeIterator rowsIterator = new DimensionNodeIterator(
051:                        rowsRoot, withTotals);
052:                if (rowsRoot.getDimensionCount() == 0) {
053:                    Object[] rowHeaders = new Object[0];
054:                    DimensionNodeIterator colsIterator = new DimensionNodeIterator(
055:                            colsRoot, withTotals);
056:                    Vector dataValues = new Vector();
057:                    if (colsRoot.getDimensionCount() == 0) {
058:                        fillValue(dataValues, rowHeaders, new Object[0]);
059:                    } else {
060:                        while (colsIterator.hasNext()) {
061:                            Object[] colHeaders = (Object[]) colsIterator
062:                                    .next();
063:                            fillValue(dataValues, rowHeaders, colHeaders);
064:                        }
065:                    }
066:                    dataVector.add(dataValues);
067:                    rowCount++;
068:                } else {
069:                    while (rowsIterator.hasNext()) {
070:                        Object[] rowHeaders = (Object[]) rowsIterator.next();
071:                        DimensionNodeIterator colsIterator = new DimensionNodeIterator(
072:                                colsRoot, withTotals);
073:                        Vector dataValues = new Vector();
074:                        if (colsRoot.getDimensionCount() == 0) {
075:                            fillValue(dataValues, rowHeaders, new Object[0]);
076:                        } else {
077:                            while (colsIterator.hasNext()) {
078:                                Object[] colHeaders = (Object[]) colsIterator
079:                                        .next();
080:                                fillValue(dataValues, rowHeaders, colHeaders);
081:                            }
082:                        }
083:                        dataVector.add(dataValues);
084:                        rowCount++;
085:                    }
086:                }
087:            }
088:
089:            private boolean isTotal(Object[] rowHeaders, Object[] colHeaders) {
090:                return (rowHeaders.length > 0 && rowHeaders[rowHeaders.length - 1] == null)
091:                        || (colHeaders.length > 0 && colHeaders[colHeaders.length - 1] == null);
092:            }
093:
094:            private int[] getMetrics() {
095:                return metrics;
096:            }
097:
098:            private void fillValue(Vector dataValues, Object[] rowHeaders,
099:                    Object[] colHeaders) {
100:                Object[] values = new Object[rowHeaders.length
101:                        + colHeaders.length];
102:                System.arraycopy(rowHeaders, 0, values, 0, rowHeaders.length);
103:                System.arraycopy(colHeaders, 0, values, rowHeaders.length,
104:                        colHeaders.length);
105:                Object[] metricValues;
106:                if (isTotal(rowHeaders, colHeaders)) {
107:                    //llenar con dimensiones y valores que no son null
108:                    Object[] params = getNotNullParams(values);
109:                    int[] dimensions = (int[]) params[0];
110:                    Object[] dimValues = (Object[]) params[1];
111:                    //metricValues = reportData.measuresAtDimensionsValues(dimensions, dimValues);
112:                    metricValues = reportData.getMetricValues(dimensions,
113:                            dimValues);
114:                } else {
115:                    //metricValues = reportData.measuresAtDimensionsValues(getGroupingDimensionsIndexArray(), values);
116:                    metricValues = reportData.getMetricValues(
117:                            getGroupingDimensionsIndexArray(), values);
118:                }
119:                if (metricValues == null) {
120:                    for (int i = 0; i < getMetrics().length; i++) {
121:                        Object value = null;//SharedFloat.newFrom(tempFloat);
122:                        dataValues.add(value);
123:                        if (rowCount == 0)
124:                            colCount++;
125:                    }
126:                } else {
127:                    for (int i = 0; i < getMetrics().length; i++) {
128:                        int metricIndex = getMetrics()[i]
129:                                - this .reportData.getQuery().getReportSpec()
130:                                        .getDimensions().length
131:                                + this .getGroupingDimensionsIndexArray().length;
132:                        Object value = metricValues[metricIndex];
133:                        dataValues.add(value);
134:                        if (rowCount == 0)
135:                            colCount++;
136:                    }
137:                }
138:            }
139:
140:            private int[] getGroupingDimensionsIndexArray() {
141:                if (groupingDimensions == null) {
142:                    //groupingDimensions = reportData.getQuery().getGroupingDimensionsIndexArray();
143:                    groupingDimensions = ((CubeReportData) reportData)
144:                            .getCube()
145:                            .getIntegerArray(
146:                                    0,
147:                                    reportData.getQuery()
148:                                            .getGroupingDimensionsIndexArray().length);
149:                }
150:                return groupingDimensions;
151:            }
152:
153:            private Object[] getNotNullParams(Object[] values) {
154:                Object[] result = new Object[2];
155:                Vector notNullDims = new Vector();
156:                Vector notNullValues = new Vector();
157:                for (int i = 0; i < values.length; i++) {
158:                    Object value = values[i];
159:                    if (value != null) {
160:                        notNullValues.add(value);
161:                        notNullDims.add(dimensionFromValuesIndex(i));
162:                    }
163:                }
164:                result[0] = toIntArray(notNullDims);
165:                result[1] = notNullValues.toArray();
166:                return result;
167:            }
168:
169:            private int[] toIntArray(Collection selectedDimensions) {
170:                int[] result;
171:                int index;
172:                Iterator iterator;
173:                int selectedDimensionsSize = selectedDimensions.size();
174:                result = new int[selectedDimensionsSize];
175:                iterator = selectedDimensions.iterator();
176:                for (index = 0; index < selectedDimensionsSize; index++) {
177:                    result[index] = ((Integer) iterator.next()).intValue();
178:                }
179:                return result;
180:            }
181:
182:            private Integer dimensionFromValuesIndex(int index) {
183:                return new Integer(index); /*int rowsCount = rowsRoot.getDimensionCount();
184:                   if (rowsCount == 0) {
185:                     //return new Integer(cube.getQuery().getColumns()[index]);
186:                     return new Integer(((QueryDimension)reportData.getQuery().getColumnDimensions().get(index)).getIndex());
187:                   }
188:                   else {
189:                   if (index >= rowsCount) {
190:                     //return new Integer(cube.getQuery().getColumns()[index - Math.max(rowsCount, 1)]);
191:                     return new Integer(((QueryDimension)reportData.getQuery().getColumnDimensions().get(index - Math.max(rowsCount, 1))).getIndex());
192:                   }
193:                   else {
194:                     //return new Integer(cube.getQuery().getRows()[index]);
195:                     return new Integer(((QueryDimension)reportData.getQuery().getRowDimensions().get(index)).getIndex());
196:                   }
197:                   }*/
198:            }
199:
200:            public void invalidate() {
201:                dataVector = null;
202:                colCount = 0;
203:                rowCount = 0;
204:            }
205:
206:            public Vector getNames() {
207:                Vector names = new Vector(getColCount());
208:                for (int i = 0; i < getColCount(); i++) {
209:                    names.add(String.valueOf(i));
210:                }
211:                return names;
212:            }
213:
214:            public int getRowCount() {
215:                return Math.max(rowCount, 1);
216:            }
217:
218:            public int getColCount() {
219:                return Math.max(colCount, 1);
220:            }
221:
222:            public TableModel getDataModel() {
223:                return new DefaultTableModel(getDataVector(), getNames());
224:            }
225:
226:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.