001    /**
002     *  Licensed to the Apache Software Foundation (ASF) under one or more
003     *  contributor license agreements.  See the NOTICE file distributed with
004     *  this work for additional information regarding copyright ownership.
005     *  The ASF licenses this file to You under the Apache License, Version 2.0
006     *  (the "License"); you may not use this file except in compliance with
007     *  the License.  You may obtain a copy of the License at
008     *
009     *     http://www.apache.org/licenses/LICENSE-2.0
010     *
011     *  Unless required by applicable law or agreed to in writing, software
012     *  distributed under the License is distributed on an "AS IS" BASIS,
013     *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014     *  See the License for the specific language governing permissions and
015     *  limitations under the License.
016     */
017    
018    package org.apache.geronimo.upgrade;
019    
020    import java.io.InputStream;
021    import java.io.FileInputStream;
022    import java.io.File;
023    import java.io.IOException;
024    import java.io.PrintWriter;
025    import java.io.FileWriter;
026    import java.io.Writer;
027    
028    import org.apache.xmlbeans.XmlException;
029    import org.apache.geronimo.gbean.GBeanInfo;
030    import org.apache.geronimo.gbean.GBeanInfoBuilder;
031    
032    /**
033     * @version $Rev: 486195 $ $Date: 2006-12-12 10:42:02 -0500 (Tue, 12 Dec 2006) $
034     */
035    public class UpgradeGBean {
036    
037        public void execute(String[] args) throws Exception {
038            if (args == null || args.length == 0 || args.length > 2) {
039                System.out.println("Parameter usage: ");
040                System.out.println("inputPlan outputPlan");
041                System.out.println("or");
042                System.out.println("inputPlan");
043                System.out.println("in which case the output will be in the same location as inputPlan with '.upgraded' appended");
044                return;
045            }
046            String inputFile = args[0];
047            String outFile = args.length == 2? args[1]: inputFile + ".upgrade";
048            execute(inputFile, outFile);
049        }
050    
051        public void execute(String infile, String outfile) throws IOException, XmlException {
052            File inFile = new File(infile);
053            if (!inFile.exists() || inFile.isDirectory()) {
054                throw new IOException("Input file " + inFile + " does not exist");
055            }
056            InputStream in = new FileInputStream(inFile);
057            File outFile = new File(outfile);
058            Writer out = new FileWriter(outFile);
059            PrintWriter outWriter = new PrintWriter(out);
060            new Upgrade1_0To1_1().upgrade(in, outWriter);
061            outWriter.flush();
062            outWriter.close();
063            in.close();
064        }
065    
066        public static void main(String[] args) throws Exception {
067            new UpgradeGBean().execute(args);
068        }
069    
070        public static final GBeanInfo GBEAN_INFO;
071    
072        static {
073            GBeanInfoBuilder infoBuilder = GBeanInfoBuilder.createStatic(UpgradeGBean.class);
074            infoBuilder.addOperation("execute", new Class[] {String[].class});
075            infoBuilder.addOperation("execute", new Class[] {String.class, String.class});
076            GBEAN_INFO = infoBuilder.getBeanInfo();
077        }
078    
079        public static GBeanInfo getGBeanInfo() {
080            return GBEAN_INFO;
081        }
082    }