KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > upgrade > UpgradeGBean


1 /**
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. 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 JavaDoc;
21 import java.io.FileInputStream JavaDoc;
22 import java.io.File JavaDoc;
23 import java.io.IOException JavaDoc;
24 import java.io.PrintWriter JavaDoc;
25 import java.io.FileWriter JavaDoc;
26 import java.io.Writer JavaDoc;
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: 486195 $ $Date: 2006-12-12 10:42:02 -0500 (Tue, 12 Dec 2006) $
34  */

35 public class UpgradeGBean {
36
37     public void execute(String JavaDoc[] args) throws Exception JavaDoc {
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 JavaDoc inputFile = args[0];
47         String JavaDoc outFile = args.length == 2? args[1]: inputFile + ".upgrade";
48         execute(inputFile, outFile);
49     }
50
51     public void execute(String JavaDoc infile, String JavaDoc outfile) throws IOException JavaDoc, XmlException {
52         File JavaDoc inFile = new File JavaDoc(infile);
53         if (!inFile.exists() || inFile.isDirectory()) {
54             throw new IOException JavaDoc("Input file " + inFile + " does not exist");
55         }
56         InputStream JavaDoc in = new FileInputStream JavaDoc(inFile);
57         File JavaDoc outFile = new File JavaDoc(outfile);
58         Writer JavaDoc out = new FileWriter JavaDoc(outFile);
59         PrintWriter JavaDoc outWriter = new PrintWriter JavaDoc(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 JavaDoc[] args) throws Exception JavaDoc {
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 JavaDoc[] {String JavaDoc[].class});
75         infoBuilder.addOperation("execute", new Class JavaDoc[] {String JavaDoc.class, String JavaDoc.class});
76         GBEAN_INFO = infoBuilder.getBeanInfo();
77     }
78
79     public static GBeanInfo getGBeanInfo() {
80         return GBEAN_INFO;
81     }
82 }
83
Popular Tags