Source Code Cross Referenced for ExpressionCollection.java in  » Report » pentaho-report » org » jfree » report » function » 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.function 
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:         * ExpressionCollection.java
027:         * ------------
028:         * (C) Copyright 2001-2007, by Object Refinery Ltd, Pentaho Corporation and Contributors.
029:         */package org.jfree.report.function;
030:
031:        import java.io.Serializable;
032:        import java.util.ArrayList;
033:        import java.util.Collection;
034:        import java.util.Collections;
035:        import java.util.Iterator;
036:        import java.util.List;
037:
038:        /**
039:         * Collects all expressions used in the report. There exist 2 states of the ExpressionCollection. In the first,
040:         * modifiable state, expressions can be added to the collection. During the adding the expressions get initialized. An
041:         * ExpressionCollection in this state is not able to connect to an DataRow.
042:         * <p/>
043:         * The second state is an immutable state of this collection, no expressions can be added or removed.  This
044:         * ReadOnlyExpressionCollection can be created by calling getCopy() on the first-state expression collection. The
045:         * ReadOnlyExpressionCollection is able to connect to a DataRow.
046:         *
047:         * @author Thomas Morgner
048:         */
049:        public class ExpressionCollection implements  Cloneable, Serializable {
050:            /**
051:             * Ordered storage for the Expressions.
052:             */
053:            private ArrayList expressionList;
054:
055:            /**
056:             * Creates a new expression collection (initially empty).
057:             */
058:            public ExpressionCollection() {
059:                expressionList = new ArrayList();
060:            }
061:
062:            /**
063:             * Creates a new expression collection, populated with the supplied expressions.
064:             *
065:             * @param expressions a collection of expressions.
066:             * @throws ClassCastException if the collection does not contain Expressions
067:             */
068:            public ExpressionCollection(final Collection expressions) {
069:                this ();
070:                addAll(expressions);
071:            }
072:
073:            /**
074:             * Adds all expressions contained in the given collection to this expression collection. The expressions get
075:             * initialized during the adding process.
076:             *
077:             * @param expressions the expressions to be added.
078:             * @throws ClassCastException if the collection does not contain expressions
079:             */
080:            public void addAll(final Collection expressions) {
081:                if (expressions != null) {
082:                    final Iterator iterator = expressions.iterator();
083:                    while (iterator.hasNext()) {
084:                        final Expression f = (Expression) iterator.next();
085:                        add(f);
086:                    }
087:                }
088:            }
089:
090:            /**
091:             * Returns the {@link Expression} with the specified name (or <code>null</code>).
092:             *
093:             * @param name the expression name (<code>null</code> not permitted).
094:             * @return The expression.
095:             * @throws NullPointerException if the name given is <code>null</code>.
096:             */
097:            public Expression get(final String name) {
098:                if (name == null) {
099:                    throw new NullPointerException();
100:                }
101:
102:                final int position = findExpressionByName(name);
103:                if (position == -1) {
104:                    return null;
105:                }
106:                return getExpression(position);
107:            }
108:
109:            /**
110:             * Searches the list of expressions for an expression with the given name.
111:             *
112:             * @param name the name, never null.
113:             * @return the position of the expression with that name or -1 if no expression contains that name.
114:             */
115:            private int findExpressionByName(final String name) {
116:                for (int i = 0; i < expressionList.size(); i++) {
117:                    final Expression expression = (Expression) expressionList
118:                            .get(i);
119:                    if (name.equals(expression.getName())) {
120:                        return i;
121:                    }
122:                }
123:                return -1;
124:            }
125:
126:            /**
127:             * Adds an expression to the collection.  The expression is initialized before it is added to this collection.
128:             *
129:             * @param e the expression.
130:             */
131:            public void add(final Expression e) {
132:                if (e == null) {
133:                    throw new NullPointerException("Expression is null");
134:                }
135:
136:                final int position = findExpressionByName(e.getName());
137:                if (position == -1) {
138:                    privateAdd(e);
139:                    return;
140:                }
141:
142:                removeExpression(e);
143:                privateAdd(e);
144:            }
145:
146:            /**
147:             * Adds an expression to the collection.
148:             *
149:             * @param e the expression.
150:             * @throws NullPointerException if the given Expression is null.
151:             */
152:            protected void privateAdd(final Expression e) {
153:                expressionList.add(e);
154:            }
155:
156:            /**
157:             * Removes an expression from the collection.
158:             *
159:             * @param e the expression.
160:             * @throws NullPointerException if the given Expression is null.
161:             */
162:            public void removeExpression(final Expression e) {
163:                final int position = findExpressionByName(e.getName());
164:                if (position == -1) {
165:                    return;
166:                }
167:                expressionList.remove(position);
168:            }
169:
170:            /**
171:             * Returns the number of active expressions in this collection.
172:             *
173:             * @return the number of expressions in this collection
174:             */
175:            public int size() {
176:                return expressionList.size();
177:            }
178:
179:            /**
180:             * Returns the expression on the given position in the list.
181:             *
182:             * @param pos the position in the list.
183:             * @return the expression.
184:             * @throws IndexOutOfBoundsException if the given position is invalid
185:             */
186:            public Expression getExpression(final int pos) {
187:                return (Expression) expressionList.get(pos);
188:            }
189:
190:            /**
191:             * Clones this expression collection and all expressions contained in the collection.
192:             *
193:             * @return The clone.
194:             * @throws CloneNotSupportedException should never happen.
195:             */
196:            public Object clone() throws CloneNotSupportedException {
197:                final ExpressionCollection col = (ExpressionCollection) super 
198:                        .clone();
199:                col.expressionList = (ArrayList) expressionList.clone();
200:                col.expressionList.clear();
201:
202:                try {
203:                    final Iterator it = expressionList.iterator();
204:                    while (it.hasNext()) {
205:                        final Expression ex = (Expression) it.next();
206:                        col.privateAdd(ex.getInstance());
207:                    }
208:                } catch (Exception e) {
209:                    throw new CloneNotSupportedException(
210:                            "Unable to clone an expression");
211:                }
212:                return col;
213:            }
214:
215:            /**
216:             * Returns the expressions contained in this collection as unmodifiable list.
217:             *
218:             * @return the expressions as list.
219:             * @deprecated This functionality will be removed. Use the array-version instead.
220:             */
221:            public List getExpressionList() {
222:                return Collections.unmodifiableList(expressionList);
223:            }
224:
225:            /**
226:             * Return all expressions contained in this collection as array.
227:             *
228:             * @return the expressions as array.
229:             */
230:            public Expression[] getExpressions() {
231:                return (Expression[]) expressionList
232:                        .toArray(new Expression[expressionList.size()]);
233:            }
234:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.