1 28 29 package com.caucho.xpath.expr; 30 31 import com.caucho.util.CharBuffer; 32 import com.caucho.xpath.Expr; 33 import com.caucho.xpath.ExprEnvironment; 34 import com.caucho.xpath.XPathException; 35 import com.caucho.xpath.pattern.NodeIterator; 36 import com.caucho.xpath.pattern.SingleNodeIterator; 37 38 import org.w3c.dom.Node ; 39 40 public class VarExpr extends Expr { 41 private String name; 42 43 public VarExpr(String name) 44 { 45 this.name = name.intern(); 46 } 47 48 56 public boolean evalBoolean(Node node, ExprEnvironment env) 57 throws XPathException 58 { 59 Var var = (Var) env.getVar(name); 60 61 return var == null ? false : var.getBoolean(); 62 } 63 64 72 public double evalNumber(Node node, ExprEnvironment env) 73 throws XPathException 74 { 75 Var var = env.getVar(name); 76 77 return var == null ? Double.NaN : var.getDouble(); 78 } 79 80 89 public void evalString(CharBuffer cb, Node node, ExprEnvironment env) 90 throws XPathException 91 { 92 Var var = env.getVar(name); 93 94 if (var != null) 95 var.getString(cb); 96 } 97 98 106 public String evalString(Node node, ExprEnvironment env) 107 throws XPathException 108 { 109 Var var = env.getVar(name); 110 111 return var == null ? "" : var.getString(); 112 } 113 114 122 public Object evalObject(Node node, ExprEnvironment env) 123 throws XPathException 124 { 125 Var var = env.getVar(name); 126 127 return var == null ? null : var.getObject(); 128 } 129 130 138 public Var evalVar(Node node, ExprEnvironment env) 139 throws XPathException 140 { 141 Var var = env.getVar(name); 142 143 return var; 144 } 145 146 154 public NodeIterator evalNodeSet(Node node, ExprEnvironment env) 155 throws XPathException 156 { 157 Var var = env.getVar(name); 158 159 if (var == null) 160 return new SingleNodeIterator(env, null); 161 else 162 return var.getNodeSet(env); 163 } 164 165 public String toString() 166 { 167 return "$" + name; 168 } 169 } 170 | Popular Tags |