01: /*
02:
03: Derby - Class org.apache.derby.iapi.tools.run
04:
05: Licensed to the Apache Software Foundation (ASF) under one or more
06: contributor license agreements. See the NOTICE file distributed with
07: this work for additional information regarding copyright ownership.
08: The ASF licenses this file to You under the Apache License, Version 2.0
09: (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;
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[] args) throws IOException {
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
59: printUsage();
60: }
61:
62: /**
63: Private constructor. No instances allowed.
64: */
65: private run() {
66: }
67:
68: /**
69: Utility method to trim one element off of the argument array.
70: @param args the arguments array
71: @return trimmed the trimmed array
72: */
73: private static String[] trimArgs(String[] args) {
74: String[] trimmed = new String[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: LocalizedResource locRes = LocalizedResource.getInstance();
85: System.err.println(locRes.getTextMessage("RUN_Usage"));
86: }
87: }
|