1 16 19 package org.apache.xpath.objects; 20 21 import org.apache.xml.dtm.DTM; 22 import org.apache.xml.dtm.DTMIterator; 23 import org.apache.xml.utils.XMLString; 24 import org.apache.xpath.Expression; 25 import org.apache.xpath.ExpressionNode; 26 import org.apache.xpath.XPathContext; 27 import org.apache.xpath.axes.RTFIterator; 28 29 import org.w3c.dom.NodeList ; 30 31 36 public class XRTreeFrag extends XObject implements Cloneable 37 { 38 DTM m_dtm; 39 int m_dtmRoot; 40 XPathContext m_xctxt; 41 boolean m_allowRelease = false; 42 43 56 61 public XRTreeFrag(int root, XPathContext xctxt, ExpressionNode parent) 62 { 63 super(null); 64 65 exprSetParent(parent); 67 m_dtmRoot = root; 68 m_xctxt = xctxt; 69 m_dtm = xctxt.getDTM(root); 70 } 71 72 77 public XRTreeFrag(int root, XPathContext xctxt) 78 { 79 super(null); 80 81 m_dtmRoot = root; 83 m_xctxt = xctxt; 84 m_dtm = xctxt.getDTM(root); 85 } 86 87 88 94 public Object object() 95 { 96 if (m_xctxt != null) 97 return new org.apache.xml.dtm.ref.DTMNodeIterator((DTMIterator)(new org.apache.xpath.NodeSetDTM(m_dtmRoot, m_xctxt.getDTMManager()))); 98 else 99 return super.object(); 100 } 101 102 107 public XRTreeFrag(Expression expr) 108 { 109 super(expr); 110 } 111 112 119 protected void finalize() throws Throwable 120 { 121 try 122 { 123 destruct(); 124 } 125 finally 126 { 127 super.finalize(); } 129 } 130 131 137 public void allowDetachToRelease(boolean allowRelease) 138 { 139 m_allowRelease = allowRelease; 140 } 141 142 151 public void detach() 152 { 153 if(m_allowRelease) 154 { 155 int ident = m_xctxt.getDTMIdentity(m_dtm); 159 DTM foundDTM = m_xctxt.getDTM(ident); 160 if(foundDTM == m_dtm) 161 { 162 m_xctxt.release(m_dtm, true); 163 m_dtm = null; 164 m_xctxt = null; 165 } 166 m_obj = null; 167 } 168 } 169 170 174 public void destruct() 175 { 176 if(null != m_dtm) 177 { 178 int ident = m_xctxt.getDTMIdentity(m_dtm); 197 DTM foundDTM = m_xctxt.getDTM(ident); 198 if(foundDTM == m_dtm) 199 { 200 m_xctxt.release(m_dtm, true); 201 m_dtm = null; 202 m_xctxt = null; 203 } 204 } 205 m_obj = null; 206 } 207 208 213 public int getType() 214 { 215 return CLASS_RTREEFRAG; 216 } 217 218 224 public String getTypeString() 225 { 226 return "#RTREEFRAG"; 227 } 228 229 234 public double num() 235 throws javax.xml.transform.TransformerException 236 { 237 238 XMLString s = xstr(); 239 240 return s.toDouble(); 241 } 242 243 249 public boolean bool() 250 { 251 return true; 252 } 253 254 private XMLString m_xmlStr = null; 255 256 261 public XMLString xstr() 262 { 263 if(null == m_xmlStr) 264 m_xmlStr = m_dtm.getStringValue(m_dtmRoot); 265 266 return m_xmlStr; 267 } 268 269 274 public void appendToFsb(org.apache.xml.utils.FastStringBuffer fsb) 275 { 276 XString xstring = (XString)xstr(); 277 xstring.appendToFsb(fsb); 278 } 279 280 281 286 public String str() 287 { 288 String str = m_dtm.getStringValue(m_dtmRoot).toString(); 289 290 return (null == str) ? "" : str; 291 } 292 293 298 public int rtf() 299 { 300 return m_dtmRoot; 301 } 302 303 310 public DTMIterator asNodeIterator() 311 { 312 return new RTFIterator(m_dtmRoot, m_xctxt.getDTMManager()); 313 } 314 315 320 public NodeList convertToNodeset() 321 { 322 323 if (m_obj instanceof NodeList ) 324 return (NodeList ) m_obj; 325 else 326 return new org.apache.xml.dtm.ref.DTMNodeList(asNodeIterator()); 327 } 328 329 338 public boolean equals(XObject obj2) 339 { 340 341 try 342 { 343 if (XObject.CLASS_NODESET == obj2.getType()) 344 { 345 346 return obj2.equals(this); 350 } 351 else if (XObject.CLASS_BOOLEAN == obj2.getType()) 352 { 353 return bool() == obj2.bool(); 354 } 355 else if (XObject.CLASS_NUMBER == obj2.getType()) 356 { 357 return num() == obj2.num(); 358 } 359 else if (XObject.CLASS_NODESET == obj2.getType()) 360 { 361 return xstr().equals(obj2.xstr()); 362 } 363 else if (XObject.CLASS_STRING == obj2.getType()) 364 { 365 return xstr().equals(obj2.xstr()); 366 } 367 else if (XObject.CLASS_RTREEFRAG == obj2.getType()) 368 { 369 370 return xstr().equals(obj2.xstr()); 372 } 373 else 374 { 375 return super.equals(obj2); 376 } 377 } 378 catch(javax.xml.transform.TransformerException te) 379 { 380 throw new org.apache.xml.utils.WrappedRuntimeException(te); 381 } 382 } 383 384 } 385 | Popular Tags |