Source Code Cross Referenced for FormatParser.java in  » Report » pentaho-report » org » jfree » report » filter » 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 » pentaho report » org.jfree.report.filter 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * ===========================================
003:         * JFreeReport : a free Java reporting library
004:         * ===========================================
005:         *
006:         * Project Info:  http://reporting.pentaho.org/
007:         *
008:         * (C) Copyright 2001-2007, by Object Refinery Ltd, Pentaho Corporation and Contributors.
009:         *
010:         * This library is free software; you can redistribute it and/or modify it under the terms
011:         * of the GNU Lesser General Public License as published by the Free Software Foundation;
012:         * either version 2.1 of the License, or (at your option) any later version.
013:         *
014:         * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
015:         * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
016:         * See the GNU Lesser General Public License for more details.
017:         *
018:         * You should have received a copy of the GNU Lesser General Public License along with this
019:         * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
020:         * Boston, MA 02111-1307, USA.
021:         *
022:         * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
023:         * in the United States and other countries.]
024:         *
025:         * ------------
026:         * FormatParser.java
027:         * ------------
028:         * (C) Copyright 2001-2007, by Object Refinery Ltd, Pentaho Corporation and Contributors.
029:         */package org.jfree.report.filter;
030:
031:        import java.text.Format;
032:        import java.text.ParseException;
033:
034:        import org.jfree.report.function.ExpressionRuntime;
035:
036:        /**
037:         * A format parser tries to parse a string into an object. If the value returned by the datasource is no string, a
038:         * string is formed using String.valueOf (Object). This string is fed into the java.text.Format of this FormatParser and
039:         * the parsed object is returned.
040:         * <p/>
041:         * What class of object is returned, is determined by the given format. If parsing failed, the defined NullValue is
042:         * returned.
043:         *
044:         * @author Thomas Morgner
045:         */
046:        public class FormatParser implements  DataFilter {
047:            /**
048:             * The format used to create the string representation of the data.
049:             */
050:            private Format format;
051:
052:            /**
053:             * The datasource from where the data is obtained.
054:             */
055:            private DataSource datasource;
056:
057:            /**
058:             * The object used to represent null.
059:             */
060:            private Object nullvalue;
061:
062:            /**
063:             * DefaultConstructor.
064:             */
065:            public FormatParser() {
066:            }
067:
068:            /**
069:             * Sets the format for the filter.
070:             *
071:             * @param format The format.
072:             * @throws NullPointerException if the given format is null
073:             */
074:            public void setFormatter(final Format format) {
075:                if (format == null) {
076:                    throw new NullPointerException();
077:                }
078:                this .format = format;
079:            }
080:
081:            /**
082:             * Returns the format for the filter.
083:             *
084:             * @return The format.
085:             */
086:            public Format getFormatter() {
087:                return this .format;
088:            }
089:
090:            /**
091:             * Returns the parsed object. The value is read using the data source given and parsed using the formatter of this
092:             * object. The parsing is guaranteed to completly form the target object or to return the defined NullValue.
093:             * <p/>
094:             * If the given datasource does not return a string, the returned object is transformed into a string using
095:             * String.valueOf (Object) and then parsed.
096:             * <p/>
097:             * If format, datasource or object are null, the NullValue is returned.
098:             *
099:             * @param runtime the expression runtime that is used to evaluate formulas and expressions when computing the value of
100:             *                this filter.
101:             * @return The formatted value.
102:             */
103:            public Object getValue(final ExpressionRuntime runtime) {
104:                final Format f = getFormatter();
105:                if (f == null) {
106:                    return getNullValue();
107:                }
108:
109:                final DataSource ds = getDataSource();
110:                if (ds == null) {
111:                    return getNullValue();
112:                }
113:
114:                final Object o = ds.getValue(runtime);
115:                if (o == null) {
116:                    return getNullValue();
117:                }
118:
119:                if (isValidOutput(o)) {
120:                    return o;
121:                }
122:
123:                try {
124:                    return f.parseObject(String.valueOf(o));
125:                } catch (ParseException e) {
126:                    return null;
127:                }
128:            }
129:
130:            /**
131:             * Checks whether the given value is already a valid result. IF the datasource already returned a valid value, and no
132:             * parsing is required, a parser can skip the parsing process by returning true in this function.
133:             *
134:             * @param o the object to parse.
135:             * @return false as this class does not know anything about the format of input or result objects.
136:             */
137:            protected boolean isValidOutput(final Object o) {
138:                return false;
139:            }
140:
141:            /**
142:             * Returns the data source for the filter.
143:             *
144:             * @return The data source.
145:             */
146:            public DataSource getDataSource() {
147:                return datasource;
148:            }
149:
150:            /**
151:             * Sets the data source.
152:             *
153:             * @param ds The data source.
154:             */
155:            public void setDataSource(final DataSource ds) {
156:                if (ds == null) {
157:                    throw new NullPointerException();
158:                }
159:                this .datasource = ds;
160:            }
161:
162:            /**
163:             * Sets the value that will be displayed if the data source supplies a null value. The nullValue itself can be null to
164:             * cover the case when no reasonable default value can be defined.
165:             *
166:             * @param nullvalue The value returned when the parsing failed.
167:             */
168:            public void setNullValue(final Object nullvalue) {
169:                this .nullvalue = nullvalue;
170:            }
171:
172:            /**
173:             * Returns the object representing a null value from the data source. This value will also be returned when parsing
174:             * failed or no parser or datasource is set at all.
175:             *
176:             * @return The value returned when the parsing failed.
177:             */
178:            public Object getNullValue() {
179:                return nullvalue;
180:            }
181:
182:            /**
183:             * Clones the parser.
184:             *
185:             * @return a clone.
186:             * @throws CloneNotSupportedException this should never happen.
187:             */
188:            public Object clone() throws CloneNotSupportedException {
189:                final FormatParser p = (FormatParser) super .clone();
190:                if (datasource != null) {
191:                    p.datasource = (DataSource) datasource.clone();
192:                }
193:                if (format != null) {
194:                    p.format = (Format) format.clone();
195:                }
196:                return p;
197:            }
198:
199:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.