Source Code Cross Referenced for ASTEQNode.java in  » Template-Engine » Velocity » org » apache » velocity » runtime » parser » node » 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 » Template Engine » Velocity » org.apache.velocity.runtime.parser.node 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.apache.velocity.runtime.parser.node;
002:
003:        /*
004:         * Licensed to the Apache Software Foundation (ASF) under one
005:         * or more contributor license agreements.  See the NOTICE file
006:         * distributed with this work for additional information
007:         * regarding copyright ownership.  The ASF licenses this file
008:         * to you under the Apache License, Version 2.0 (the
009:         * "License"); you may not use this file except in compliance
010:         * with the License.  You may obtain a copy of the License at
011:         *
012:         *   http://www.apache.org/licenses/LICENSE-2.0
013:         *
014:         * Unless required by applicable law or agreed to in writing,
015:         * software distributed under the License is distributed on an
016:         * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017:         * KIND, either express or implied.  See the License for the
018:         * specific language governing permissions and limitations
019:         * under the License.    
020:         */
021:
022:        import org.apache.velocity.context.InternalContextAdapter;
023:        import org.apache.velocity.exception.MethodInvocationException;
024:        import org.apache.velocity.runtime.parser.Parser;
025:        import org.apache.velocity.runtime.parser.ParserVisitor;
026:        import org.apache.velocity.util.TemplateNumber;
027:
028:        /**
029:         *  Handles <code>arg1  == arg2</code>
030:         *
031:         *  This operator requires that the LHS and RHS are both of the
032:         *  same Class OR both are subclasses of java.lang.Number
033:         *
034:         *  @author <a href="mailto:wglass@forio.com">Will Glass-Husain</a>
035:         *  @author <a href="mailto:pero@antaramusic.de">Peter Romianowski</a>
036:         *  @version $Id: ASTEQNode.java 463298 2006-10-12 16:10:32Z henning $
037:         */
038:        public class ASTEQNode extends SimpleNode {
039:            /**
040:             * @param id
041:             */
042:            public ASTEQNode(int id) {
043:                super (id);
044:            }
045:
046:            /**
047:             * @param p
048:             * @param id
049:             */
050:            public ASTEQNode(Parser p, int id) {
051:                super (p, id);
052:            }
053:
054:            /**
055:             * @see org.apache.velocity.runtime.parser.node.SimpleNode#jjtAccept(org.apache.velocity.runtime.parser.ParserVisitor, java.lang.Object)
056:             */
057:            public Object jjtAccept(ParserVisitor visitor, Object data) {
058:                return visitor.visit(this , data);
059:            }
060:
061:            /**
062:             *   Calculates the value of the logical expression
063:             *
064:             *     arg1 == arg2
065:             *
066:             *   All class types are supported.   Uses equals() to
067:             *   determine equivalence.  This should work as we represent
068:             *   with the types we already support, and anything else that
069:             *   implements equals() to mean more than identical references.
070:             *
071:             *
072:             *  @param context  internal context used to evaluate the LHS and RHS
073:             *  @return true if equivalent, false if not equivalent,
074:             *          false if not compatible arguments, or false
075:             *          if either LHS or RHS is null
076:             * @throws MethodInvocationException
077:             */
078:            public boolean evaluate(InternalContextAdapter context)
079:                    throws MethodInvocationException {
080:                Object left = jjtGetChild(0).value(context);
081:                Object right = jjtGetChild(1).value(context);
082:
083:                /*
084:                 *  they could be null if they are references and not in the context
085:                 */
086:
087:                if (left == null || right == null) {
088:                    log.error((left == null ? "Left" : "Right") + " side ("
089:                            + jjtGetChild((left == null ? 0 : 1)).literal()
090:                            + ") of '==' operation " + "has null value. "
091:                            + "If a reference, it may not be in the context."
092:                            + " Operation not possible. "
093:                            + context.getCurrentTemplateName() + " [line "
094:                            + getLine() + ", column " + getColumn() + "]");
095:                    return false;
096:                }
097:
098:                /*
099:                 *  convert to Number if applicable
100:                 */
101:                if (left instanceof  TemplateNumber) {
102:                    left = ((TemplateNumber) left).getAsNumber();
103:                }
104:                if (right instanceof  TemplateNumber) {
105:                    right = ((TemplateNumber) right).getAsNumber();
106:                }
107:
108:                /*
109:                 * If comparing Numbers we do not care about the Class.
110:                 */
111:
112:                if (left instanceof  Number && right instanceof  Number) {
113:                    return MathUtils.compare((Number) left, (Number) right) == 0;
114:                }
115:
116:                /**
117:                 * assume that if one class is a subclass of the other
118:                 * that we should use the equals operator
119:                 */
120:
121:                if (left.getClass().isAssignableFrom(right.getClass())
122:                        || right.getClass().isAssignableFrom(left.getClass())) {
123:                    return left.equals(right);
124:                } else {
125:                    /**
126:                     * Compare the String representations
127:                     */
128:                    if ((left.toString() == null) || (right.toString() == null)) {
129:                        boolean culprit = (left.toString() == null);
130:                        log.error((culprit ? "Left" : "Right")
131:                                + " string side " + "String representation ("
132:                                + jjtGetChild((culprit ? 0 : 1)).literal()
133:                                + ") of '!=' operation has null value."
134:                                + " Operation not possible. "
135:                                + context.getCurrentTemplateName() + " [line "
136:                                + getLine() + ", column " + getColumn() + "]");
137:
138:                        return false;
139:                    }
140:
141:                    else {
142:                        return left.toString().equals(right.toString());
143:                    }
144:                }
145:
146:            }
147:
148:            /**
149:             * @see org.apache.velocity.runtime.parser.node.SimpleNode#value(org.apache.velocity.context.InternalContextAdapter)
150:             */
151:            public Object value(InternalContextAdapter context)
152:                    throws MethodInvocationException {
153:                return evaluate(context) ? Boolean.TRUE : Boolean.FALSE;
154:            }
155:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.