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 ASTMulNode extends SimpleNode 35 { 36 public ASTMulNode(int id) 37 { 38 super(id); 39 } 40 41 public ASTMulNode(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 56 public Object value( InternalContextAdapter context ) 57 throws MethodInvocationException 58 { 59 62 63 Object left = jjtGetChild(0).value( context ); 64 Object right = jjtGetChild(1).value( context ); 65 66 69 70 if (left == null || right == null) 71 { 72 rsvc.error( ( left == null ? "Left" : "Right" ) + " side (" 73 + jjtGetChild( (left == null? 0 : 1) ).literal() 74 + ") of multiplication operation has null value." 75 + " Operation not possible. " 76 + context.getCurrentTemplateName() + " [line " + getLine() 77 + ", column " + getColumn() + "]"); 78 return null; 79 } 80 81 84 85 if ( !( left instanceof Integer ) || !( right instanceof Integer )) 86 { 87 rsvc.error( ( !( left instanceof Integer ) ? "Left" : "Right" ) 88 + " side of multiplication operation is not a valid type. " 89 + "Currently only integers (1,2,3...) and Integer type is supported. " 90 + context.getCurrentTemplateName() + " [line " + getLine() 91 + ", column " + getColumn() + "]"); 92 93 return null; 94 } 95 96 return new Integer ( ( (Integer ) left ).intValue() * ( (Integer ) right ).intValue() ); 97 } 98 } 99 100 101 102 103 | Popular Tags |