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.InputStream;
022    
023    import org.w3c.dom.*;
024    
025    import org.objectweb.jac.util.URLInputStream;
026    
027    public class XmlConfig {
028        
029       //public static final String methodElementTagName = new String("method").intern();
030       public static final String methodElementTagName = "method";
031        
032       /**
033        *  @param fileLocation the xml file
034        *  @param targetClass the object will be operated on
035        */
036       public XmlConfig(InputStream inputStream, 
037                        String fileLocation, 
038                        Class targetClass)
039          throws Exception 
040       {
041          XmlParserJAXP xmlParser = new XmlParserJAXP();
042          Document document = xmlParser.parse( inputStream, false );
043    
044          // create an interpreter for the root element
045          ACElementInterpreter acElementInterpreter = new ACElementInterpreter();
046            
047          // create an interpreter for the XML document
048          DefaultDocumentInterpreter documentInterpreter = new DefaultDocumentInterpreter();
049            
050          // add the interpreter for the root element
051          documentInterpreter.setElementInterpreter( acElementInterpreter );
052            
053          // interpret xml and do method invocations        
054          documentInterpreter.interpret(document, targetClass);
055       }
056        
057       /**
058        *  Do some invocations on System.out
059        *
060        */
061       public static void main(String[] args) throws Exception {
062          if ( args.length != 2 )
063             System.err.println("usage: java XmlConfig <target_class> <xml_document>");
064          else
065             new XmlConfig( new URLInputStream(args[0]).getInputStream(), 
066                            args[0],
067                            Class.forName(args[1]) );
068            
069          System.exit(0);        
070       }    
071        
072    }