1 package net.sf.tomp.xtcl.source;
2
3 import javax.xml.transform.sax.SAXSource;
4
5 import net.sf.tomp.xml.sax.ParametrizedXMLReader;
6
7 import org.xml.sax.InputSource;
8 import org.xml.sax.XMLReader;
9
10 /***
11 * Creates either a normal SAXSource or XTSAXSource which is parametrized.
12 *
13 * @author tomp
14 */
15 public class XTSourceFactoryImpl implements XTSourceFactory {
16 /***
17 * Creates either a normal SAXSource or XTSAXSource which is parametrized.
18 *
19 * @param className class name of XMLReader used to create the SAXSource
20 * @param is InputSource to be read by the XMLReader
21 * @return the SAXSource or XTSAXSource
22 * @throws ClassNotFoundException
23 * @throws InstantiationException
24 * @throws IllegalAccessException
25 */
26 public SAXSource newSAXSource(String className, InputSource is)
27 throws ClassNotFoundException, InstantiationException,
28 IllegalAccessException {
29 Class readerClass = Class.forName(className);
30 XMLReader f = (XMLReader) readerClass.newInstance();
31
32 if (f instanceof ParametrizedXMLReader) {
33 return new XTSAXSource((ParametrizedXMLReader) f, is);
34 } else {
35 return new SAXSource(f, is);
36 }
37 }
38 }
39
40
41
42
43
44
45
46
47
48
49