1 package org.apache.velocity.runtime.parser.node; 2 3 18 19 import org.apache.velocity.context.InternalContextAdapter; 20 import org.apache.velocity.runtime.parser.Parser; 21 22 import org.apache.velocity.exception.MethodInvocationException; 23 24 34 public class ASTEQNode extends SimpleNode 35 { 36 public ASTEQNode(int id) 37 { 38 super(id); 39 } 40 41 public ASTEQNode(Parser p, int id) 42 { 43 super(p, id); 44 } 45 46 47 public Object jjtAccept(ParserVisitor visitor, Object data) 48 { 49 return visitor.visit(this, data); 50 } 51 52 68 public boolean evaluate( InternalContextAdapter context) 69 throws MethodInvocationException 70 { 71 Object left = jjtGetChild(0).value(context); 72 Object right = jjtGetChild(1).value(context); 73 74 77 78 if (left == null || right == null) 79 { 80 rsvc.error( ( left == null ? "Left" : "Right" ) 81 + " side (" 82 + jjtGetChild( (left == null? 0 : 1) ).literal() 83 + ") of '==' operation " 84 + "has null value. " 85 + "If a reference, it may not be in the context." 86 + " Operation not possible. " 87 + context.getCurrentTemplateName() + " [line " + getLine() 88 + ", column " + getColumn() + "]"); 89 return false; 90 } 91 92 97 98 if (left.getClass().equals( right.getClass() ) ) 99 { 100 return left.equals( right ); 101 } 102 else 103 { 104 rsvc.error("Error in evaluation of == expression." 105 + " Both arguments must be of the same Class." 106 + " Currently left = " + left.getClass() + ", right = " 107 + right.getClass() + ". " 108 + context.getCurrentTemplateName() + " [line " + getLine() 109 + ", column " + getColumn() + "] (ASTEQNode)"); 110 } 111 112 return false; 113 } 114 115 public Object value(InternalContextAdapter context) 116 throws MethodInvocationException 117 { 118 boolean val = evaluate(context); 119 120 return val ? Boolean.TRUE : Boolean.FALSE; 121 } 122 123 } 124 | Popular Tags |