View Javadoc

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   * The contents of this file are subject to the Mozilla Public License Version
42   * 1.1 (the "License"); you may not use this file except in compliance with the
43   * License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
44   * Software distributed under the License is distributed on an "AS IS" basis,
45   * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
46   * the specific language governing rights and limitations under the License. The
47   * Original Code is: all this file. The Initial Developer of the Original Code
48   * is: Tomas Pitner, Masaryk University in Brno, Czech Republic. Contributor(s):
49   */