001: // SAX parser factory.
002: // http://www.saxproject.org
003: // No warranty; no copyright -- use this as you will.
004: // $Id: ParserFactory.java,v 1.1.1.1 2002/05/03 23:29:43 yuvalo Exp $
005:
006: package org.xml.sax.helpers;
007:
008: import java.lang.ClassNotFoundException;
009: import java.lang.IllegalAccessException;
010: import java.lang.InstantiationException;
011: import java.lang.SecurityException;
012: import java.lang.ClassCastException;
013:
014: import org.xml.sax.Parser;
015:
016: /**
017: * Java-specific class for dynamically loading SAX parsers.
018: *
019: * <blockquote>
020: * <em>This module, both source code and documentation, is in the
021: * Public Domain, and comes with <strong>NO WARRANTY</strong>.</em>
022: * See <a href='http://www.saxproject.org'>http://www.saxproject.org</a>
023: * for further information.
024: * </blockquote>
025: *
026: * <p><strong>Note:</strong> This class is designed to work with the now-deprecated
027: * SAX1 {@link org.xml.sax.Parser Parser} class. SAX2 applications should use
028: * {@link org.xml.sax.helpers.XMLReaderFactory XMLReaderFactory} instead.</p>
029: *
030: * <p>ParserFactory is not part of the platform-independent definition
031: * of SAX; it is an additional convenience class designed
032: * specifically for Java XML application writers. SAX applications
033: * can use the static methods in this class to allocate a SAX parser
034: * dynamically at run-time based either on the value of the
035: * `org.xml.sax.parser' system property or on a string containing the class
036: * name.</p>
037: *
038: * <p>Note that the application still requires an XML parser that
039: * implements SAX1.</p>
040: *
041: * @deprecated This class works with the deprecated
042: * {@link org.xml.sax.Parser Parser}
043: * interface.
044: * @since SAX 1.0
045: * @author David Megginson
046: * @version 2.0.1 (sax2r2)
047: */
048: public class ParserFactory {
049:
050: /**
051: * Private null constructor.
052: */
053: private ParserFactory() {
054: }
055:
056: /**
057: * Create a new SAX parser using the `org.xml.sax.parser' system property.
058: *
059: * <p>The named class must exist and must implement the
060: * {@link org.xml.sax.Parser Parser} interface.</p>
061: *
062: * @exception java.lang.NullPointerException There is no value
063: * for the `org.xml.sax.parser' system property.
064: * @exception java.lang.ClassNotFoundException The SAX parser
065: * class was not found (check your CLASSPATH).
066: * @exception IllegalAccessException The SAX parser class was
067: * found, but you do not have permission to load
068: * it.
069: * @exception InstantiationException The SAX parser class was
070: * found but could not be instantiated.
071: * @exception java.lang.ClassCastException The SAX parser class
072: * was found and instantiated, but does not implement
073: * org.xml.sax.Parser.
074: * @see #makeParser(java.lang.String)
075: * @see org.xml.sax.Parser
076: */
077: public static Parser makeParser() throws ClassNotFoundException,
078: IllegalAccessException, InstantiationException,
079: NullPointerException, ClassCastException {
080: String className = System.getProperty("org.xml.sax.parser");
081: if (className == null) {
082: throw new NullPointerException(
083: "No value for sax.parser property");
084: } else {
085: return makeParser(className);
086: }
087: }
088:
089: /**
090: * Create a new SAX parser object using the class name provided.
091: *
092: * <p>The named class must exist and must implement the
093: * {@link org.xml.sax.Parser Parser} interface.</p>
094: *
095: * @param className A string containing the name of the
096: * SAX parser class.
097: * @exception java.lang.ClassNotFoundException The SAX parser
098: * class was not found (check your CLASSPATH).
099: * @exception IllegalAccessException The SAX parser class was
100: * found, but you do not have permission to load
101: * it.
102: * @exception InstantiationException The SAX parser class was
103: * found but could not be instantiated.
104: * @exception java.lang.ClassCastException The SAX parser class
105: * was found and instantiated, but does not implement
106: * org.xml.sax.Parser.
107: * @see #makeParser()
108: * @see org.xml.sax.Parser
109: */
110: public static Parser makeParser(String className)
111: throws ClassNotFoundException, IllegalAccessException,
112: InstantiationException, ClassCastException {
113: return (Parser) NewInstance.newInstance(NewInstance
114: .getClassLoader(), className);
115: }
116:
117: }
|