KickJava   Java API By Example, From Geeks To Geeks.

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


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.InputStream JavaDoc;
22
23 import org.w3c.dom.*;
24
25 import org.objectweb.jac.util.URLInputStream;
26
27 public class XmlConfig {
28     
29    //public static final String methodElementTagName = new String("method").intern();
30
public static final String JavaDoc methodElementTagName = "method";
31     
32    /**
33     * @param fileLocation the xml file
34     * @param targetClass the object will be operated on
35     */

36    public XmlConfig(InputStream JavaDoc inputStream,
37                     String JavaDoc fileLocation,
38                     Class JavaDoc targetClass)
39       throws Exception JavaDoc
40    {
41       XmlParserJAXP xmlParser = new XmlParserJAXP();
42       Document document = xmlParser.parse( inputStream, false );
43
44       // create an interpreter for the root element
45
ACElementInterpreter acElementInterpreter = new ACElementInterpreter();
46         
47       // create an interpreter for the XML document
48
DefaultDocumentInterpreter documentInterpreter = new DefaultDocumentInterpreter();
49         
50       // add the interpreter for the root element
51
documentInterpreter.setElementInterpreter( acElementInterpreter );
52         
53       // interpret xml and do method invocations
54
documentInterpreter.interpret(document, targetClass);
55    }
56     
57    /**
58     * Do some invocations on System.out
59     *
60     */

61    public static void main(String JavaDoc[] args) throws Exception JavaDoc {
62       if ( args.length != 2 )
63          System.err.println("usage: java XmlConfig <target_class> <xml_document>");
64       else
65          new XmlConfig( new URLInputStream(args[0]).getInputStream(),
66                         args[0],
67                         Class.forName(args[1]) );
68         
69       System.exit(0);
70    }
71     
72 }
73
Popular Tags