XMLReaderFactory.createXMLReader Deprecation (#1493)
* remove the resources\datafiles\presets folder as its is being built by the copy-orc-files build script * Refactored from new Boolean and new Integer to Boolean.valueOf and Integer.valueOf due to deprecation warnings. Value of is supported in Java 8 (https://docs.oracle.com/javase/8/docs/api/java/lang/Integer.html) * Removed non-atomic updates around deprecation * updates * sync * resolved deprecated xmlreader
This commit is contained in:
parent
30e423064e
commit
08b76e0b7e
@ -11,6 +11,9 @@ import org.xml.sax.SAXException;
|
|||||||
import org.xml.sax.XMLReader;
|
import org.xml.sax.XMLReader;
|
||||||
import org.xml.sax.helpers.XMLReaderFactory;
|
import org.xml.sax.helpers.XMLReaderFactory;
|
||||||
|
|
||||||
|
import javax.xml.parsers.ParserConfigurationException;
|
||||||
|
import javax.xml.parsers.SAXParser;
|
||||||
|
import javax.xml.parsers.SAXParserFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A "simple SAX" XML reader. This system imposes the limit that an XML element may
|
* A "simple SAX" XML reader. This system imposes the limit that an XML element may
|
||||||
@ -18,27 +21,26 @@ import org.xml.sax.helpers.XMLReaderFactory;
|
|||||||
* both. This holds true for both the OpenRocket and RockSim design formats and the
|
* both. This holds true for both the OpenRocket and RockSim design formats and the
|
||||||
* RockSim engine definition format.
|
* RockSim engine definition format.
|
||||||
* <p>
|
* <p>
|
||||||
* The actual handling is performed by subclasses of {@link ElementHandler}. The
|
* The actual handling is performed by subclasses of {@link ElementHandler}. The
|
||||||
* initial handler is provided to the {@link #readXML(InputSource, ElementHandler, WarningSet)}
|
* initial handler is provided to the {@link #readXML(InputSource, ElementHandler, WarningSet)}
|
||||||
* method.
|
* method.
|
||||||
*
|
*
|
||||||
* @author Sampo Niskanen <sampo.niskanen@iki.fi>
|
* @author Sampo Niskanen <sampo.niskanen@iki.fi>
|
||||||
*/
|
*/
|
||||||
public class SimpleSAX {
|
public class SimpleSAX {
|
||||||
|
|
||||||
static final XMLReaderCache cache = new XMLReaderCache(10);
|
static final XMLReaderCache cache = new XMLReaderCache(10);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Read a simple XML file.
|
* Read a simple XML file.
|
||||||
*
|
*
|
||||||
* @param source the SAX input source.
|
* @param source the SAX input source.
|
||||||
* @param initialHandler the initial content handler.
|
* @param initialHandler the initial content handler.
|
||||||
* @param warnings a warning set to store warning (cannot be <code>null</code>).
|
* @param warnings a warning set to store warning (cannot be <code>null</code>).
|
||||||
* @throws IOException if an I/O exception occurs while reading.
|
* @throws IOException if an I/O exception occurs while reading.
|
||||||
* @throws SAXException if e.g. malformed XML is encountered.
|
* @throws SAXException if e.g. malformed XML is encountered.
|
||||||
*/
|
*/
|
||||||
public static void readXML(InputSource source, ElementHandler initialHandler,
|
public static void readXML(InputSource source, ElementHandler initialHandler, WarningSet warnings)
|
||||||
WarningSet warnings) throws IOException, SAXException {
|
throws IOException, SAXException {
|
||||||
|
|
||||||
DelegatorHandler xmlhandler = new DelegatorHandler(initialHandler, warnings);
|
DelegatorHandler xmlhandler = new DelegatorHandler(initialHandler, warnings);
|
||||||
|
|
||||||
@ -55,17 +57,27 @@ public class SimpleSAX {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static class XMLReaderCache {
|
private static class XMLReaderCache {
|
||||||
|
private final SAXParserFactory parserFactory;
|
||||||
|
|
||||||
private final BlockingQueue<XMLReader> queue;
|
private final BlockingQueue<XMLReader> queue;
|
||||||
|
|
||||||
private XMLReaderCache( int maxSize ) {
|
private XMLReaderCache( int maxSize ) {
|
||||||
this.queue = new LinkedBlockingQueue<XMLReader>(maxSize);
|
parserFactory = SAXParserFactory.newInstance();
|
||||||
|
parserFactory.setNamespaceAware(true);
|
||||||
|
queue = new LinkedBlockingQueue<XMLReader>(maxSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
private XMLReader createXMLReader() throws SAXException {
|
private XMLReader createXMLReader() throws SAXException {
|
||||||
|
|
||||||
XMLReader reader = queue.poll();
|
XMLReader reader = queue.poll();
|
||||||
if ( reader == null ) {
|
if ( reader == null ) {
|
||||||
|
try {
|
||||||
reader = XMLReaderFactory.createXMLReader();
|
reader = XMLReaderFactory.createXMLReader();
|
||||||
|
SAXParser parser = parserFactory.newSAXParser();
|
||||||
|
reader = parser.getXMLReader();
|
||||||
|
}
|
||||||
|
catch (ParserConfigurationException ignore) {
|
||||||
|
System.out.print(ignore);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return reader;
|
return reader;
|
||||||
}
|
}
|
||||||
@ -77,5 +89,4 @@ public class SimpleSAX {
|
|||||||
queue.offer( reader );
|
queue.offer( reader );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user