From 6d0e93c68d3aeaeb4bb6d96ac0460eec40ef786e Mon Sep 17 00:00:00 2001 From: lresende Date: Wed, 11 Nov 2009 23:13:23 +0000 Subject: Moving 1.x branches git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@835143 13f79535-47bb-0310-9956-ffa450edef68 --- .../utils/xmlfromxsd/CmdLineArgsProcessor.java | 79 ++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/containers/container.javascript/src/main/java/org/apache/tuscany/container/javascript/utils/xmlfromxsd/CmdLineArgsProcessor.java (limited to 'sca-java-1.x/branches/sca-java-M2/sca/services/containers/container.javascript/src/main/java/org/apache/tuscany/container/javascript/utils/xmlfromxsd/CmdLineArgsProcessor.java') diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/containers/container.javascript/src/main/java/org/apache/tuscany/container/javascript/utils/xmlfromxsd/CmdLineArgsProcessor.java b/sca-java-1.x/branches/sca-java-M2/sca/services/containers/container.javascript/src/main/java/org/apache/tuscany/container/javascript/utils/xmlfromxsd/CmdLineArgsProcessor.java new file mode 100644 index 0000000000..914f1d03f2 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/containers/container.javascript/src/main/java/org/apache/tuscany/container/javascript/utils/xmlfromxsd/CmdLineArgsProcessor.java @@ -0,0 +1,79 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.container.javascript.utils.xmlfromxsd; + +/** + * This class provides a generic command line arguments processing utility. The processArgs + * method of this class processes the command line arguments that could contain option flags, + * options and values and calls a ArgumentHanlder instance for handling the agruments. + * + */ +public class CmdLineArgsProcessor { + private String printUsageMessage = "No hints available on Usage!"; + + private CmdLineArgsHandler argsHandler = null; + + public static final String HYPEN = "-"; + + public void processArgs(String[] args) { + try { + if (args.length == 0) { + printUsage(); + } else { + parseAndHandleArgs(args); + } + } catch (Exception e) { + System.out.println("Exception in processing argument - " + e); + printUsage(); + } + + } + + public void parseAndHandleArgs(String[] args) throws Exception { + int index = 0; + while (index < args.length - 1) { + if (args[index].startsWith(HYPEN) && !args[index + 1].startsWith(HYPEN)) { + argsHandler.handleArgument(args[index].substring(1), args[index + 1]); + index = index + 2; + } else { + throw new IllegalArgumentException("Wrong Usage of options!"); + } + } + } + + protected void printUsage() { + + } + + public CmdLineArgsHandler getArgsHandler() { + return argsHandler; + } + + public void setArgsHandler(CmdLineArgsHandler argsHandler) { + this.argsHandler = argsHandler; + } + + public String getPrintUsageMessage() { + return printUsageMessage; + } + + public void setPrintUsageMessage(String printUsageMessage) { + this.printUsageMessage = printUsageMessage; + } +} -- cgit v1.2.3