1 28 29 package com.caucho.xpath.expr; 30 31 import com.caucho.xpath.Expr; 32 import com.caucho.xpath.ExprEnvironment; 33 import com.caucho.xpath.XPathException; 34 35 import org.w3c.dom.Node ; 36 37 abstract public class AbstractNumberExpr extends Expr { 38 public boolean isNumber() 39 { 40 return true; 41 } 42 43 51 public Var evalVar(Node node, ExprEnvironment env) 52 throws XPathException 53 { 54 double value = evalNumber(node, env); 55 56 return NumberVar.create(value); 57 } 58 59 67 abstract public double evalNumber(Node node, ExprEnvironment env) 68 throws XPathException; 69 70 78 public boolean evalBoolean(Node node, ExprEnvironment env) 79 throws XPathException 80 { 81 double value = evalNumber(node, env); 82 83 return value != 0.0 && ! Double.isNaN(value); 84 } 85 86 94 public String evalString(Node node, ExprEnvironment env) 95 throws XPathException 96 { 97 double value = evalNumber(node, env); 98 99 if ((int) value == value) 100 return String.valueOf((int) value); 101 else 102 return String.valueOf(value); 103 } 104 105 113 public Object evalObject(Node node, ExprEnvironment env) 114 throws XPathException 115 { 116 return new Double (evalNumber(node, env)); 117 } 118 } 119 | Popular Tags |