1 16 17 package org.apache.taglibs.standard.lang.jpath.expression; 18 19 import javax.servlet.jsp.PageContext ; 20 21 import org.apache.taglibs.standard.lang.jpath.adapter.ConversionException; 22 import org.apache.taglibs.standard.lang.jpath.adapter.Convert; 23 import org.apache.taglibs.standard.lang.jpath.adapter.IterationContext; 24 25 32 public class GreaterThanEqualOperator extends SimpleNode { 33 34 41 public GreaterThanEqualOperator(int id) { 42 super(id); 43 } 44 45 53 public GreaterThanEqualOperator(Parser p, int id) { 54 super(p, id); 55 } 56 57 67 public String toNormalizedString() { 68 69 String normalized = ""; 70 71 normalized = "(" + jjtGetChild(0).toNormalizedString() + " " 72 + getTokenImage(ParserConstants.GTE) + " " 73 + jjtGetChild(1).toNormalizedString() + ")"; 74 75 return normalized; 76 } 77 78 95 public Object evaluate(PageContext pageContext, IterationContext icontext) 96 throws EvaluationException { 97 98 boolean result; 99 100 try { 101 Object leftSide = jjtGetChild(0).evaluate(pageContext, icontext); 102 Object rightSide = jjtGetChild(1).evaluate(pageContext, icontext); 103 104 if ((leftSide instanceof Boolean ) 105 || (rightSide instanceof Boolean ) 106 || (leftSide instanceof Double ) 107 || (rightSide instanceof Double ) 108 || (leftSide instanceof String ) 109 || (rightSide instanceof String )) { 110 double leftResult = 111 Convert.toDouble(jjtGetChild(0).evaluate(pageContext, 112 icontext)).doubleValue(); 113 double rightResult = 114 Convert.toDouble(jjtGetChild(1).evaluate(pageContext, 115 icontext)).doubleValue(); 116 117 result = leftResult >= rightResult; 118 } else if ((leftSide instanceof Comparable ) 119 && (rightSide instanceof Comparable )) { 120 try { 121 int comp = ((Comparable ) leftSide).compareTo(rightSide); 122 123 if (comp >= 0) { 124 result = true; 125 } else { 126 result = false; 127 } 128 } catch (ClassCastException cce) { 129 throw new EvaluationException(this, 130 "child nodes [" 131 + jjtGetChild(0).toNormalizedString() + "] and [" 132 + jjtGetChild(1).toNormalizedString() 133 + "] cannot be compared"); 134 } 135 } else { 136 throw new EvaluationException(this, 137 "child nodes [" + jjtGetChild(0).toNormalizedString() 138 + "] and [" + jjtGetChild(1).toNormalizedString() 139 + "] cannot be compared"); 140 } 141 } catch (ConversionException ce) { 142 throw new EvaluationException(this, ce.getMessage()); 143 } 144 145 return new Boolean (result); 146 } 147 } 148 | Popular Tags |