KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jac > core > parsers > xml > JacXmlParser


1 /*
2   Copyright (C) 2002 Zachary Medico
3
4   This program is free software; you can redistribute it and/or modify
5   it under the terms of the GNU Lesser General Public License as
6   published by the Free Software Foundation; either version 2 of the
7   License, or (at your option) any later version.
8
9   This program is distributed in the hope that it will be useful,
10   but WITHOUT ANY WARRANTY; without even the implied warranty of
11   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12   GNU Lesser General Public License for more details.
13
14   You should have received a copy of the GNU Lesser General Public
15   License along with this program; if not, write to the Free Software
16   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
17   USA */

18
19 package org.objectweb.jac.core.parsers.xml;
20
21 import java.io.IOException JavaDoc;
22 import java.io.InputStream JavaDoc;
23 import java.util.List JavaDoc;
24 import java.util.Set JavaDoc;
25 import java.util.Vector JavaDoc;
26 import org.apache.log4j.Logger;
27 import org.objectweb.jac.core.InputStreamParser;
28 import org.w3c.dom.Document JavaDoc;
29
30 /**
31  * Adapter for org.objectweb.jac.core.Parser
32  */

33 public class JacXmlParser implements InputStreamParser {
34     static Logger logger = Logger.getLogger("xml");
35     
36     private DefaultDocumentInterpreter documentInterpreter;
37     private XmlParser xmlParser;
38     
39     /**
40      * The DocumentInterpreter always receives a Vector as the Object argument in interpret()
41      */

42     public JacXmlParser() {
43         documentInterpreter = new DefaultDocumentInterpreter();
44         documentInterpreter.setElementInterpreter(new ACElementInterpreter());
45         xmlParser = new XmlParserJAXP();
46     }
47     
48     /**
49      * Parse a stream.
50      */

51     public List JavaDoc parse(InputStream JavaDoc input, String JavaDoc filePath,
52                       String JavaDoc targetClassName, Set JavaDoc blockKeywords)
53         throws IOException JavaDoc
54     {
55         Vector JavaDoc vector = new Vector JavaDoc();
56         try {
57             Document JavaDoc document = xmlParser.parse(input, false);
58             logger.debug("XML parsed "+filePath);
59             vector = documentInterpreter.interpret(
60                 document,
61                 Class.forName(targetClassName));
62         } catch (Exception JavaDoc e) {
63             throw new IOException JavaDoc(e.getMessage());
64         }
65         return vector;
66     }
67 }
68
Popular Tags