⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xmlreaderfactory.java

📁 这是外国一个开源推理机
💻 JAVA
字号:
/*  Sesame - Storage and Querying architecture for RDF and RDF Schema *  Copyright (C) 2001-2005 Aduna * *  Contact: *  	Aduna *  	Prinses Julianaplein 14 b *  	3817 CS Amersfoort *  	The Netherlands *  	tel. +33 (0)33 465 99 87 *  	fax. +33 (0)33 465 99 87 * *  	http://aduna.biz/ *  	http://www.openrdf.org/ * *  This library is free software; you can redistribute it and/or *  modify it under the terms of the GNU Lesser General Public *  License as published by the Free Software Foundation; either *  version 2.1 of the License, or (at your option) any later version. * *  This library is distributed in the hope that it will be useful, *  but WITHOUT ANY WARRANTY; without even the implied warranty of *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU *  Lesser General Public License for more details. * *  You should have received a copy of the GNU Lesser General Public *  License along with this library; if not, write to the Free Software *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */package org.openrdf.util.xml;import org.xml.sax.SAXException;import org.xml.sax.XMLReader;import org.openrdf.util.log.ThreadLog;/** * Factory class for creating an XMLReader. This factory tries to use the * system property 'org.xml.sax.driver', if that fails it falls back on * javax.xml.sax.parsers.SAXParserFactory. If the SAXParserFactory class * can not be found (this can happen when using a Java 1.3 or older), or * the initialization using SAXParserFactory fails otherwise, the factory * falls back on the Xerces 2 SAX Parser. * * @author Jeen Broekstra * @version $Revision: 1.3 $ */public class XMLReaderFactory {	public static final String XERCES_SAXPARSER = "org.apache.xerces.parsers.SAXParser";	/**	 * creates an org.xml.sax.XMLReader object. The method first tries to	 * create the XMLReader object specified in the 'org.xml.sax.driver'	 * system property. If that fails, it tries to use	 * java.xml.parsers.SAXParserFactory. If that also fails, it tries to	 * initialize the Xerces 2 SAX parser. If that also fails, a	 * SAXException is thrown.	 *	 * @return an XMLReader	 * @exception SAXException when no default XMLReader class can be	 * found or instantiated.	 */	public static XMLReader createXMLReader() 		throws SAXException 	{		XMLReader reader = null;				// first, try and initialize based on the system property.		String xmlReaderName = System.getProperty("org.xml.sax.driver");		if (xmlReaderName != null) {			try {				reader = _createXMLReader(xmlReaderName);			}			catch (ClassNotFoundException e) {				ThreadLog.warning("Class " + xmlReaderName + " not found");			}			catch (ClassCastException e) {				ThreadLog.warning(xmlReaderName + " is not a valid XMLReader.");			}			catch (Exception e) {				ThreadLog.warning("could not create instance of " + xmlReaderName);			}			ThreadLog.trace("XMLReader initialized using system property: " + xmlReaderName);		}		// next, try using javax.xml.parsers.SAXParserFactory		if (reader == null) {			try {				javax.xml.parsers.SAXParserFactory factory = 					javax.xml.parsers.SAXParserFactory.newInstance();				factory.setNamespaceAware(true);				reader = factory.newSAXParser().getXMLReader();			}			catch (NoClassDefFoundError e) {				ThreadLog.warning("javax.xml.parsers.SAXParserFactory not available");			}			catch (Exception e) {				ThreadLog.warning("Failed to initialize XMLReader through JAXP");			}			ThreadLog.trace("XMLReader initialized using JAXP: " + reader);		}		// Last resort: try using the Xerces 2 SAX Parser		if (reader == null) {			try {				reader = _createXMLReader(XERCES_SAXPARSER);			}			catch (ClassNotFoundException e) {				String message = "Class " + XERCES_SAXPARSER + " not found";				ThreadLog.error(message);				throw new SAXException(message);			}			catch (ClassCastException e) {				String message = XERCES_SAXPARSER + " is not a valid XMLReader.";				ThreadLog.error(message);				throw new SAXException(message);			}			catch (Exception e) {				String message = "Could not create instance of " + XERCES_SAXPARSER;				ThreadLog.error(message);				throw new SAXException(message);			}			ThreadLog.trace("XMLReader initialized using default Xerces SAX parser " + XERCES_SAXPARSER);		}		return reader;	}	/**	 * Creates an org.xml.sax.XMLReader object using the supplied name.	 	 * 	 * @return an XMLReader	 * @exception SAXException when the supplied XMLReader class name can	 * not be found or instantiated.	 */	public static XMLReader createXMLReader(String name) 		throws SAXException	{		XMLReader reader = null;		try {			reader = _createXMLReader(name);		}		catch (ClassNotFoundException e) {			ThreadLog.error("Class " + name + " not found");			throw new SAXException(e);		}		catch (ClassCastException e) {			ThreadLog.error(name + " is not a valid XMLReader.");			throw new SAXException(e);		}		catch (Exception e) {			ThreadLog.error("Could not create instance of " + name);			throw new SAXException(e);		}		return reader;	}	protected static XMLReader _createXMLReader(String name) 		throws ClassNotFoundException, ClassCastException, InstantiationException, IllegalAccessException	{		return (XMLReader)Class.forName(name).newInstance();	}}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -