Source Code Cross Referenced for ExpressionList.java in  » Development » JoSQL » org » josql » expressions » 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 » Development » JoSQL » org.josql.expressions 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2004-2007 Gary Bentley 
003:         * 
004:         * Licensed under the Apache License, Version 2.0 (the "License"); you may 
005:         * not use this file except in compliance with the License. 
006:         * You may obtain a copy of the License at 
007:         *    http://www.apache.org/licenses/LICENSE-2.0 
008:         *
009:         * Unless required by applicable law or agreed to in writing, software 
010:         * distributed under the License is distributed on an "AS IS" BASIS, 
011:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
012:         * See the License for the specific language governing permissions and 
013:         * limitations under the License.
014:         */
015:        package org.josql.expressions;
016:
017:        import java.util.List;
018:        import java.util.ArrayList;
019:
020:        import org.josql.Query;
021:        import org.josql.QueryExecutionException;
022:        import org.josql.QueryParseException;
023:
024:        /**
025:         * This class represents a list of expressions used within a SQL statement.
026:         * <p>
027:         * Expressions lists are created using pairs of "[]" brackets, i.e.
028:         * <pre>
029:         *  [toString, 10, true]
030:         * </pre>
031:         * Would create a list of expressions that should be treated as a unit.
032:         * <p>
033:         * Since expression lists are also expressions it is possible to nest them to the nth degree, if desired.
034:         * i.e.
035:         * <pre>
036:         *  [toString, [1, 2, 3, 4], [true, true]]
037:         * </pre>
038:         */
039:        public class ExpressionList extends ValueExpression {
040:
041:            private List expressions = null;
042:
043:            /**
044:             * Get the expected return type, which is {@link List}.
045:             *
046:             * @param q The Query object.
047:             * @return {@link List}.
048:             */
049:            public Class getExpectedReturnType(Query q) {
050:
051:                return List.class;
052:
053:            }
054:
055:            /**
056:             * Initialises this expression list, each expression in the list is inited.
057:             *
058:             * @param q The Query object.
059:             * @throws QueryParseException If one of the expressions cannot be inited.
060:             */
061:            public void init(Query q) throws QueryParseException {
062:
063:                for (int i = 0; i < this .expressions.size(); i++) {
064:
065:                    Expression exp = (Expression) this .expressions.get(i);
066:
067:                    exp.init(q);
068:
069:                }
070:
071:            }
072:
073:            /**
074:             * Returns the expressions, a list of {@link Expression} objects.
075:             *
076:             * @return The expressions.
077:             */
078:            public List getExpressions() {
079:
080:                return this .expressions;
081:
082:            }
083:
084:            /**
085:             * Add an expression to the list.
086:             *
087:             * @param expr The expression.
088:             */
089:            public void addExpression(Expression expr) {
090:
091:                if (this .expressions == null) {
092:
093:                    this .expressions = new ArrayList();
094:
095:                }
096:
097:                this .expressions.add(expr);
098:
099:            }
100:
101:            /**
102:             * Set the expressions.
103:             *
104:             * @param exprs The expressions.
105:             */
106:            public void setExpressions(List exprs) {
107:
108:                this .expressions = exprs;
109:
110:            }
111:
112:            /**
113:             * Gets the value of the expressions, this will return a list of the values for
114:             * each of the expressions in the list.  In essence {@link Expression#getValue(Object,Query)}
115:             * is called on each of the expressions.
116:             *
117:             * @param o The current object.  
118:             * @param q The Query object.
119:             * @return A list of the values, if there are no expressions in the list then an empty list is returned.
120:             * @throws QueryExecutionException If something goes wrong the acquisition of the values.
121:             */
122:            public Object getValue(Object o, Query q)
123:                    throws QueryExecutionException {
124:
125:                List ret = new ArrayList();
126:
127:                for (int i = 0; i < this .expressions.size(); i++) {
128:
129:                    Expression exp = (Expression) this .expressions.get(i);
130:
131:                    ret.add(exp.getValue(o, q));
132:
133:                }
134:
135:                return ret;
136:
137:            }
138:
139:            /**
140:             * Returns <code>true</code> if one of the expression values is non-null.
141:             * Note: for efficiency this method calls {@link Expression#getValue(Object,Query)}
142:             * on each expression directly and returns <code>true</code> for the first non-null
143:             * value found, as such if any of your expressions triggers side-effects then this
144:             * method should not be used.
145:             *
146:             * @param o The current object.  
147:             * @param q The Query object.
148:             * @return <code>true</code> if one of the expression values is non-null.
149:             * @throws QueryExecutionException If a problem occurs during evaluation.
150:             */
151:            public boolean isTrue(Object o, Query q)
152:                    throws QueryExecutionException {
153:
154:                for (int i = 0; i < this .expressions.size(); i++) {
155:
156:                    Expression exp = (Expression) this .expressions.get(i);
157:
158:                    if (exp.getValue(o, q) != null) {
159:
160:                        return true;
161:
162:                    }
163:
164:                }
165:
166:                return false;
167:
168:            }
169:
170:            /**
171:             * Evaluates the value of this expression list.  This is just a thin-wrapper around:
172:             * {@link #getValue(Object,Query)}.
173:             *
174:             * @param o The current object.
175:             * @param q The Query object.
176:             * @return The value of this expression list.
177:             * @throws QueryExecutionException If there is a problem getting the values.
178:             */
179:            public Object evaluate(Object o, Query q)
180:                    throws QueryExecutionException {
181:
182:                return this .getValue(o, q);
183:
184:            }
185:
186:            /**
187:             * Returns a string version of this expression list.
188:             * Returns in the form: "[" Expression [ , Expression ]* "]".
189:             *
190:             * @return A string version of the expression list.
191:             */
192:            public String toString() {
193:
194:                StringBuffer buf = new StringBuffer("[");
195:
196:                for (int i = 0; i < this .expressions.size(); i++) {
197:
198:                    buf.append(this .expressions.get(i));
199:
200:                    if (i < this .expressions.size() - 1) {
201:
202:                        buf.append(", ");
203:
204:                    }
205:
206:                }
207:
208:                buf.append("]");
209:
210:                return buf.toString();
211:
212:            }
213:
214:            /**
215:             * Returns <code>true</code> if this expression list is empty (no expressions) or
216:             * if ALL of the expressions have a fixed result.
217:             *
218:             * @param q The Query object.
219:             * @return See description.
220:             */
221:            public boolean hasFixedResult(Query q) {
222:
223:                if (this .expressions.size() == 0) {
224:
225:                    return true;
226:
227:                }
228:
229:                for (int i = 0; i < this .expressions.size(); i++) {
230:
231:                    Expression exp = (Expression) this .expressions.get(i);
232:
233:                    if (!exp.hasFixedResult(q)) {
234:
235:                        return false;
236:
237:                    }
238:
239:                }
240:
241:                return true;
242:
243:            }
244:
245:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.