01: /*
02: * Copyright (c) 1998 by Groupe Bull. All Rights Reserved
03: * ParserFactory.java
04: * $Id: ParserFactory.java,v 1.1.1.1 1999/11/03 15:34:31 phk Exp $
05: */
06: package fr.dyade.koala.xml.sax;
07:
08: import org.xml.sax.Parser;
09: import org.xml.sax.SAXException;
10:
11: /**
12: * This class helps to create a SAX Parser.
13: *
14: * @version $Revision: 1.1.1.1 $
15: * @author Philippe Le Hégaret
16: */
17: public class ParserFactory extends org.xml.sax.helpers.ParserFactory {
18:
19: private final static String[] allParsers = {
20: "com.sun.xml.parser.Parser", "com.microstar.xml.SAXDriver",
21: "fr.dyade.koala.xml.sax.SAXParser",
22: "com.sun.xml.parser.ValidatingParser",
23: "com.ibm.xml.parser.SAXDriver",
24: "com.jclark.xml.sax.Driver",
25: "com.datachannel.xml.sax.SAXDriver",
26: "com.megginson.sax.LarkDriver",
27: "com.megginson.sax.MSXMLDriver" };
28:
29: /**
30: * Don't create a new ParserFactory
31: */
32: private ParserFactory() {
33:
34: }
35:
36: /**
37: * Creates a new SAX parser object using the system property
38: * `org.xml.sax.parser'.
39: * If no system property found, try to find a SAX Parser, here is the
40: * search list :
41: * <ol>
42: * <li>"com.sun.xml.parser.Parser"
43: * <li>"com.microstar.xml.SAXDriver"
44: * <li>"fr.dyade.koala.xml.sax.SAXParser"
45: * <li>"com.sun.xml.parser.ValidatingParser"
46: * <li>"com.ibm.xml.sax.Driver"
47: * <li>"com.jclark.xml.sax.Driver"
48: * <li>"com.datachannel.xml.sax.SAXDriver"
49: * <li>"com.megginson.sax.LarkDriver"
50: * <li>"com.megginson.sax.MSXMLDriver"
51: * </ol>
52: *
53: * @exception java.lang.ClassNotFoundException The SAX parser
54: * class was not found (check your CLASSPATH).
55: * @exception IllegalAccessException The SAX parser class was
56: * found, but you do not have permission to load
57: * it.
58: * @exception InstantiationException The SAX parser class was
59: * found but could not be instantiated.
60: * @exception java.lang.ClassCastException The SAX parser class
61: * was found and instantiated, but does not implement
62: * org.xml.sax.Parser.
63: */
64: public static Parser makeParser() throws ClassNotFoundException,
65: IllegalAccessException, InstantiationException,
66: ClassCastException {
67: try {
68: return org.xml.sax.helpers.ParserFactory.makeParser();
69: } catch (NullPointerException e) {
70: // ignore
71: } catch (SecurityException e) {
72: // ignore
73: }
74: for (int i = 0; i < allParsers.length; i++) {
75: try {
76: return org.xml.sax.helpers.ParserFactory
77: .makeParser(allParsers[i]);
78: } catch (ClassNotFoundException ex) {
79: // ignore
80: }
81: }
82: throw new ClassNotFoundException("No SAX Parser found.");
83: }
84:
85: }
|