KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derby > iapi > tools > run


1 /*
2
3    Derby - Class org.apache.derby.iapi.tools.run
4
5    Licensed to the Apache Software Foundation (ASF) under one or more
6    contributor license agreements. See the NOTICE file distributed with
7    this work for additional information regarding copyright ownership.
8    The ASF licenses this file to You under the Apache License, Version 2.0
9    (the "License"); you may not use this file except in compliance with
10    the License. You may obtain a copy of the License at
11
12       http://www.apache.org/licenses/LICENSE-2.0
13
14    Unless required by applicable law or agreed to in writing, software
15    distributed under the License is distributed on an "AS IS" BASIS,
16    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17    See the License for the specific language governing permissions and
18    limitations under the License.
19
20  */

21
22 package org.apache.derby.iapi.tools;
23
24 import java.io.IOException JavaDoc;
25 import org.apache.derby.drda.NetworkServerControl;
26 import org.apache.derby.tools.dblook;
27 import org.apache.derby.tools.ij;
28 import org.apache.derby.tools.sysinfo;
29 import org.apache.derby.iapi.tools.i18n.LocalizedResource;
30
31 /**
32   <p>
33   The run class facilitates running the various Derby utilities with the
34   java -jar command. For example:
35   <p>
36   java -jar derbyrun.jar ij [-p propertiesfile] [sql script]<br>
37   java -jar derbyrun.jar sysinfo [-cp ...] [-cp help]<br>
38   java -jar derbyrun.jar dblook [args] (or no arguments for usage)<br>
39   java -jar derbyrun.jar server [args] (or no arguments for usage)<br>
40 */

41 public class run {
42
43   /**
44      Switch on the first argument to choose the tool, pass the remaining
45          arguments to the tool.
46    */

47   static public void main(String JavaDoc[] args) throws IOException JavaDoc {
48       if (args.length < 1) {
49           printUsage();
50       } else if (args[0].equals("ij")) {
51           ij.main(trimArgs(args));
52       } else if (args[0].equals("sysinfo")) {
53           sysinfo.main(trimArgs(args));
54       } else if (args[0].equals("dblook")) {
55           dblook.main(trimArgs(args));
56       } else if (args[0].equals("server")) {
57           NetworkServerControl.main(trimArgs(args));
58       } else printUsage();
59   }
60
61   /**
62        Private constructor. No instances allowed.
63    */

64   private run() {
65   }
66   
67   /**
68        Utility method to trim one element off of the argument array.
69        @param args the arguments array
70        @return trimmed the trimmed array
71    */

72   private static String JavaDoc[] trimArgs(String JavaDoc[] args)
73   {
74       String JavaDoc [] trimmed = new String JavaDoc[args.length - 1];
75       System.arraycopy(args, 1, trimmed, 0, args.length - 1);
76       return trimmed;
77   }
78
79   /**
80        Print the usage statement if the user didn't enter a valid choice
81        of tool.
82    */

83   public static void printUsage()
84   {
85       LocalizedResource locRes = LocalizedResource.getInstance();
86       System.err.println(locRes.getTextMessage("RUN_Usage"));
87   }
88 }
89
Popular Tags