1 16 19 package com.sun.org.apache.xpath.internal.axes; 20 21 import java.util.Vector ; 22 23 import com.sun.org.apache.xml.internal.dtm.DTMIterator; 24 import com.sun.org.apache.xml.internal.utils.WrappedRuntimeException; 25 26 30 public class IteratorPool implements java.io.Serializable 31 { 32 33 35 private final DTMIterator m_orig; 36 37 39 private final Vector m_freeStack; 40 41 46 public IteratorPool(DTMIterator original) 47 { 48 m_orig = original; 49 m_freeStack = new Vector (); 50 } 51 52 57 public synchronized DTMIterator getInstanceOrThrow() 58 throws CloneNotSupportedException 59 { 60 if (m_freeStack.isEmpty()) 62 { 63 64 return (DTMIterator)m_orig.clone(); 66 } 67 else 68 { 69 DTMIterator result = (DTMIterator)m_freeStack.lastElement(); 71 72 m_freeStack.setSize(m_freeStack.size() - 1); 73 74 return result; 75 } 76 } 77 78 83 public synchronized DTMIterator getInstance() 84 { 85 if (m_freeStack.isEmpty()) 87 { 88 89 try 91 { 92 return (DTMIterator)m_orig.clone(); 93 } 94 catch (Exception ex) 95 { 96 throw new WrappedRuntimeException(ex); 97 } 98 } 99 else 100 { 101 DTMIterator result = (DTMIterator)m_freeStack.lastElement(); 103 104 m_freeStack.setSize(m_freeStack.size() - 1); 105 106 return result; 107 } 108 } 109 110 116 public synchronized void freeInstance(DTMIterator obj) 117 { 118 m_freeStack.addElement(obj); 119 } 120 } 121 | Popular Tags |