Source Code Cross Referenced for TreeCompiler.java in  » Library » Apache-commons-jxpath-1.2-src » org » apache » commons » jxpath » ri » compiler » 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 » Library » Apache commons jxpath 1.2 src » org.apache.commons.jxpath.ri.compiler 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 1999-2004 The Apache Software Foundation
003:         *
004:         * Licensed under the Apache License, Version 2.0 (the "License");
005:         * you may not use this file except in compliance with the License.
006:         * You may obtain a copy of the License at
007:         *
008:         *     http://www.apache.org/licenses/LICENSE-2.0
009:         *
010:         * Unless required by applicable law or agreed to in writing, software
011:         * distributed under the License is distributed on an "AS IS" BASIS,
012:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013:         * See the License for the specific language governing permissions and
014:         * limitations under the License.
015:         */
016:        package org.apache.commons.jxpath.ri.compiler;
017:
018:        import org.apache.commons.jxpath.ri.Compiler;
019:        import org.apache.commons.jxpath.ri.QName;
020:
021:        /**
022:         * @author Dmitri Plotnikov
023:         * @version $Revision: 1.10 $ $Date: 2004/02/29 14:17:39 $
024:         */
025:        public class TreeCompiler implements  Compiler {
026:
027:            private static final QName QNAME_NAME = new QName(null, "name");
028:
029:            public Object number(String value) {
030:                return new Constant(new Double(value));
031:            }
032:
033:            public Object literal(String value) {
034:                return new Constant(value);
035:            }
036:
037:            public Object qname(String prefix, String name) {
038:                return new QName(prefix, name);
039:            }
040:
041:            public Object sum(Object[] arguments) {
042:                return new CoreOperationAdd(toExpressionArray(arguments));
043:            }
044:
045:            public Object minus(Object left, Object right) {
046:                return new CoreOperationSubtract((Expression) left,
047:                        (Expression) right);
048:            }
049:
050:            public Object multiply(Object left, Object right) {
051:                return new CoreOperationMultiply((Expression) left,
052:                        (Expression) right);
053:            }
054:
055:            public Object divide(Object left, Object right) {
056:                return new CoreOperationDivide((Expression) left,
057:                        (Expression) right);
058:            }
059:
060:            public Object mod(Object left, Object right) {
061:                return new CoreOperationMod((Expression) left,
062:                        (Expression) right);
063:            }
064:
065:            public Object lessThan(Object left, Object right) {
066:                return new CoreOperationLessThan((Expression) left,
067:                        (Expression) right);
068:            }
069:
070:            public Object lessThanOrEqual(Object left, Object right) {
071:                return new CoreOperationLessThanOrEqual((Expression) left,
072:                        (Expression) right);
073:            }
074:
075:            public Object greaterThan(Object left, Object right) {
076:                return new CoreOperationGreaterThan((Expression) left,
077:                        (Expression) right);
078:            }
079:
080:            public Object greaterThanOrEqual(Object left, Object right) {
081:                return new CoreOperationGreaterThanOrEqual((Expression) left,
082:                        (Expression) right);
083:            }
084:
085:            public Object equal(Object left, Object right) {
086:                if (isNameAttributeTest((Expression) left)) {
087:                    return new NameAttributeTest((Expression) left,
088:                            (Expression) right);
089:                } else {
090:                    return new CoreOperationEqual((Expression) left,
091:                            (Expression) right);
092:                }
093:            }
094:
095:            public Object notEqual(Object left, Object right) {
096:                return new CoreOperationNotEqual((Expression) left,
097:                        (Expression) right);
098:            }
099:
100:            public Object minus(Object argument) {
101:                return new CoreOperationNegate((Expression) argument);
102:            }
103:
104:            public Object variableReference(Object qName) {
105:                return new VariableReference((QName) qName);
106:            }
107:
108:            public Object function(int code, Object[] args) {
109:                return new CoreFunction(code, toExpressionArray(args));
110:            }
111:
112:            public Object function(Object name, Object[] args) {
113:                return new ExtensionFunction((QName) name,
114:                        toExpressionArray(args));
115:            }
116:
117:            public Object and(Object arguments[]) {
118:                return new CoreOperationAnd(toExpressionArray(arguments));
119:            }
120:
121:            public Object or(Object arguments[]) {
122:                return new CoreOperationOr(toExpressionArray(arguments));
123:            }
124:
125:            public Object union(Object[] arguments) {
126:                return new CoreOperationUnion(toExpressionArray(arguments));
127:            }
128:
129:            public Object locationPath(boolean absolute, Object[] steps) {
130:                return new LocationPath(absolute, toStepArray(steps));
131:            }
132:
133:            public Object expressionPath(Object expression,
134:                    Object[] predicates, Object[] steps) {
135:                return new ExpressionPath((Expression) expression,
136:                        toExpressionArray(predicates), toStepArray(steps));
137:            }
138:
139:            public Object nodeNameTest(Object qname) {
140:                return new NodeNameTest((QName) qname);
141:            }
142:
143:            public Object nodeTypeTest(int nodeType) {
144:                return new NodeTypeTest(nodeType);
145:            }
146:
147:            public Object processingInstructionTest(String instruction) {
148:                return new ProcessingInstructionTest(instruction);
149:            }
150:
151:            public Object step(int axis, Object nodeTest, Object[] predicates) {
152:                return new Step(axis, (NodeTest) nodeTest,
153:                        toExpressionArray(predicates));
154:            }
155:
156:            private Expression[] toExpressionArray(Object[] array) {
157:                Expression expArray[] = null;
158:                if (array != null) {
159:                    expArray = new Expression[array.length];
160:                    for (int i = 0; i < expArray.length; i++) {
161:                        expArray[i] = (Expression) array[i];
162:                    }
163:                }
164:                return expArray;
165:            }
166:
167:            private Step[] toStepArray(Object[] array) {
168:                Step stepArray[] = null;
169:                if (array != null) {
170:                    stepArray = new Step[array.length];
171:                    for (int i = 0; i < stepArray.length; i++) {
172:                        stepArray[i] = (Step) array[i];
173:                    }
174:                }
175:                return stepArray;
176:            }
177:
178:            private boolean isNameAttributeTest(Expression arg) {
179:                if (!(arg instanceof  LocationPath)) {
180:                    return false;
181:                }
182:
183:                Step[] steps = ((LocationPath) arg).getSteps();
184:                if (steps.length != 1) {
185:                    return false;
186:                }
187:                if (steps[0].getAxis() != Compiler.AXIS_ATTRIBUTE) {
188:                    return false;
189:                }
190:                NodeTest test = steps[0].getNodeTest();
191:                if (!(test instanceof  NodeNameTest)) {
192:                    return false;
193:                }
194:                if (!((NodeNameTest) test).getNodeName().equals(QNAME_NAME)) {
195:                    return false;
196:                }
197:                return true;
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.