001/*
002 *                    BioJava development code
003 *
004 * This code may be freely distributed and modified under the
005 * terms of the GNU Lesser General Public Licence.  This should
006 * be distributed with the code.  If you do not have a copy,
007 * see:
008 *
009 *      http://www.gnu.org/copyleft/lesser.html
010 *
011 * Copyright for this code is held jointly by the individual
012 * authors.  These should be listed in @author doc comments.
013 *
014 * For more information on the BioJava project and its aims,
015 * or to join the biojava-l mailing list, visit the home page
016 * at:
017 *
018 *      http://www.biojava.org/
019 *
020 */
021
022package org.biojava.utils.xml;
023
024import java.io.FileInputStream;
025
026import javax.xml.parsers.DocumentBuilder;
027import javax.xml.parsers.DocumentBuilderFactory;
028
029import org.w3c.dom.Document;
030import org.xml.sax.InputSource;
031
032/**
033 * Create a bean from an XML file, then attempt to enter it.
034 *
035 * @author Thomas Down
036 */
037
038public class AppBeanRunner {
039    public static void main(String[] args) {
040        try {
041            if (args.length != 1) {
042                throw new RuntimeException("Usage: java eponine.AppBeanRunner app.xml");
043            }
044            String name = args[0];
045
046            String[] altArgs = new String[args.length - 1];
047            for (int i = 1; i < args.length; ++i)
048                altArgs[i-1] = args[i];
049            
050            InputSource is = new InputSource(new FileInputStream(name));
051            DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
052            dbf.setValidating(false);
053            DocumentBuilder parser = dbf.newDocumentBuilder();
054            Document doc = parser.parse(is);
055            Object bean = XMLBeans.INSTANCE.instantiateBean(doc.getDocumentElement());
056            if (! (bean instanceof AppEntry)) {
057                System.out.println("Application can't be entered");
058                return;
059            }
060            
061            ((AppEntry) bean).start(altArgs);
062        } catch (Exception ex) {
063            ex.printStackTrace();
064        }
065    }
066}