1 /**
2 *
3 * Copyright 2006 The Apache Software Foundation
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18 package org.apache.geronimo.upgrade;
19
20 import java.io.InputStream;
21 import java.io.FileInputStream;
22 import java.io.File;
23 import java.io.IOException;
24 import java.io.PrintWriter;
25 import java.io.FileWriter;
26 import java.io.Writer;
27
28 import org.apache.xmlbeans.XmlException;
29 import org.apache.geronimo.gbean.GBeanInfo;
30 import org.apache.geronimo.gbean.GBeanInfoBuilder;
31
32 /**
33 * @version $Rev: 430508 $ $Date: 2006-08-10 12:56:47 -0700 (Thu, 10 Aug 2006) $
34 */
35 public class UpgradeGBean {
36
37 public void execute(String[] args) throws Exception {
38 if (args == null || args.length == 0 || args.length > 2) {
39 System.out.println("Parameter usage: ");
40 System.out.println("inputPlan outputPlan");
41 System.out.println("or");
42 System.out.println("inputPlan");
43 System.out.println("in which case the output will be in the same location as inputPlan with '.upgraded' appended");
44 return;
45 }
46 String inputFile = args[0];
47 String outFile = args.length == 2? args[1]: inputFile + ".upgrade";
48 execute(inputFile, outFile);
49 }
50
51 public void execute(String infile, String outfile) throws IOException, XmlException {
52 File inFile = new File(infile);
53 if (!inFile.exists() || inFile.isDirectory()) {
54 throw new IOException("Input file " + inFile + " does not exist");
55 }
56 InputStream in = new FileInputStream(inFile);
57 File outFile = new File(outfile);
58 Writer out = new FileWriter(outFile);
59 PrintWriter outWriter = new PrintWriter(out);
60 new Upgrade1_0To1_1().upgrade(in, outWriter);
61 outWriter.flush();
62 outWriter.close();
63 in.close();
64 }
65
66 public static void main(String[] args) throws Exception {
67 new UpgradeGBean().execute(args);
68 }
69
70 public static final GBeanInfo GBEAN_INFO;
71
72 static {
73 GBeanInfoBuilder infoBuilder = GBeanInfoBuilder.createStatic(UpgradeGBean.class);
74 infoBuilder.addOperation("execute", new Class[] {String[].class});
75 infoBuilder.addOperation("execute", new Class[] {String.class, String.class});
76 GBEAN_INFO = infoBuilder.getBeanInfo();
77 }
78
79 public static GBeanInfo getGBeanInfo() {
80 return GBEAN_INFO;
81 }
82 }