29 import org.xml.sax.SAXException; 30 import java.util.concurrent.ArrayBlockingQueue; 31 import java.util.concurrent.BlockingQueue; 32 import javax.xml.parsers.ParserConfigurationException; 33 import javax.xml.parsers.SAXParser; 34 import javax.xml.parsers.SAXParserFactory; 35 import org.xml.sax.SAXNotRecognizedException; 36 import org.xml.sax.SAXNotSupportedException; 37 38 39 /** 40 * Pool of SAXParser objects 41 */ 42 public class ParserPool { 43 private final BlockingQueue<SAXParser> queue; 44 private SAXParserFactory factory; 45 46 public ParserPool(int capacity) { 47 queue = new ArrayBlockingQueue<SAXParser>(capacity); 48 factory = SAXParserFactory.newInstance("com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl", SAAJUtil.getSystemClassLoader()); 49 factory.setNamespaceAware(true); 50 for (int i = 0; i < capacity; i++) { 51 try { 52 queue.put(factory.newSAXParser()); 53 } catch (InterruptedException ex) { 54 Thread.currentThread().interrupt(); 55 throw new RuntimeException(ex); 56 } catch (ParserConfigurationException ex) { 57 throw new RuntimeException(ex); 58 } catch (SAXException ex) { 59 throw new RuntimeException(ex); 60 } 61 } 62 } 63 64 public SAXParser get() throws ParserConfigurationException, 65 SAXException { 66 67 try { 68 return (SAXParser) queue.take(); | 29 import org.xml.sax.SAXException; 30 import java.util.concurrent.ArrayBlockingQueue; 31 import java.util.concurrent.BlockingQueue; 32 import javax.xml.parsers.ParserConfigurationException; 33 import javax.xml.parsers.SAXParser; 34 import javax.xml.parsers.SAXParserFactory; 35 import org.xml.sax.SAXNotRecognizedException; 36 import org.xml.sax.SAXNotSupportedException; 37 38 39 /** 40 * Pool of SAXParser objects 41 */ 42 public class ParserPool { 43 private final BlockingQueue<SAXParser> queue; 44 private SAXParserFactory factory; 45 46 public ParserPool(int capacity) { 47 queue = new ArrayBlockingQueue<SAXParser>(capacity); 48 factory = SAXParserFactory.newInstance("com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl", SAAJUtil.getSystemClassLoader()); 49 try { 50 factory.setFeature("jdk.xml.resetSymbolTable", true); 51 } catch(SAXException | ParserConfigurationException e) { 52 } 53 factory.setNamespaceAware(true); 54 for (int i = 0; i < capacity; i++) { 55 try { 56 queue.put(factory.newSAXParser()); 57 } catch (InterruptedException ex) { 58 Thread.currentThread().interrupt(); 59 throw new RuntimeException(ex); 60 } catch (ParserConfigurationException ex) { 61 throw new RuntimeException(ex); 62 } catch (SAXException ex) { 63 throw new RuntimeException(ex); 64 } 65 } 66 } 67 68 public SAXParser get() throws ParserConfigurationException, 69 SAXException { 70 71 try { 72 return (SAXParser) queue.take(); |