001 /* 002 Copyright (C) 2002 Zachary Medico 003 004 This program is free software; you can redistribute it and/or modify 005 it under the terms of the GNU Lesser General Public License as 006 published by the Free Software Foundation; either version 2 of the 007 License, or (at your option) any later version. 008 009 This program is distributed in the hope that it will be useful, 010 but WITHOUT ANY WARRANTY; without even the implied warranty of 011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 012 GNU Lesser General Public License for more details. 013 014 You should have received a copy of the GNU Lesser General Public 015 License along with this program; if not, write to the Free Software 016 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 017 USA */ 018 019 package org.objectweb.jac.core.parsers.xml; 020 021 import java.io.IOException; 022 import java.io.InputStream; 023 import java.util.List; 024 import java.util.Set; 025 import java.util.Vector; 026 import org.apache.log4j.Logger; 027 import org.objectweb.jac.core.InputStreamParser; 028 import org.w3c.dom.Document; 029 030 /** 031 * Adapter for org.objectweb.jac.core.Parser 032 */ 033 public class JacXmlParser implements InputStreamParser { 034 static Logger logger = Logger.getLogger("xml"); 035 036 private DefaultDocumentInterpreter documentInterpreter; 037 private XmlParser xmlParser; 038 039 /** 040 * The DocumentInterpreter always receives a Vector as the Object argument in interpret() 041 */ 042 public JacXmlParser() { 043 documentInterpreter = new DefaultDocumentInterpreter(); 044 documentInterpreter.setElementInterpreter(new ACElementInterpreter()); 045 xmlParser = new XmlParserJAXP(); 046 } 047 048 /** 049 * Parse a stream. 050 */ 051 public List parse(InputStream input, String filePath, 052 String targetClassName, Set blockKeywords) 053 throws IOException 054 { 055 Vector vector = new Vector(); 056 try { 057 Document document = xmlParser.parse(input, false); 058 logger.debug("XML parsed "+filePath); 059 vector = documentInterpreter.interpret( 060 document, 061 Class.forName(targetClassName)); 062 } catch (Exception e) { 063 throw new IOException(e.getMessage()); 064 } 065 return vector; 066 } 067 }