001 /**
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements. See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License. You may obtain a copy of the License at
008 *
009 * http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017 package org.apache.geronimo.system.main;
018
019 import java.util.Collections;
020
021 import org.apache.geronimo.cli.CLParserException;
022 import org.apache.geronimo.cli.client.ClientCLParser;
023 import org.apache.geronimo.gbean.AbstractName;
024 import org.apache.geronimo.gbean.AbstractNameQuery;
025 import org.apache.geronimo.kernel.Jsr77Naming;
026 import org.apache.geronimo.kernel.repository.Artifact;
027
028 /**
029 * @version $Revision: 706640 $ $Date: 2008-10-21 14:44:05 +0000 (Tue, 21 Oct 2008) $
030 */
031 public class ClientCommandLine extends CommandLine {
032
033 /**
034 * Command line entry point called by executable jar
035 * @param args command line args
036 */
037 public static void main(String[] args) {
038 ClientCLParser parser = new ClientCLParser(System.out);
039 try {
040 parser.parse(args);
041 } catch (CLParserException e) {
042 System.err.println(e.getMessage());
043 parser.displayHelp();
044 System.exit(1);
045 }
046
047 ClientCommandLine clientCommandLine = new ClientCommandLine();
048 int exitCode = clientCommandLine.execute(parser);
049 System.exit(exitCode);
050 }
051
052 public ClientCommandLine(Artifact configuration, String[] args) throws Exception {
053 startClient(configuration, args);
054 }
055
056 protected ClientCommandLine() {
057 }
058
059 public int execute(ClientCLParser parser) {
060 log.info("Client startup begun");
061 try {
062 Artifact configuration = Artifact.create(parser.getApplicationClientConfiguration());
063 return startClient(configuration, parser.getApplicationClientArgs());
064 } catch (Exception e) {
065 ExceptionUtil.trimStackTrace(e);
066 log.error("Client failed with exception: ", e);
067 return 2;
068 }
069 }
070
071 protected int startClient(Artifact configuration, String[] args) throws Exception {
072 Jsr77Naming naming = new Jsr77Naming();
073 //this kinda sucks, but resource adapter modules deployed on the client insist on having a
074 //J2EEApplication name component
075 AbstractName baseName = naming.createRootName(configuration, configuration.toString(), "J2EEApplication");
076 AbstractNameQuery baseNameQuery = new AbstractNameQuery(baseName);
077 invokeMainGBean(Collections.singletonList(configuration), baseNameQuery, "main", args);
078 return 0;
079 }
080 }