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 public class ASTNENode extends SimpleNode 25 { 26 public ASTNENode(int id) 27 { 28 super(id); 29 } 30 31 public ASTNENode(Parser p, int id) 32 { 33 super(p, id); 34 } 35 36 37 public Object jjtAccept(ParserVisitor visitor, Object data) 38 { 39 return visitor.visit(this, data); 40 } 41 42 public boolean evaluate( InternalContextAdapter context) 43 throws MethodInvocationException 44 { 45 Object left = jjtGetChild(0).value( context ); 46 Object right = jjtGetChild(1).value( context ); 47 48 51 52 if ( left == null || right == null) 53 { 54 rsvc.error( ( left == null ? "Left" : "Right" ) + " side (" 55 + jjtGetChild( (left == null? 0 : 1) ).literal() 56 + ") of '!=' operation has null value." 57 + " Operation not possible. " 58 + context.getCurrentTemplateName() + " [line " + getLine() 59 + ", column " + getColumn() + "]"); 60 return false; 61 62 } 63 64 65 70 71 if (left.getClass().equals( right.getClass() ) ) 72 { 73 return !(left.equals( right )); 74 } 75 else 76 { 77 rsvc.error("Error in evaluation of != expression." 78 + " Both arguments must be of the same Class." 79 + " Currently left = " + left.getClass() + ", right = " 80 + right.getClass() + ". " 81 + context.getCurrentTemplateName() + " [line " + getLine() 82 + ", column " + getColumn() + "] (ASTEQNode)"); 83 84 return false; 85 } 86 } 87 88 public Object value(InternalContextAdapter context) 89 throws MethodInvocationException 90 { 91 boolean val = evaluate(context); 92 93 return val ? Boolean.TRUE : Boolean.FALSE; 94 } 95 96 } 97 | Popular Tags |