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.NodeArrayListIterator; 36 import com.caucho.xpath.pattern.NodeIterator; 37 import com.caucho.xpath.pattern.NodeListIterator; 38 import com.caucho.xpath.pattern.SingleNodeIterator; 39 40 import org.w3c.dom.Node ; 41 import org.w3c.dom.NodeList ; 42 43 import java.util.ArrayList ; 44 45 public abstract class Var { 46 49 boolean getBoolean() 50 throws XPathException 51 { 52 return Expr.toBoolean(getObject()); 53 } 54 55 58 double getDouble() 59 throws XPathException 60 { 61 Object o = getObject(); 62 return Expr.toDouble(getObject()); 63 } 64 65 68 String getString() 69 throws XPathException 70 { 71 return Expr.toString(getObject()); 72 } 73 74 77 void getString(CharBuffer cb) 78 throws XPathException 79 { 80 cb.append(getString()); 81 } 82 83 86 NodeIterator getNodeSet(ExprEnvironment env) 87 throws XPathException 88 { 89 Object obj = getObject(); 90 91 if (obj instanceof Node ) 92 return new SingleNodeIterator(env, (Node ) obj); 93 else if (obj instanceof NodeList ) 94 return new NodeListIterator(env, (NodeList ) obj); 95 else if (obj instanceof ArrayList ) 96 return new NodeArrayListIterator(env, (ArrayList ) obj); 97 else 98 return new SingleNodeIterator(env, null); 99 } 100 101 104 abstract Object getObject(); 105 106 109 public void free() 110 { 111 } 112 } 113 | Popular Tags |