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 import org.apache.velocity.exception.MethodInvocationException; 22 23 public class ASTGENode extends SimpleNode 24 { 25 public ASTGENode(int id) 26 { 27 super(id); 28 } 29 30 public ASTGENode(Parser p, int id) 31 { 32 super(p, id); 33 } 34 35 36 public Object jjtAccept(ParserVisitor visitor, Object data) 37 { 38 return visitor.visit(this, data); 39 } 40 41 public boolean evaluate( InternalContextAdapter context) 42 throws MethodInvocationException 43 { 44 47 48 Object left = jjtGetChild(0).value( context ); 49 Object right = jjtGetChild(1).value( context ); 50 51 54 55 if (left == null || right == null) 56 { 57 rsvc.error( ( left == null ? "Left" : "Right" ) 58 + " side (" 59 + jjtGetChild( (left == null? 0 : 1) ).literal() 60 + ") of '>=' operation has null value." 61 + " Operation not possible. " 62 + context.getCurrentTemplateName() + " [line " 63 + getLine() 64 + ", column " + getColumn() + "]"); 65 return false; 66 } 67 68 71 72 if ( !( left instanceof Integer ) || !( right instanceof Integer )) 73 { 74 rsvc.error( ( !( left instanceof Integer ) ? "Left" : "Right" ) 75 + " side of '>=' operation is not a valid type. " 76 + " It is a " + ( !( left instanceof Integer ) ? left.getClass() : right.getClass() ) 77 + ". Currently only integers (1,2,3...) and Integer type is supported. " 78 + context.getCurrentTemplateName() + " [line " + getLine() 79 + ", column " + getColumn() + "]"); 80 81 return false; 82 } 83 84 return ( (Integer ) left).intValue() >= ((Integer ) right).intValue(); 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 |