KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > system > main > ClientCommandLine


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 package org.apache.geronimo.system.main;
18
19 import java.util.Collections JavaDoc;
20
21 import org.apache.geronimo.gbean.AbstractName;
22 import org.apache.geronimo.gbean.AbstractNameQuery;
23 import org.apache.geronimo.kernel.Jsr77Naming;
24 import org.apache.geronimo.kernel.repository.Artifact;
25
26 /**
27  * @version $Revision: 476049 $ $Date: 2006-11-16 23:35:17 -0500 (Thu, 16 Nov 2006) $
28  */

29 public class ClientCommandLine extends CommandLine {
30     /**
31      * Command line entry point called by executable jar
32      * @param args command line args
33      */

34     public static void main(String JavaDoc[] args) {
35         log.info("Client startup begun");
36         if(args.length == 0) {
37             System.out.println();
38             System.out.println("ERROR: No arguments");
39             showHelp();
40             System.exit(1);
41         } else if(args[0].equals("--help") || args[0].equals("-h") || args[0].equals("/?")) {
42             showHelp();
43             System.exit(0);
44         }
45         try {
46             Artifact configuration = Artifact.create(args[0]);
47             String JavaDoc[] clientArgs = new String JavaDoc[args.length -1];
48             System.arraycopy(args, 1, clientArgs, 0, clientArgs.length);
49             new ClientCommandLine(configuration, clientArgs);
50         } catch (Exception JavaDoc e) {
51             ExceptionUtil.trimStackTrace(e);
52             e.printStackTrace();
53             System.exit(2);
54             throw new AssertionError JavaDoc();
55         }
56     }
57
58     private static void showHelp() {
59         System.out.println();
60         System.out.println("syntax: java -jar bin/client.jar config-name [app arg] [app arg] ...");
61         System.out.println();
62         System.out.println("The first argument should identify the Geronimo configuration that");
63         System.out.println("contains the application client you want to run.");
64         System.out.println();
65         System.out.println("The rest of the arguments will be passed as arguments to the");
66         System.out.println("application client when it is started.");
67         System.out.println();
68     }
69
70
71     public ClientCommandLine(Artifact configuration, String JavaDoc[] args) throws Exception JavaDoc {
72         Jsr77Naming naming = new Jsr77Naming();
73         //this kinda sucks, but resource adapter modules deployed on the client insist on having a
74
//J2EEApplication name component
75
AbstractName baseName = naming.createRootName(configuration, configuration.toString(), "J2EEApplication");
76         AbstractNameQuery baseNameQuery = new AbstractNameQuery(baseName);
77         invokeMainGBean(Collections.singletonList(configuration), baseNameQuery, "main", args);
78     }
79 }
80
Popular Tags