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.cli.client;
018    
019    import java.io.OutputStream;
020    
021    import org.apache.geronimo.cli.BaseCLParser;
022    import org.apache.geronimo.cli.CLParserException;
023    import org.apache.geronimo.cli.PrintHelper;
024    
025    
026    /**
027     * @version $Rev: 476049 $ $Date: 2006-11-17 15:35:17 +1100 (Fri, 17 Nov 2006) $
028     */
029    public class ClientCLParser extends BaseCLParser {
030        
031        public ClientCLParser(OutputStream out) {
032            super(out);
033        }
034    
035        public String getApplicationClientConfiguration() {
036            String[] args = commandLine.getArgs();
037            return args[0];
038        }
039        
040        public String[] getApplicationClientArgs() {
041            String[] args = commandLine.getArgs();
042            String[] newArgs = new String[args.length - 1];
043            System.arraycopy(args, 1, newArgs, 0, newArgs.length);
044            return newArgs;
045        }
046        
047        @Override
048        protected void validateRemainingArgs() throws CLParserException {
049            if (0 == commandLine.getArgs().length) {
050                throw new CLParserException("No configuration provided");
051            }
052        }
053    
054        public void displayHelp() {
055            PrintHelper printHelper = new PrintHelper(System.out);
056            printHelper.printHelp("java -jar bin/client.jar $options config-name [app_arg ...]",
057                    "\nThe following options are available:",
058                    options,
059                    "\nThe first argument should identify the Geronimo configuration that "
060                            + "contains the application client you want to run." + "\n"
061                            + "The rest of the arguments will be passed as arguments to the "
062                            + "application client when it is started.",
063                    true);
064        }
065    
066    }