Source Code Cross Referenced for ReportFilterBuilder.java in  » Report » jmagallanes-1.0 » com » calipso » reportgenerator » common » 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.common 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package com.calipso.reportgenerator.common;
002:
003:        import com.calipso.reportgenerator.reportcalculator.ExpressionCubeFilter;
004:        import com.calipso.reportgenerator.reportcalculator.SharedDate;
005:        import com.calipso.reportgenerator.reportcalculator.SharedInteger;
006:        import com.calipso.reportgenerator.reportcalculator.SharedFloat;
007:        import com.calipso.reportgenerator.reportcalculator.expression.Expression;
008:        import com.calipso.reportgenerator.reportdefinitions.ParameterValues;
009:        import com.calipso.reportgenerator.reportdefinitions.ParameterValue;
010:        import com.calipso.reportgenerator.reportdefinitions.types.ReportDataType;
011:        import com.calipso.reportgenerator.common.ReportSpec;
012:        import com.calipso.reportgenerator.common.ReportFilter;
013:        import com.calipso.common.DateEx;
014:
015:        import java.util.*;
016:        import java.text.DateFormat;
017:        import java.text.SimpleDateFormat;
018:
019:        /**
020:         * Esta clase se utiliza para construir todos los filtros que se utilizan en la ejecución de un reporte, tanto los
021:         * pre-filtros, como los post-filtros, resolver los valores de parámetros.
022:         * Se encarga de procesar todos los objetos <code>ReportFilter</code> creados a partir de los <code>FilterDefinition</code>
023:         * del <code>ReportDefinition</code> y el <code>ReportSourceDefinition</code> y generar un objeto <code>CubeFilter</code>
024:         * que sirve para determinar si un registro del <code>DataSource</code> o de la <code>Matrix</code> del <code>ReportSource<code>
025:         * cumplen con todas las condiciones.
026:         * El objeto CubeFilter también es capaz de generar una condición para ser utilizada en una consulta OQL.
027:         * Provee mecanismos para consolidar los valores de los parámetros ingresados por el usuario y completarlos con los valores
028:         * de los parámetros que figuran el las definiciones correspondientes.
029:         */
030:        public class ReportFilterBuilder {
031:
032:            private List reportFilters;
033:            private Map paramValues;
034:            private int mode;
035:            public static final int VARMODE_INDEX = 0;
036:            public static final int VARMODE_DATAINDEX = 1;
037:            public static final int VARMODE_NAME = 2;
038:            public static final int VARMODE_EXTERNALDATA = 3;
039:
040:            /**
041:             * Constructor que inicializa el ReportFilterBuilder
042:             * @param reportFilters
043:             * @param paramValues
044:             * @param mode
045:             */
046:            public ReportFilterBuilder(List reportFilters, Map paramValues,
047:                    int mode) {
048:                this .paramValues = paramValues;
049:                this .reportFilters = reportFilters;
050:                this .mode = mode;
051:            }
052:
053:            /**
054:             * Devuelve un filtro para el cubo
055:             * @return
056:             */
057:            public ExpressionCubeFilter getCubeFilter(ReportSpec reportSpec,
058:                    ReportDataSourceSpec dataSourceSpec) throws InfoException {
059:                Expression exp = null;
060:                ExpressionCubeFilter cubeFilter = null;
061:                for (Iterator iterator = reportFilters.iterator(); iterator
062:                        .hasNext();) {
063:                    ReportFilter reportFilter = (ReportFilter) iterator.next();
064:                    String dimensionName = reportFilter.getFilterSpec()
065:                            .getDimensionName();
066:                    if (dimensionName != null
067:                            && !dimensionName.equalsIgnoreCase("")) {
068:                        Expression currentExp = reportFilter.getExpression(
069:                                paramValues, mode, reportSpec, dataSourceSpec,
070:                                reportFilter);
071:                        if (currentExp != null) {
072:                            if (exp == null) {
073:                                exp = currentExp;
074:                            } else {
075:                                exp = exp.newAnd(currentExp);
076:                            }
077:                        }
078:                    }
079:                }
080:                if (exp == null) { //!= null) {
081:                    //exp = new Expression();
082:                }
083:                cubeFilter = new ExpressionCubeFilter(exp, paramValues);
084:                //}
085:                return cubeFilter;
086:            }
087:
088:            /**
089:             * Sobrecarga los parameters values default con los valores del diccionario
090:             * @param values
091:             * @param defaultparameterValues
092:             * @return
093:             */
094:            public static Map mergeParamValues(Map values,
095:                    Map defaultparameterValues) {
096:                Map defParams;
097:                if (defaultparameterValues != null) {
098:                    defParams = defaultparameterValues;
099:                } else {
100:                    defParams = new HashMap();
101:                }
102:                Map returnValues = new HashMap();
103:                Iterator keys;
104:                if (values != null) {
105:                    keys = values.keySet().iterator();
106:                    while (keys.hasNext()) {
107:                        String key = (String) keys.next();
108:                        returnValues.put(key, values.get(key));
109:                    }
110:                }
111:                keys = defParams.keySet().iterator();
112:                while (keys.hasNext()) {
113:                    String key = (String) keys.next();
114:                    returnValues.put(key, defParams.get(key));
115:                }
116:                return returnValues;
117:            }
118:
119:            /**
120:             * Sobrecarga los parameters values default con los valores del diccionario
121:             * @param values
122:             * @param defaultParameterValues
123:             * @return
124:             */
125:            public static Map mergeParamValues(Map values,
126:                    ParameterValues defaultParameterValues) {
127:                return mergeParamValues(
128:                        values,
129:                        paramValuesDictFromParameterValues(defaultParameterValues));
130:            }
131:
132:            /**
133:             * Retorna un diccionario a partir de un ParameterValues
134:             * @param parameterValues
135:             * @return
136:             */
137:            private static Map paramValuesDictFromParameterValues(
138:                    ParameterValues parameterValues) {
139:                Map returnValues = new HashMap();
140:                if (parameterValues != null) {
141:                    for (int i = 0; i < parameterValues
142:                            .getParameterValueCount(); i++) {
143:                        ParameterValue parameterValue = parameterValues
144:                                .getParameterValue(i);
145:                        String parameterValueKey = parameterValue
146:                                .getFilterDefinitionName()
147:                                + parameterValue.getFilterParameter()
148:                                        .toString();
149:                        returnValues.put(parameterValueKey, parameterValue
150:                                .getDefaultValue());
151:                    }
152:                }
153:                return returnValues;
154:            }
155:
156:            public static Object getConstatValue(int mode, Object o,
157:                    ReportDataSourceSpec dataSourceSpec, int dataType) {
158:                switch (mode) {
159:                case VARMODE_INDEX:
160:                    return o;
161:                case VARMODE_DATAINDEX:
162:                    return o;
163:                case VARMODE_NAME:
164:                    return o;
165:                case VARMODE_EXTERNALDATA:
166:                    try {
167:                        return getExternalData(o, dataSourceSpec, dataType);
168:                    } catch (Exception e) {
169:                        //Este error se da para objetos "fecha". Puede ser un error de especificación de reporte
170:                        //Si ocurre, el objeto se guardará en su estado original, para no "romper" el reporte
171:                        e.printStackTrace();
172:                        return o;
173:                    }
174:                }
175:                return null;
176:            }
177:
178:            public static Object getExternalData(Object o,
179:                    ReportDataSourceSpec dataSourceSpec, int dataType)
180:                    throws InfoException {
181:                switch (dataType) {
182:                case ReportDataType.DATETIME_TYPE:
183:                case ReportDataType.DATE_TYPE:
184:                    if (o == "" && dataSourceSpec != null) {
185:                        return new String("' '");
186:                    } else if (dataSourceSpec != null) {
187:                        String formatedDate;
188:                        DateFormat dateFormat;
189:                        String pattern = dataSourceSpec.getPattern(dataType);
190:                        if (pattern != null && !pattern.equalsIgnoreCase("")) {
191:                            dateFormat = new SimpleDateFormat(pattern);
192:                        } else {
193:                            dateFormat = new SimpleDateFormat("yyyyMMdd");
194:                        }
195:                        if (o instanceof  SharedDate) {
196:                            formatedDate = dateFormat.format(((SharedDate) o)
197:                                    .getDateEx().getDate());
198:                        } else if (o instanceof  Date) {
199:                            formatedDate = dateFormat.format((Date) o);
200:                        } else {
201:                            formatedDate = dateFormat.format(new DateEx(o
202:                                    .toString()).getDate());
203:                        }
204:                        return new String("'" + formatedDate + "'");
205:                    } else {
206:                        DateFormat dateFormat;
207:                        if (dataType == ReportDataType.DATETIME_TYPE) {
208:                            dateFormat = new SimpleDateFormat(
209:                                    "yyyyMMddHHmmssSSS");
210:                        } else {
211:                            dateFormat = new SimpleDateFormat("yyyyMMdd");
212:                        }
213:                        Date date = (new DateEx(o.toString())).getDate();
214:                        return dateFormat.format(date);
215:                    }
216:                case ReportDataType.STRING_TYPE:
217:                    String value = o.toString().replaceAll("'", "''");
218:                    return new String("'" + value + "'");
219:                case ReportDataType.INTEGER_TYPE:
220:                    return ((SharedInteger) o).getValue();
221:                case ReportDataType.FLOAT_TYPE:
222:                    return ((SharedFloat) o).getValue();
223:                case ReportDataType.BOOLEAN_TYPE:
224:                    return ((Boolean) o).toString();
225:                }
226:                return null;
227:            }
228:
229:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.