KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > xdoclet > loader > XDocletXmlParser


1 /*
2  * Copyright (c) 2001, 2002 The XDoclet team
3  * All rights reserved.
4  */

5 package xdoclet.loader;
6
7 import java.io.IOException JavaDoc;
8
9 import javax.xml.parsers.ParserConfigurationException JavaDoc;
10 import javax.xml.parsers.SAXParser JavaDoc;
11 import javax.xml.parsers.SAXParserFactory JavaDoc;
12
13 import org.xml.sax.Attributes JavaDoc;
14 import org.xml.sax.InputSource JavaDoc;
15 import org.xml.sax.SAXException JavaDoc;
16 import org.xml.sax.SAXParseException JavaDoc;
17 import org.xml.sax.helpers.DefaultHandler JavaDoc;
18
19 /**
20  * Parses xdoclet.xml deployment descriptor
21  *
22  * @author <a HREF="mailto:aslak.nospam@users.sf.net">Aslak Hellesøy</a>
23  * @created 7. april 2002
24  * @version $Revision: 1.7 $
25  */

26 class XDocletXmlParser extends DefaultHandler JavaDoc
27 {
28     private final SAXParserFactory JavaDoc _factory;
29     private XDocletModule module;
30
31     public XDocletXmlParser()
32     {
33         _factory = SAXParserFactory.newInstance();
34         _factory.setValidating(false);
35     }
36
37     /**
38      * @param in
39      * @return
40      * @todo log some sensible error messages
41      */

42     public XDocletModule parse(InputSource JavaDoc in)
43     {
44         try {
45             SAXParser JavaDoc parser = _factory.newSAXParser();
46
47             parser.parse(in, this);
48         }
49         catch (IOException JavaDoc e) {
50             module = null;
51             e.printStackTrace();
52         }
53         catch (IllegalArgumentException JavaDoc e) {
54             module = null;
55             e.printStackTrace();
56         }
57         catch (ParserConfigurationException JavaDoc e) {
58             module = null;
59             e.printStackTrace();
60         }
61         catch (SAXParseException JavaDoc e) {
62             module = null;
63             e.printStackTrace();
64             System.out.println("location:" + in.getSystemId() + ":" + e.getLineNumber() + "," + e.getColumnNumber());
65         }
66         catch (SAXException JavaDoc e) {
67             module = null;
68             e.printStackTrace();
69             System.out.println("location:" + in.getSystemId());
70         }
71         return module;
72     }
73
74     public void startDocument()
75     {
76         module = new XDocletModule();
77     }
78
79     public void startElement(String JavaDoc namespaceURI, String JavaDoc localName, String JavaDoc qName, Attributes JavaDoc attributes)
80     {
81
82         if (qName.equals("taghandler")) {
83             module.addTagHandler(
84                 attributes.getValue("namespace"),
85                 attributes.getValue("class")
86                 );
87         }
88         else
89             if (qName.equals("subtask")) {
90             module.addSubTask(
91                 attributes.getValue("name"),
92                 attributes.getValue("implementation-class"),
93                 attributes.getValue("parent-task-class")
94                 );
95         }
96     }
97 }
98
Popular Tags