View Javadoc

1   
2   package org.onemind.commons.java.datastructure;
3   
4   import java.io.*;
5   import java.sql.Types;
6   import java.util.HashMap;
7   import java.util.Map;
8   import javax.xml.parsers.*;
9   import org.onemind.commons.java.lang.reflect.ReflectUtils;
10  import org.onemind.commons.java.xml.digest.*;
11  import org.xml.sax.Attributes;
12  import org.xml.sax.SAXException;
13  /***
14   * An XmlPropertiesReader read a properties out of an xml file. The xml is read
15   * using dom parser. It support all the java primitive types 
16   * and in addition creation of instance of ElementDigester
17   * @author TiongHiang Lee (thlee@onemindsoft.org)
18   * @version $Id: XmlProperties.java,v 1.3 2005/06/22 22:57:52 thlee Exp $ $Name:  $
19   */
20  public class XmlProperties extends HashMap
21  {
22      /***
23       * Constructor
24       * @param filename the file name
25       * @throws FileNotFoundException
26       * @throws IOException
27       * @throws SAXException
28       * @throws ParserConfigurationException
29       */
30      public XmlProperties(String filename) throws FileNotFoundException, ParserConfigurationException, SAXException, IOException
31      {
32          this(new FileInputStream(filename));
33      }
34  
35      /***
36       * Constructor
37       * @param stream
38       * @throws ParserConfigurationException
39       * @throws SAXException
40       * @throws IOException
41       */
42      public XmlProperties(InputStream is) throws ParserConfigurationException, SAXException, IOException
43      {
44          SAXParserFactory factory = SAXParserFactory.newInstance();
45          // Parse the input
46          SAXParser saxParser = factory.newSAXParser();
47          SaxDigesterHandler handler = new SaxDigesterHandler();
48          handler.addDigester("Properties", new XmlPropertyElementDigester("Property", this));
49          saxParser.parse(is, handler);
50      }
51  }