You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@oodt.apache.org by bf...@apache.org on 2011/11/10 18:27:30 UTC

svn commit: r1200439 [1/2] - in /oodt/trunk/cli/src: main/java/org/apache/oodt/cas/cli/ main/java/org/apache/oodt/cas/cli/action/ main/java/org/apache/oodt/cas/cli/action/store/ main/java/org/apache/oodt/cas/cli/action/store/spring/ main/java/org/apach...

Author: bfoster
Date: Thu Nov 10 17:27:28 2011
New Revision: 1200439

URL: http://svn.apache.org/viewvc?rev=1200439&view=rev
Log:
- bug fixes
- CmdLinePrinter cleanedup
- stacktrace printout controlled and cleaned up
- can use offline now... fixed spring schemalocation
- updated unit-tests

Added:
    oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/exception/CmdLineActionException.java   (with props)
    oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/exception/CmdLineActionExecutionException.java   (with props)
    oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/exception/CmdLineActionStoreException.java   (with props)
    oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/exception/CmdLineOptionStoreException.java   (with props)
    oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/exception/CmdLineParserException.java   (with props)
    oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/exception/CmdLineUtilityException.java   (with props)
    oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/presenter/
      - copied from r1198889, oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/help/presenter/
    oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/presenter/CmdLinePresenter.java   (with props)
    oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/presenter/StdCmdLinePresenter.java   (with props)
    oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/printer/
    oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/printer/CmdLinePrinter.java   (with props)
    oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/printer/StdCmdLinePrinter.java   (with props)
Removed:
    oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/help/presenter/
    oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/help/printer/
    oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/presenter/CmdLineOptionHelpPresenter.java
    oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/presenter/StdCmdLineOptionHelpPresenter.java
Modified:
    oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/CmdLineArgs.java
    oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/CmdLineUtility.java
    oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/action/CmdLineAction.java
    oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/action/store/CmdLineActionStore.java
    oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/action/store/CmdLineActionStoreFactory.java
    oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/action/store/spring/SpringCmdLineActionStore.java
    oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/action/store/spring/SpringCmdLineActionStoreFactory.java
    oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/contruct/StdCmdLineConstructor.java
    oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/store/CmdLineOptionStore.java
    oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/store/spring/SpringCmdLineOptionStore.java
    oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/store/spring/SpringCmdLineOptionStoreFactory.java
    oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/validator/AllowedArgsCmdLineOptionValidator.java
    oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/validator/ArgRegExpCmdLineOptionValidator.java
    oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/validator/ClassExistsCmdLineOptionValidator.java
    oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/validator/CmdLineOptionValidator.java
    oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/validator/FileExistCmdLineOptionValidator.java
    oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/validator/NoRestrictionsCmdLineOptionValidator.java
    oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/parser/CmdLineParser.java
    oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/parser/StdCmdLineParser.java
    oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/util/CmdLineIterable.java
    oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/util/CmdLineUtils.java
    oodt/trunk/cli/src/test/org/apache/oodt/cas/cli/TestCmdLineUtility.java
    oodt/trunk/cli/src/test/org/apache/oodt/cas/cli/action/store/spring/TestSpringCmdLineActionStore.java
    oodt/trunk/cli/src/test/org/apache/oodt/cas/cli/option/store/spring/TestSpringCmdLineOptionStore.java
    oodt/trunk/cli/src/test/org/apache/oodt/cas/cli/option/validator/TestAllowedArgsCmdLineOptionValidator.java
    oodt/trunk/cli/src/test/org/apache/oodt/cas/cli/option/validator/TestArgRegExpCmdLineOptionValidator.java
    oodt/trunk/cli/src/test/org/apache/oodt/cas/cli/option/validator/TestClassExistsCmdLineOptionValidator.java
    oodt/trunk/cli/src/test/org/apache/oodt/cas/cli/option/validator/TestFileExistCmdLineOptionValidator.java
    oodt/trunk/cli/src/test/org/apache/oodt/cas/cli/option/validator/TestNoRestrictionsCmdLineOptionValidator.java
    oodt/trunk/cli/src/test/org/apache/oodt/cas/cli/parser/TestStdCmdLineOptionParser.java
    oodt/trunk/cli/src/test/org/apache/oodt/cas/cli/util/TestCmdLineIterable.java
    oodt/trunk/cli/src/test/org/apache/oodt/cas/cli/util/TestCmdLineUtils.java
    oodt/trunk/cli/src/testdata/cmd-line-actions.xml
    oodt/trunk/cli/src/testdata/cmd-line-options.xml

Modified: oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/CmdLineArgs.java
URL: http://svn.apache.org/viewvc/oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/CmdLineArgs.java?rev=1200439&r1=1200438&r2=1200439&view=diff
==============================================================================
--- oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/CmdLineArgs.java (original)
+++ oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/CmdLineArgs.java Thu Nov 10 17:27:28 2011
@@ -39,7 +39,7 @@ import org.apache.oodt.cas.cli.option.Pr
 /**
  * A convenience class for {@link CmdLineUtility} for helping use already parsed
  * Command-Line arguments.
- * 
+ *
  * @author bfoster (Brian Foster)
  */
 public class CmdLineArgs {

Modified: oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/CmdLineUtility.java
URL: http://svn.apache.org/viewvc/oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/CmdLineUtility.java?rev=1200439&r1=1200438&r2=1200439&view=diff
==============================================================================
--- oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/CmdLineUtility.java (original)
+++ oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/CmdLineUtility.java Thu Nov 10 17:27:28 2011
@@ -17,13 +17,15 @@
 package org.apache.oodt.cas.cli;
 
 //OODT static imports
+import static org.apache.oodt.cas.cli.util.CmdLineUtils.determineFailedValidation;
 import static org.apache.oodt.cas.cli.util.CmdLineUtils.determineRequired;
-import static org.apache.oodt.cas.cli.util.CmdLineUtils.findActionOption;
+import static org.apache.oodt.cas.cli.util.CmdLineUtils.findFirstActionOption;
 import static org.apache.oodt.cas.cli.util.CmdLineUtils.findHelpOption;
+import static org.apache.oodt.cas.cli.util.CmdLineUtils.findPrintSupportedActionsOption;
 
 //JDK imports
-import java.io.IOException;
 import java.util.HashSet;
+import java.util.List;
 import java.util.Set;
 
 //Apache imports
@@ -34,15 +36,12 @@ import org.apache.oodt.cas.cli.action.st
 import org.apache.oodt.cas.cli.action.store.spring.SpringCmdLineActionStoreFactory;
 import org.apache.oodt.cas.cli.contruct.CmdLineConstructor;
 import org.apache.oodt.cas.cli.contruct.StdCmdLineConstructor;
+import org.apache.oodt.cas.cli.exception.CmdLineActionException;
+import org.apache.oodt.cas.cli.exception.CmdLineActionExecutionException;
+import org.apache.oodt.cas.cli.exception.CmdLineActionStoreException;
 import org.apache.oodt.cas.cli.exception.CmdLineConstructionException;
-import org.apache.oodt.cas.cli.help.presenter.CmdLineOptionHelpPresenter;
-import org.apache.oodt.cas.cli.help.presenter.StdCmdLineOptionHelpPresenter;
-import org.apache.oodt.cas.cli.help.printer.CmdLineActionHelpPrinter;
-import org.apache.oodt.cas.cli.help.printer.CmdLineActionsHelpPrinter;
-import org.apache.oodt.cas.cli.help.printer.CmdLineOptionsHelpPrinter;
-import org.apache.oodt.cas.cli.help.printer.StdCmdLineActionHelpPrinter;
-import org.apache.oodt.cas.cli.help.printer.StdCmdLineActionsHelpPrinter;
-import org.apache.oodt.cas.cli.help.printer.StdCmdLineOptionsHelpPrinter;
+import org.apache.oodt.cas.cli.exception.CmdLineOptionStoreException;
+import org.apache.oodt.cas.cli.exception.CmdLineParserException;
 import org.apache.oodt.cas.cli.option.ActionCmdLineOption;
 import org.apache.oodt.cas.cli.option.CmdLineOption;
 import org.apache.oodt.cas.cli.option.CmdLineOptionInstance;
@@ -50,12 +49,20 @@ import org.apache.oodt.cas.cli.option.He
 import org.apache.oodt.cas.cli.option.PrintSupportedActionsCmdLineOption;
 import org.apache.oodt.cas.cli.option.store.CmdLineOptionStore;
 import org.apache.oodt.cas.cli.option.store.spring.SpringCmdLineOptionStoreFactory;
+import org.apache.oodt.cas.cli.option.validator.CmdLineOptionValidator;
 import org.apache.oodt.cas.cli.parser.CmdLineParser;
 import org.apache.oodt.cas.cli.parser.StdCmdLineParser;
+import org.apache.oodt.cas.cli.presenter.CmdLinePresenter;
+import org.apache.oodt.cas.cli.presenter.StdCmdLinePresenter;
+import org.apache.oodt.cas.cli.printer.CmdLinePrinter;
+import org.apache.oodt.cas.cli.printer.StdCmdLinePrinter;
 import org.apache.oodt.cas.cli.util.CmdLineIterable;
 import org.apache.oodt.cas.cli.util.CmdLineUtils;
 import org.apache.oodt.cas.cli.util.ParsedArg;
 
+//Google imports
+import com.google.common.collect.Lists;
+
 /**
  * A highly configurable utility class which supports parsing and handling of
  * command line arguments via its action driven design. After parsing the
@@ -68,24 +75,23 @@ import org.apache.oodt.cas.cli.util.Pars
  */
 public class CmdLineUtility {
 
+   private boolean debugMode;
    private CmdLineParser parser;
    private CmdLineConstructor constructor;
    private CmdLineOptionStore optionStore;
    private CmdLineActionStore actionStore;
-   private CmdLineOptionsHelpPrinter optionHelpPrinter;
-   private CmdLineActionHelpPrinter actionHelpPrinter;
-   private CmdLineActionsHelpPrinter actionsHelpPrinter;
-   private CmdLineOptionHelpPresenter helpPresenter;
+   private CmdLinePrinter printer;
+   private CmdLinePresenter presenter;
 
    public CmdLineUtility() {
       parser = new StdCmdLineParser();
       constructor = new StdCmdLineConstructor();
       optionStore = new SpringCmdLineOptionStoreFactory().createStore();
       actionStore = new SpringCmdLineActionStoreFactory().createStore();
-      optionHelpPrinter = new StdCmdLineOptionsHelpPrinter();
-      actionHelpPrinter = new StdCmdLineActionHelpPrinter();
-      actionsHelpPrinter = new StdCmdLineActionsHelpPrinter();
-      helpPresenter = new StdCmdLineOptionHelpPresenter();
+      printer = new StdCmdLinePrinter();
+      presenter = new StdCmdLinePresenter();
+
+      debugMode = Boolean.getBoolean("org.apache.oodt.cas.cli.debug");
    }
 
    public CmdLineOptionStore getOptionStore() {
@@ -104,58 +110,53 @@ public class CmdLineUtility {
       this.actionStore = actionStore;
    }
 
-   public CmdLineOptionsHelpPrinter getOptionHelpPrinter() {
-      return optionHelpPrinter;
-   }
-
-   public void setOptionHelpPrinter(CmdLineOptionsHelpPrinter optionHelpPrinter) {
-      this.optionHelpPrinter = optionHelpPrinter;
-   }
-
-   public CmdLineActionHelpPrinter getActionHelpPrinter() {
-      return actionHelpPrinter;
+   public CmdLinePrinter getPrinter() {
+      return printer;
    }
 
-   public void setActionHelpPrinter(CmdLineActionHelpPrinter actionHelpPrinter) {
-      this.actionHelpPrinter = actionHelpPrinter;
+   public void setPrinter(CmdLinePrinter printer) {
+      this.printer = printer;
    }
 
-   public CmdLineActionsHelpPrinter getActionsHelpPrinter() {
-      return actionsHelpPrinter;
+   public CmdLinePresenter getPresenter() {
+      return presenter;
    }
 
-   public void setActionsHelpPrinter(
-         CmdLineActionsHelpPrinter actionsHelpPrinter) {
-      this.actionsHelpPrinter = actionsHelpPrinter;
-   }
-
-   public CmdLineOptionHelpPresenter getHelpPresenter() {
-      return helpPresenter;
-   }
-
-   public void setHelpPresenter(CmdLineOptionHelpPresenter helpPresenter) {
-      this.helpPresenter = helpPresenter;
+   public void setPresenter(CmdLinePresenter presenter) {
+      this.presenter = presenter;
    }
 
    public void printOptionHelp(CmdLineArgs cmdLineArgs) {
-      helpPresenter.presentOptionHelp(optionHelpPrinter.printHelp(cmdLineArgs
+      presenter.presentOptionHelp(printer.printOptionsHelp(cmdLineArgs
             .getSupportedOptions()));
    }
 
    public void printActionHelp(CmdLineArgs cmdLineArgs) {
       Validate.notEmpty(cmdLineArgs.getHelpOptionInst().getValues());
 
-      helpPresenter.presentActionHelp(actionHelpPrinter.printHelp(
+      presenter.presentActionHelp(printer.printActionHelp(
             CmdLineUtils.findAction(cmdLineArgs.getHelpOptionInst().getValues()
                   .get(0), cmdLineArgs.getSupportedActions()),
             cmdLineArgs.getSupportedOptions()));
    }
 
    public void printActionsHelp(CmdLineArgs cmdLineArgs) {
-      helpPresenter.presentActionsHelp(actionsHelpPrinter.printHelp(cmdLineArgs
+      presenter.presentActionsHelp(printer.printActionsHelp(cmdLineArgs
             .getSupportedActions()));
    }
 
+   public void printValidationErrors(List<CmdLineOptionValidator.Result> results) {
+      presenter.presentErrorMessage(printer.printOptionValidationErrors(results));
+   }
+
+   public void printMissingRequiredOptionsError(Set<CmdLineOption> missingOptions) {
+      presenter.presentErrorMessage(printer.printRequiredOptionsMissingError(missingOptions));
+   }
+
+   public void printErrorMessage(String errorMessage) {
+      presenter.presentErrorMessage(errorMessage);
+   }
+
    /**
     * Parses given command line arguments, then checks for help and print
     * supported actions options, prints them out if found, otherwise performs
@@ -163,17 +164,18 @@ public class CmdLineUtility {
     * 
     * @param args
     *           The who will be parsed and executed.
-    * @throws IOException
-    *            On error parsing or executing the args.
-    * @throws CmdLineConstructionException 
-    *            On error constructing or executing the args.
     */
-   public void run(String[] args) throws IOException, CmdLineConstructionException {
-      CmdLineArgs cmdLineArgs = parse(args);
-      if (cmdLineArgs.getSpecifiedOptions().isEmpty()) {
-         printOptionHelp(cmdLineArgs);
-      } else if (!handleHelp(cmdLineArgs) && !handlePrintSupportedActions(cmdLineArgs)) {
-         execute(cmdLineArgs);
+   public void run(String[] args) {
+      try {
+         CmdLineArgs cmdLineArgs = parse(args);
+         if (cmdLineArgs.getSpecifiedOptions().isEmpty()) {
+            printOptionHelp(cmdLineArgs);
+         } else if (!handleHelp(cmdLineArgs) && !handlePrintSupportedActions(cmdLineArgs)) {
+            execute(cmdLineArgs);
+         }
+      } catch (Exception e) {
+         if (debugMode) { e.printStackTrace(); }
+         printErrorMessage(e.getMessage());
       }
    }
 
@@ -188,8 +190,11 @@ public class CmdLineUtility {
     *            On error parsing command line arguments.
     * @throws CmdLineConstructionException 
     *            On error constructing command line arguments.
+    * @throws CmdLineOptionStoreException 
     */
-   public CmdLineArgs parse(String[] args) throws IOException, CmdLineConstructionException {
+   public CmdLineArgs parse(String[] args) throws CmdLineParserException,
+         CmdLineActionStoreException, CmdLineConstructionException,
+         CmdLineOptionStoreException {
       Validate.notNull(parser);
       Validate.notNull(optionStore);
 
@@ -197,27 +202,25 @@ public class CmdLineUtility {
       Set<CmdLineOption> validOptions = optionStore.loadSupportedOptions();
 
       // Insure help options is present if required.
-      HelpCmdLineOption helpOption = findHelpOption(validOptions);
-      if (helpOption == null) {
-         validOptions.add(helpOption = new HelpCmdLineOption());
+      if (findHelpOption(validOptions) == null) {
+         validOptions.add(new HelpCmdLineOption());
       }
 
-      // Insure action options is present if required.
-      ActionCmdLineOption actionOption = findActionOption(validOptions);
-      if (actionOption == null) {
-         validOptions.add(actionOption = new ActionCmdLineOption());
+      // Insure action options are present if required.
+      if (findFirstActionOption(validOptions) == null) {
+         validOptions.add(new ActionCmdLineOption());
       }
 
       // Insure print supported actions option is present if required.
-      PrintSupportedActionsCmdLineOption psaOption = CmdLineUtils
-            .findPrintSupportedActionsOption(validOptions);
-      if (psaOption == null) {
-         validOptions.add(psaOption = new PrintSupportedActionsCmdLineOption());
+      if (findPrintSupportedActionsOption(validOptions) == null) {
+         validOptions.add(new PrintSupportedActionsCmdLineOption());
       }
 
       // Parse command line arguments.
       return new CmdLineArgs(actionStore.loadSupportedActions(), validOptions,
-            constructor.construct(new CmdLineIterable<ParsedArg>(parser.parse(args)), validOptions));
+            constructor.construct(
+                  new CmdLineIterable<ParsedArg>(parser.parse(args)),
+                  validOptions));
    }
 
    /**
@@ -263,20 +266,23 @@ public class CmdLineUtility {
     * @param cmdLineArgs
     *           The {@link CmdLineArgs} for which execution processing will be
     *           run.
-    * @throws IOException
-    *            If required options are missing or validation fails.
     */
-   public static void execute(CmdLineArgs cmdLineArgs) throws IOException {
+   public void execute(CmdLineArgs cmdLineArgs)
+         throws CmdLineActionExecutionException, CmdLineActionException {
+      if (cmdLineArgs.getActionOptionInst() == null) {
+         throw new CmdLineActionExecutionException(
+               "Must specify an action option!");
+      }
       Set<CmdLineOption> requiredOptionsNotSet = check(cmdLineArgs);
       if (!requiredOptionsNotSet.isEmpty()) {
-         throw new IOException("Required options are not set: '"
-               + requiredOptionsNotSet + "'");
+         printMissingRequiredOptionsError(requiredOptionsNotSet);
+         return;
       }
 
-      Set<CmdLineOptionInstance> optionsFailedValidation = validate(cmdLineArgs);
-      if (!optionsFailedValidation.isEmpty()) {
-         throw new IOException("Options failed validation: '"
-               + optionsFailedValidation + "'");
+      List<CmdLineOptionValidator.Result> failedValidationResults = determineFailedValidation(validate(cmdLineArgs));
+      if (!failedValidationResults.isEmpty()) {
+         printValidationErrors(failedValidationResults);
+         return;
       }
 
       handle(cmdLineArgs);
@@ -307,24 +313,23 @@ public class CmdLineUtility {
    }
 
    /**
-    * Runs validation on {@link CmdLineArgs} and returns the options which
-    * failed validation.
+    * Runs validation on {@link CmdLineArgs} and returns the validation results.
     * 
     * @param cmdLineArgs
     *           The {@link CmdLineArgs} which will be validated.
-    * @return The {@link CmdLineOptionInstance}s which failed validation.
+    * @return The {@link CmdLineOptionValidator.Result}s generated when running
+    *    {@link CmdLineOptionValidator}s.
     */
-   public static Set<CmdLineOptionInstance> validate(CmdLineArgs cmdLineArgs) {
+   public static List<CmdLineOptionValidator.Result> validate(
+         CmdLineArgs cmdLineArgs) {
       Validate.notNull(cmdLineArgs);
 
-      HashSet<CmdLineOptionInstance> optionsFailed = new HashSet<CmdLineOptionInstance>();
+      List<CmdLineOptionValidator.Result> results = Lists.newArrayList();
       for (CmdLineOptionInstance optionInst : cmdLineArgs
             .getSpecifiedOptions()) {
-         if (!CmdLineUtils.validate(optionInst)) {
-            optionsFailed.add(optionInst);
-         }
+         results.addAll(CmdLineUtils.validate(optionInst));
       }
-      return optionsFailed;
+      return results;
    }
 
    /**

Modified: oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/action/CmdLineAction.java
URL: http://svn.apache.org/viewvc/oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/action/CmdLineAction.java?rev=1200439&r1=1200438&r2=1200439&view=diff
==============================================================================
--- oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/action/CmdLineAction.java (original)
+++ oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/action/CmdLineAction.java Thu Nov 10 17:27:28 2011
@@ -16,6 +16,9 @@
  */
 package org.apache.oodt.cas.cli.action;
 
+//OODT imports
+import org.apache.oodt.cas.cli.exception.CmdLineActionException;
+
 /**
  * Action which is specified and configured via {@link CmdLineOption}s and
  * then executed.
@@ -51,6 +54,6 @@ public abstract class CmdLineAction {
       return description;
    }
 
-   public abstract void execute();
+   public abstract void execute() throws CmdLineActionException;
 
 }

Modified: oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/action/store/CmdLineActionStore.java
URL: http://svn.apache.org/viewvc/oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/action/store/CmdLineActionStore.java?rev=1200439&r1=1200438&r2=1200439&view=diff
==============================================================================
--- oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/action/store/CmdLineActionStore.java (original)
+++ oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/action/store/CmdLineActionStore.java Thu Nov 10 17:27:28 2011
@@ -21,6 +21,7 @@ import java.util.Set;
 
 //OODT imports
 import org.apache.oodt.cas.cli.action.CmdLineAction;
+import org.apache.oodt.cas.cli.exception.CmdLineActionStoreException;
 
 /**
  * Storage for loading supported {@link CmdLineAction}s.
@@ -29,6 +30,6 @@ import org.apache.oodt.cas.cli.action.Cm
  */
 public interface CmdLineActionStore {
 
-   public Set<CmdLineAction> loadSupportedActions();
-
+   public Set<CmdLineAction> loadSupportedActions()
+         throws CmdLineActionStoreException;
 }

Modified: oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/action/store/CmdLineActionStoreFactory.java
URL: http://svn.apache.org/viewvc/oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/action/store/CmdLineActionStoreFactory.java?rev=1200439&r1=1200438&r2=1200439&view=diff
==============================================================================
--- oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/action/store/CmdLineActionStoreFactory.java (original)
+++ oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/action/store/CmdLineActionStoreFactory.java Thu Nov 10 17:27:28 2011
@@ -24,5 +24,4 @@ package org.apache.oodt.cas.cli.action.s
 public interface CmdLineActionStoreFactory {
 
    public CmdLineActionStore createStore();
-
 }

Modified: oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/action/store/spring/SpringCmdLineActionStore.java
URL: http://svn.apache.org/viewvc/oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/action/store/spring/SpringCmdLineActionStore.java?rev=1200439&r1=1200438&r2=1200439&view=diff
==============================================================================
--- oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/action/store/spring/SpringCmdLineActionStore.java (original)
+++ oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/action/store/spring/SpringCmdLineActionStore.java Thu Nov 10 17:27:28 2011
@@ -25,6 +25,7 @@ import java.util.Map.Entry;
 //OODT imports
 import org.apache.oodt.cas.cli.action.CmdLineAction;
 import org.apache.oodt.cas.cli.action.store.CmdLineActionStore;
+import org.apache.oodt.cas.cli.exception.CmdLineActionStoreException;
 import org.springframework.context.ApplicationContext;
 import org.springframework.context.support.FileSystemXmlApplicationContext;
 
@@ -43,7 +44,9 @@ public class SpringCmdLineActionStore im
       handleSettingNameForCmdLineActions();
    }
 
-   public Set<CmdLineAction> loadSupportedActions() {
+   @Override
+   public Set<CmdLineAction> loadSupportedActions()
+         throws CmdLineActionStoreException {
       @SuppressWarnings("unchecked")
       Map<String, CmdLineAction> actionsMap = appContext
             .getBeansOfType(CmdLineAction.class);

Modified: oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/action/store/spring/SpringCmdLineActionStoreFactory.java
URL: http://svn.apache.org/viewvc/oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/action/store/spring/SpringCmdLineActionStoreFactory.java?rev=1200439&r1=1200438&r2=1200439&view=diff
==============================================================================
--- oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/action/store/spring/SpringCmdLineActionStoreFactory.java (original)
+++ oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/action/store/spring/SpringCmdLineActionStoreFactory.java Thu Nov 10 17:27:28 2011
@@ -17,6 +17,7 @@
 package org.apache.oodt.cas.cli.action.store.spring;
 
 //OODT imports
+import org.apache.commons.lang.Validate;
 import org.apache.oodt.cas.cli.action.store.CmdLineActionStoreFactory;
 
 /**
@@ -35,10 +36,8 @@ public class SpringCmdLineActionStoreFac
    }
 
    public SpringCmdLineActionStore createStore() {
-      if (config != null) {
-         return new SpringCmdLineActionStore(config);
-      } else {
-         return null;
-      }
+      Validate.notNull(config);
+
+      return new SpringCmdLineActionStore(config);
    }
 }

Modified: oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/contruct/StdCmdLineConstructor.java
URL: http://svn.apache.org/viewvc/oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/contruct/StdCmdLineConstructor.java?rev=1200439&r1=1200438&r2=1200439&view=diff
==============================================================================
--- oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/contruct/StdCmdLineConstructor.java (original)
+++ oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/contruct/StdCmdLineConstructor.java Thu Nov 10 17:27:28 2011
@@ -33,6 +33,7 @@ import java.util.Stack;
 import org.apache.commons.lang.Validate;
 
 //OODT imports
+import org.apache.oodt.cas.cli.exception.CmdLineConstructionException;
 import org.apache.oodt.cas.cli.option.CmdLineOption;
 import org.apache.oodt.cas.cli.option.CmdLineOptionInstance;
 import org.apache.oodt.cas.cli.option.GroupCmdLineOption;
@@ -52,7 +53,7 @@ import com.google.common.annotations.Vis
 public class StdCmdLineConstructor implements CmdLineConstructor {
 
    public Set<CmdLineOptionInstance> construct(CmdLineIterable<ParsedArg> parsedArgs,
-         Set<CmdLineOption> validOptions) {
+         Set<CmdLineOption> validOptions) throws CmdLineConstructionException {
       HashSet<CmdLineOptionInstance> optionInstances = new HashSet<CmdLineOptionInstance>();
 
       Stack<CmdLineOptionInstance> groupOptions = new Stack<CmdLineOptionInstance>();
@@ -64,7 +65,7 @@ public class StdCmdLineConstructor imple
             CmdLineOption option = getOptionByName(arg.getName(),
                   validOptions);
             if (option == null) {
-               throw new RuntimeException("Invalid option: '" + arg.getName() + "'");
+               throw new CmdLineConstructionException("Invalid option: '" + arg.getName() + "'");
             }
 
             // read found option
@@ -75,20 +76,20 @@ public class StdCmdLineConstructor imple
 
                CmdLineOptionInstance currentGroup = groupOptions.peek();
 
-               // Check if option is a subOption for current group.
+               // Check if option is NOT a subOption for current group.
                if (!isSubOption(currentGroup.getOption(), option)) {
 
                   // Check if current group was expecting more subOptions.
                   Set<CmdLineOption> requiredSubOptions = verifyGroupHasRequiredSubOptions(currentGroup);
                   if (!requiredSubOptions.isEmpty()) {
-                     throw new RuntimeException(
+                     throw new CmdLineConstructionException(
                            "Missing the following required subOptions for '"
                                  + currentGroup.getOption()
                                  + "': "
                                  + sortOptionsByRequiredStatus(requiredSubOptions));
 
                   } else if (currentGroup.getSubOptions().isEmpty()) {
-                     throw new RuntimeException(
+                     throw new CmdLineConstructionException(
                            "Must specify a subOption for group option '"
                                  + currentGroup.getOption() + "'");
 
@@ -97,6 +98,7 @@ public class StdCmdLineConstructor imple
                      // pop group and add to list of specified options.
                      optionInstances.add(groupOptions.pop());
                   }
+               // It is a sub-option...
                } else {
 
                   // Add option to current group subOptions.
@@ -110,9 +112,14 @@ public class StdCmdLineConstructor imple
 
                // Push group as current group.
                groupOptions.push(specifiedOption);
-
+               
+               if (!parsedArgs.hasNext()) {
+                  throw new CmdLineConstructionException(
+                        "Must specify a subOption for group option '"
+                              + specifiedOption.getOption() + "'");
+               }
             } else if (option.isSubOption()) {
-               throw new RuntimeException("Option '" + option
+               throw new CmdLineConstructionException("Option '" + option
                      + "' is a subOption, but was used at top level Option");
 
             } else {
@@ -121,14 +128,14 @@ public class StdCmdLineConstructor imple
                optionInstances.add(specifiedOption);
             }
          } else {
-            throw new RuntimeException("Invalid argument: '" + arg + "'");
+            throw new CmdLineConstructionException("Invalid argument: '" + arg + "'");
          }
       }
       while (!groupOptions.isEmpty()) {
          CmdLineOptionInstance currentGroup = groupOptions.pop();
          Set<CmdLineOption> requiredSubOptions = verifyGroupHasRequiredSubOptions(currentGroup);
          if (!requiredSubOptions.isEmpty()) {
-            throw new RuntimeException(
+            throw new CmdLineConstructionException(
                   "Missing the following required subOptions for '"
                         + currentGroup.getOption() + "': "
                         + sortOptionsByRequiredStatus(requiredSubOptions));
@@ -142,7 +149,7 @@ public class StdCmdLineConstructor imple
 
    @VisibleForTesting
    /* package */static CmdLineOptionInstance getOption(CmdLineIterable<ParsedArg> args,
-         CmdLineOption option) {
+         CmdLineOption option) throws CmdLineConstructionException {
       CmdLineOptionInstance specifiedOption = new CmdLineOptionInstance();
       specifiedOption.setOption(option);
       List<String> values = getValues(args);
@@ -152,10 +159,10 @@ public class StdCmdLineConstructor imple
          if (!values.isEmpty()) {
             specifiedOption.setValues(values);
          } else if (!option.hasStaticArgs()) {
-            throw new RuntimeException("Option " + option + " requires args");
+            throw new CmdLineConstructionException("Option " + option + " requires args");
          }
       } else if (!option.hasArgs() && !values.isEmpty()) {
-         throw new RuntimeException("Option " + option + " does not support args");
+         throw new CmdLineConstructionException("Option " + option + " does not support args");
       }
       return specifiedOption;
    }
@@ -185,11 +192,12 @@ public class StdCmdLineConstructor imple
    @VisibleForTesting
    /* package */static List<String> getValues(CmdLineIterable<ParsedArg> args) {
       List<String> values = new ArrayList<String>();
-      ParsedArg nextValue = args.getCurrentArg();
+      ParsedArg nextValue = args.incrementAndGet();
       while (nextValue != null && nextValue.getType().equals(ParsedArg.Type.VALUE)) {
          values.add(nextValue.getName());
          nextValue = args.incrementAndGet();
       }
+      args.descrementIndex();
       return values;
    }
 }

Added: oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/exception/CmdLineActionException.java
URL: http://svn.apache.org/viewvc/oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/exception/CmdLineActionException.java?rev=1200439&view=auto
==============================================================================
--- oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/exception/CmdLineActionException.java (added)
+++ oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/exception/CmdLineActionException.java Thu Nov 10 17:27:28 2011
@@ -0,0 +1,35 @@
+/*
+ * 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.oodt.cas.cli.exception;
+
+/**
+ * An {@link Exception} thrown when failure to execute a {@link CmdLineAction}.
+ *
+ * @author bfoster (Brian Foster)
+ */
+public class CmdLineActionException extends Exception {
+
+   private static final long serialVersionUID = 6416302963047726032L;
+
+   public CmdLineActionException(String msg) {
+      super(msg);
+   }
+
+   public CmdLineActionException(String msg, Throwable t) {
+      super(msg, t);
+   }
+}

Propchange: oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/exception/CmdLineActionException.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/exception/CmdLineActionExecutionException.java
URL: http://svn.apache.org/viewvc/oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/exception/CmdLineActionExecutionException.java?rev=1200439&view=auto
==============================================================================
--- oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/exception/CmdLineActionExecutionException.java (added)
+++ oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/exception/CmdLineActionExecutionException.java Thu Nov 10 17:27:28 2011
@@ -0,0 +1,35 @@
+/*
+ * 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.oodt.cas.cli.exception;
+
+/**
+ * An {@link Exception} thrown when failure to execute a {@link CmdLineAction}.
+ *
+ * @author bfoster (Brian Foster)
+ */
+public class CmdLineActionExecutionException extends Exception {
+
+   private static final long serialVersionUID = 4784139793086538249L;
+
+   public CmdLineActionExecutionException(String msg) {
+      super(msg);
+   }
+
+   public CmdLineActionExecutionException(String msg, Throwable t) {
+      super(msg, t);
+   }
+}

Propchange: oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/exception/CmdLineActionExecutionException.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/exception/CmdLineActionStoreException.java
URL: http://svn.apache.org/viewvc/oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/exception/CmdLineActionStoreException.java?rev=1200439&view=auto
==============================================================================
--- oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/exception/CmdLineActionStoreException.java (added)
+++ oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/exception/CmdLineActionStoreException.java Thu Nov 10 17:27:28 2011
@@ -0,0 +1,35 @@
+/*
+ * 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.oodt.cas.cli.exception;
+
+/**
+ * An {@link Exception} thrown by {@link CmdLineActionStore}.
+ *
+ * @author bfoster (Brian Foster)
+ */
+public class CmdLineActionStoreException extends Exception {
+
+   private static final long serialVersionUID = 4303378887098186113L;
+
+   public CmdLineActionStoreException(String msg) {
+      super(msg);
+   }
+
+   public CmdLineActionStoreException(String msg, Throwable t) {
+      super(msg, t);
+   }
+}

Propchange: oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/exception/CmdLineActionStoreException.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/exception/CmdLineOptionStoreException.java
URL: http://svn.apache.org/viewvc/oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/exception/CmdLineOptionStoreException.java?rev=1200439&view=auto
==============================================================================
--- oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/exception/CmdLineOptionStoreException.java (added)
+++ oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/exception/CmdLineOptionStoreException.java Thu Nov 10 17:27:28 2011
@@ -0,0 +1,35 @@
+/*
+ * 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.oodt.cas.cli.exception;
+
+/**
+ * An {@link Exception} thrown by {@link CmdLineOptionStore}.
+ *
+ * @author bfoster (Brian Foster)
+ */
+public class CmdLineOptionStoreException extends Exception {
+
+   private static final long serialVersionUID = -5223714380324479058L;
+
+   public CmdLineOptionStoreException(String msg) {
+      super(msg);
+   }
+
+   public CmdLineOptionStoreException(String msg, Throwable t) {
+      super(msg, t);
+   }
+}

Propchange: oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/exception/CmdLineOptionStoreException.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/exception/CmdLineParserException.java
URL: http://svn.apache.org/viewvc/oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/exception/CmdLineParserException.java?rev=1200439&view=auto
==============================================================================
--- oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/exception/CmdLineParserException.java (added)
+++ oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/exception/CmdLineParserException.java Thu Nov 10 17:27:28 2011
@@ -0,0 +1,35 @@
+/*
+ * 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.oodt.cas.cli.exception;
+
+/**
+ * A {@link Exception} throw when there is an error parsing command line args.
+ *
+ * @author bfoster (Brian Foster)
+ */
+public class CmdLineParserException extends Exception {
+
+   private static final long serialVersionUID = 926637321837303042L;
+
+   public CmdLineParserException(String msg) {
+      super(msg);
+   }
+
+   public CmdLineParserException(String msg, Throwable t) {
+      super(msg, t);
+   }
+}

Propchange: oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/exception/CmdLineParserException.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/exception/CmdLineUtilityException.java
URL: http://svn.apache.org/viewvc/oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/exception/CmdLineUtilityException.java?rev=1200439&view=auto
==============================================================================
--- oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/exception/CmdLineUtilityException.java (added)
+++ oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/exception/CmdLineUtilityException.java Thu Nov 10 17:27:28 2011
@@ -0,0 +1,35 @@
+/*
+ * 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.oodt.cas.cli.exception;
+
+/**
+ * An {@link Exception} thrown by {@link CmdLineUtility}.
+ *
+ * @author bfoster (Brian Foster)
+ */
+public class CmdLineUtilityException extends Exception {
+
+   private static final long serialVersionUID = 2977147381764985598L;
+
+   public CmdLineUtilityException(String msg) {
+      super(msg);
+   }
+
+   public CmdLineUtilityException(String msg, Throwable t) {
+      super(msg, t);
+   }
+}

Propchange: oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/exception/CmdLineUtilityException.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/store/CmdLineOptionStore.java
URL: http://svn.apache.org/viewvc/oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/store/CmdLineOptionStore.java?rev=1200439&r1=1200438&r2=1200439&view=diff
==============================================================================
--- oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/store/CmdLineOptionStore.java (original)
+++ oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/store/CmdLineOptionStore.java Thu Nov 10 17:27:28 2011
@@ -20,6 +20,7 @@ package org.apache.oodt.cas.cli.option.s
 import java.util.Set;
 
 //OODT imports
+import org.apache.oodt.cas.cli.exception.CmdLineOptionStoreException;
 import org.apache.oodt.cas.cli.option.CmdLineOption;
 
 /**
@@ -29,6 +30,7 @@ import org.apache.oodt.cas.cli.option.Cm
  */
 public interface CmdLineOptionStore {
 
-   public Set<CmdLineOption> loadSupportedOptions();
+   public Set<CmdLineOption> loadSupportedOptions()
+      throws CmdLineOptionStoreException;
 
 }

Modified: oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/store/spring/SpringCmdLineOptionStore.java
URL: http://svn.apache.org/viewvc/oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/store/spring/SpringCmdLineOptionStore.java?rev=1200439&r1=1200438&r2=1200439&view=diff
==============================================================================
--- oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/store/spring/SpringCmdLineOptionStore.java (original)
+++ oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/store/spring/SpringCmdLineOptionStore.java Thu Nov 10 17:27:28 2011
@@ -21,6 +21,7 @@ import java.util.Map;
 import java.util.Set;
 
 //OODT imports
+import org.apache.oodt.cas.cli.exception.CmdLineOptionStoreException;
 import org.apache.oodt.cas.cli.option.CmdLineOption;
 import org.apache.oodt.cas.cli.option.store.CmdLineOptionStore;
 
@@ -28,6 +29,7 @@ import org.apache.oodt.cas.cli.option.st
 import org.springframework.context.ApplicationContext;
 import org.springframework.context.support.FileSystemXmlApplicationContext;
 
+//Google imports
 import com.google.common.collect.Sets;
 
 /**
@@ -43,7 +45,9 @@ public class SpringCmdLineOptionStore im
       appContext = new FileSystemXmlApplicationContext(springConfig);
    }
 
-   public Set<CmdLineOption> loadSupportedOptions() {
+   @Override
+   public Set<CmdLineOption> loadSupportedOptions()
+         throws CmdLineOptionStoreException {
       @SuppressWarnings("unchecked")
       Map<String, CmdLineOption> optionsMap = appContext
             .getBeansOfType(CmdLineOption.class);

Modified: oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/store/spring/SpringCmdLineOptionStoreFactory.java
URL: http://svn.apache.org/viewvc/oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/store/spring/SpringCmdLineOptionStoreFactory.java?rev=1200439&r1=1200438&r2=1200439&view=diff
==============================================================================
--- oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/store/spring/SpringCmdLineOptionStoreFactory.java (original)
+++ oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/store/spring/SpringCmdLineOptionStoreFactory.java Thu Nov 10 17:27:28 2011
@@ -17,6 +17,7 @@
 package org.apache.oodt.cas.cli.option.store.spring;
 
 //OODT imports
+import org.apache.commons.lang.Validate;
 import org.apache.oodt.cas.cli.option.store.CmdLineOptionStoreFactory;
 
 /**
@@ -34,12 +35,11 @@ public class SpringCmdLineOptionStoreFac
             "org.apache.oodt.cas.cli.option.spring.config", null);
    }
 
+   @Override
    public SpringCmdLineOptionStore createStore() {
-      if (config != null) {
-         return new SpringCmdLineOptionStore(config);
-      } else {
-         return null;
-      }
+      Validate.notNull(config);
+
+      return new SpringCmdLineOptionStore(config);
    }
 
    public void setConfig(String config) {

Modified: oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/validator/AllowedArgsCmdLineOptionValidator.java
URL: http://svn.apache.org/viewvc/oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/validator/AllowedArgsCmdLineOptionValidator.java?rev=1200439&r1=1200438&r2=1200439&view=diff
==============================================================================
--- oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/validator/AllowedArgsCmdLineOptionValidator.java (original)
+++ oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/validator/AllowedArgsCmdLineOptionValidator.java Thu Nov 10 17:27:28 2011
@@ -23,6 +23,7 @@ import java.util.List;
 //OODT imports
 import org.apache.commons.lang.Validate;
 import org.apache.oodt.cas.cli.option.CmdLineOptionInstance;
+import org.apache.oodt.cas.cli.option.validator.CmdLineOptionValidator.Result.Grade;
 
 /**
  * A {@link CmdLineOptionValidator} which check args against a supplied list of
@@ -39,18 +40,19 @@ public class AllowedArgsCmdLineOptionVal
       this.allowedArgs = new LinkedList<String>();
    }
 
-   public boolean validate(CmdLineOptionInstance optionInst) {
+   @Override
+   public Result validate(CmdLineOptionInstance optionInst) {
       Validate.notNull(optionInst);
 
       for (String value : optionInst.getValues()) {
          if (!allowedArgs.contains(value)) {
-            LOG.severe("Option value " + value + " is not allowed for option "
+            return new Result(Grade.FAIL, "Option value " + value
+                  + " is not allowed for option "
                   + optionInst.getOption().getLongOption()
                   + " - Allowed values = " + this.getAllowedArgs());
-            return false;
          }
       }
-      return true;
+      return new Result(Grade.PASS, "Success");
    }
 
    public List<String> getAllowedArgs() {

Modified: oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/validator/ArgRegExpCmdLineOptionValidator.java
URL: http://svn.apache.org/viewvc/oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/validator/ArgRegExpCmdLineOptionValidator.java?rev=1200439&r1=1200438&r2=1200439&view=diff
==============================================================================
--- oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/validator/ArgRegExpCmdLineOptionValidator.java (original)
+++ oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/validator/ArgRegExpCmdLineOptionValidator.java Thu Nov 10 17:27:28 2011
@@ -22,6 +22,7 @@ import java.util.regex.Pattern;
 //OODT imports
 import org.apache.commons.lang.Validate;
 import org.apache.oodt.cas.cli.option.CmdLineOptionInstance;
+import org.apache.oodt.cas.cli.option.validator.CmdLineOptionValidator.Result.Grade;
 
 /**
  * Performs validation on option instances via allowed args which are regular
@@ -33,7 +34,7 @@ public class ArgRegExpCmdLineOptionValid
       AllowedArgsCmdLineOptionValidator {
 
    @Override
-   public boolean validate(CmdLineOptionInstance optionInst) {
+   public Result validate(CmdLineOptionInstance optionInst) {
       Validate.notNull(optionInst);
 
       TOP: for (String value : optionInst.getValues()) {
@@ -42,11 +43,11 @@ public class ArgRegExpCmdLineOptionValid
                continue TOP;
             }
          }
-         LOG.severe("Option1 value " + value + " is not allowed for option "
+         return new Result(Grade.FAIL, "Option1 value " + value
+               + " is not allowed for option "
                + optionInst.getOption().getLongOption()
                + " - Allowed values = " + getAllowedArgs());
-         return false;
       }
-      return true;
+      return new Result(Grade.PASS, "Success");
    }
 }

Modified: oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/validator/ClassExistsCmdLineOptionValidator.java
URL: http://svn.apache.org/viewvc/oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/validator/ClassExistsCmdLineOptionValidator.java?rev=1200439&r1=1200438&r2=1200439&view=diff
==============================================================================
--- oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/validator/ClassExistsCmdLineOptionValidator.java (original)
+++ oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/validator/ClassExistsCmdLineOptionValidator.java Thu Nov 10 17:27:28 2011
@@ -19,6 +19,7 @@ package org.apache.oodt.cas.cli.option.v
 //OODT imports
 import org.apache.commons.lang.Validate;
 import org.apache.oodt.cas.cli.option.CmdLineOptionInstance;
+import org.apache.oodt.cas.cli.option.validator.CmdLineOptionValidator.Result.Grade;
 
 /**
  * Validates arguments which are checked to see if they are valid classpaths.
@@ -28,19 +29,19 @@ import org.apache.oodt.cas.cli.option.Cm
 public class ClassExistsCmdLineOptionValidator implements
       CmdLineOptionValidator {
 
-   public boolean validate(CmdLineOptionInstance optionInst) {
+   @Override
+   public Result validate(CmdLineOptionInstance optionInst) {
       Validate.notNull(optionInst);
 
       for (String value : optionInst.getValues()) {
          try {
             Class.forName(value);
          } catch (Exception e) {
-            LOG.severe("Option value " + value + " for option "
-                  + optionInst.getOption().getLongOption()
+            return new Result(Grade.FAIL, "Option value " + value
+                  + " for option " + optionInst.getOption().getLongOption()
                   + " is not a valid class");
-            return false;
          }
       }
-      return true;
+      return new Result(Grade.PASS, "Success");
    }
 }

Modified: oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/validator/CmdLineOptionValidator.java
URL: http://svn.apache.org/viewvc/oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/validator/CmdLineOptionValidator.java?rev=1200439&r1=1200438&r2=1200439&view=diff
==============================================================================
--- oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/validator/CmdLineOptionValidator.java (original)
+++ oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/validator/CmdLineOptionValidator.java Thu Nov 10 17:27:28 2011
@@ -16,9 +16,6 @@
  */
 package org.apache.oodt.cas.cli.option.validator;
 
-//JDK imports
-import java.util.logging.Logger;
-
 //OODT imports
 import org.apache.oodt.cas.cli.option.CmdLineOptionInstance;
 
@@ -29,8 +26,31 @@ import org.apache.oodt.cas.cli.option.Cm
  */
 public interface CmdLineOptionValidator {
 
-   static Logger LOG = Logger.getLogger(CmdLineOptionValidator.class.getName());
-
-   public boolean validate(CmdLineOptionInstance optionInst);
-
+   public class Result {
+      public enum Grade {
+         PASS, FAIL;
+      }
+
+      private String message;
+      private Grade grade;
+
+      public Result(Grade grade, String message) {
+         this.message = message;
+         this.grade = grade;
+      }
+
+      public String getMessage() {
+         return message;
+      }
+
+      public Grade getGrade() {
+         return grade;
+      }
+   }
+
+   /**
+    * Throws {@link CmdLineValidationException} if validation fails, otherwise
+    * method just returns.
+    */
+   public Result validate(CmdLineOptionInstance optionInst);
 }

Modified: oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/validator/FileExistCmdLineOptionValidator.java
URL: http://svn.apache.org/viewvc/oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/validator/FileExistCmdLineOptionValidator.java?rev=1200439&r1=1200438&r2=1200439&view=diff
==============================================================================
--- oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/validator/FileExistCmdLineOptionValidator.java (original)
+++ oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/validator/FileExistCmdLineOptionValidator.java Thu Nov 10 17:27:28 2011
@@ -22,6 +22,7 @@ import java.io.File;
 //OODT imports
 import org.apache.commons.lang.Validate;
 import org.apache.oodt.cas.cli.option.CmdLineOptionInstance;
+import org.apache.oodt.cas.cli.option.validator.CmdLineOptionValidator.Result.Grade;
 
 /**
  * A {@link CmdLineOptionValidator} which checks args if they are existing
@@ -31,17 +32,17 @@ import org.apache.oodt.cas.cli.option.Cm
  */
 public class FileExistCmdLineOptionValidator implements CmdLineOptionValidator {
 
-   public boolean validate(CmdLineOptionInstance optionInst) {
+   @Override
+   public Result validate(CmdLineOptionInstance optionInst) {
       Validate.notNull(optionInst);
 
       for (String value : optionInst.getValues()) {
          if (!new File(value).exists()) {
-            LOG.severe("Option value " + value + " for option "
-                  + optionInst.getOption().getLongOption()
+            return new Result(Grade.FAIL, "Option value " + value
+                  + " for option " + optionInst.getOption().getLongOption()
                   + " is not an existing file");
-            return false;
          }
       }
-      return true;
+      return new Result(Grade.PASS, "Success");
    }
 }

Modified: oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/validator/NoRestrictionsCmdLineOptionValidator.java
URL: http://svn.apache.org/viewvc/oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/validator/NoRestrictionsCmdLineOptionValidator.java?rev=1200439&r1=1200438&r2=1200439&view=diff
==============================================================================
--- oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/validator/NoRestrictionsCmdLineOptionValidator.java (original)
+++ oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/validator/NoRestrictionsCmdLineOptionValidator.java Thu Nov 10 17:27:28 2011
@@ -18,6 +18,7 @@ package org.apache.oodt.cas.cli.option.v
 
 //OODT imports
 import org.apache.oodt.cas.cli.option.CmdLineOptionInstance;
+import org.apache.oodt.cas.cli.option.validator.CmdLineOptionValidator.Result.Grade;
 
 /**
  * A {@link CmdLineOptionValidator} which always returns true.
@@ -27,7 +28,7 @@ import org.apache.oodt.cas.cli.option.Cm
 public class NoRestrictionsCmdLineOptionValidator implements
       CmdLineOptionValidator {
 
-   public boolean validate(CmdLineOptionInstance optionInst) {
-      return true;
+   public Result validate(CmdLineOptionInstance optionInst) {
+      return new Result(Grade.PASS, "Success");
    }
 }

Modified: oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/parser/CmdLineParser.java
URL: http://svn.apache.org/viewvc/oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/parser/CmdLineParser.java?rev=1200439&r1=1200438&r2=1200439&view=diff
==============================================================================
--- oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/parser/CmdLineParser.java (original)
+++ oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/parser/CmdLineParser.java Thu Nov 10 17:27:28 2011
@@ -17,10 +17,10 @@
 package org.apache.oodt.cas.cli.parser;
 
 //JDK imports
-import java.io.IOException;
 import java.util.List;
 
 //OODT imports
+import org.apache.oodt.cas.cli.exception.CmdLineParserException;
 import org.apache.oodt.cas.cli.util.ParsedArg;
 
 /**
@@ -31,6 +31,6 @@ import org.apache.oodt.cas.cli.util.Pars
  */
 public interface CmdLineParser {
 
-   public List<ParsedArg> parse(String[] args) throws IOException;
+   public List<ParsedArg> parse(String[] args) throws CmdLineParserException;
 
 }

Modified: oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/parser/StdCmdLineParser.java
URL: http://svn.apache.org/viewvc/oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/parser/StdCmdLineParser.java?rev=1200439&r1=1200438&r2=1200439&view=diff
==============================================================================
--- oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/parser/StdCmdLineParser.java (original)
+++ oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/parser/StdCmdLineParser.java Thu Nov 10 17:27:28 2011
@@ -33,10 +33,10 @@
 package org.apache.oodt.cas.cli.parser;
 
 //JDK imports
-import java.io.IOException;
 import java.util.List;
 
 //OODT imports
+import org.apache.oodt.cas.cli.exception.CmdLineParserException;
 import org.apache.oodt.cas.cli.util.ParsedArg;
 
 //Google imports
@@ -51,7 +51,7 @@ import com.google.common.collect.Lists;
  */
 public class StdCmdLineParser implements CmdLineParser {
 
-   public List<ParsedArg> parse(String[] args) throws IOException {
+   public List<ParsedArg> parse(String[] args) throws CmdLineParserException {
       List<ParsedArg> parsedArgs = Lists.newArrayList();
 
       for (String arg : args) {

Added: oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/presenter/CmdLinePresenter.java
URL: http://svn.apache.org/viewvc/oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/presenter/CmdLinePresenter.java?rev=1200439&view=auto
==============================================================================
--- oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/presenter/CmdLinePresenter.java (added)
+++ oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/presenter/CmdLinePresenter.java Thu Nov 10 17:27:28 2011
@@ -0,0 +1,34 @@
+/*
+ * 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.oodt.cas.cli.presenter;
+
+/**
+ * Presenter to displaying help messages generated by help printers.
+ * 
+ * @author bfoster (Brian Foster)
+ */
+public interface CmdLinePresenter {
+
+   public void presentOptionHelp(String optionHelpMessage);
+
+   public void presentActionHelp(String actionHelpMessage);
+
+   public void presentActionsHelp(String actionsHelpMessage);
+
+   public void presentErrorMessage(String errorMessage);
+
+}

Propchange: oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/presenter/CmdLinePresenter.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/presenter/StdCmdLinePresenter.java
URL: http://svn.apache.org/viewvc/oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/presenter/StdCmdLinePresenter.java?rev=1200439&view=auto
==============================================================================
--- oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/presenter/StdCmdLinePresenter.java (added)
+++ oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/presenter/StdCmdLinePresenter.java Thu Nov 10 17:27:28 2011
@@ -0,0 +1,65 @@
+/*
+ * 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.oodt.cas.cli.presenter;
+
+//JDK imports
+import java.io.OutputStream;
+import java.io.PrintStream;
+
+//Apache imports
+import org.apache.commons.lang.Validate;
+
+/**
+ * Standard help presenter which sends help messages to {@link System.out}.
+ * 
+ * @author bfoster (Brian Foster)
+ */
+public class StdCmdLinePresenter implements
+      CmdLinePresenter {
+
+   private PrintStream ps;
+
+   public StdCmdLinePresenter() {
+      this(System.out);
+   }
+
+   public StdCmdLinePresenter(OutputStream os) {
+      Validate.notNull(os);
+
+      ps = new PrintStream(os);
+   }
+
+   @Override
+   public void presentOptionHelp(String optionHelpMessage) {
+      ps.println(optionHelpMessage);
+   }
+
+   @Override
+   public void presentActionHelp(String actionHelpMessage) {
+      ps.println(actionHelpMessage);
+   }
+
+   @Override
+   public void presentActionsHelp(String actionsHelpMessage) {
+      ps.println(actionsHelpMessage);
+   }
+
+   @Override
+   public void presentErrorMessage(String errorMessage) {
+      ps.println(errorMessage);
+   }
+}

Propchange: oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/presenter/StdCmdLinePresenter.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/printer/CmdLinePrinter.java
URL: http://svn.apache.org/viewvc/oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/printer/CmdLinePrinter.java?rev=1200439&view=auto
==============================================================================
--- oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/printer/CmdLinePrinter.java (added)
+++ oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/printer/CmdLinePrinter.java Thu Nov 10 17:27:28 2011
@@ -0,0 +1,86 @@
+/*
+ * 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.oodt.cas.cli.printer;
+
+//JDK imports
+import java.util.List;
+import java.util.Set;
+
+//OODT imports
+import org.apache.oodt.cas.cli.action.CmdLineAction;
+import org.apache.oodt.cas.cli.option.CmdLineOption;
+import org.apache.oodt.cas.cli.option.validator.CmdLineOptionValidator.Result;
+
+/**
+ * Printer which is responsible for generating a {@link String} representation
+ * of help, validation errors, and missing required options errors.
+ *
+ * @author bfoster (Brian Foster)
+ */
+public interface CmdLinePrinter {
+
+   /**
+    * Should generate help message for action specified by
+    * {@link #CmdLineArgs.getSpecifiedAction()}.
+    * 
+    * @param action
+    *           {@link CmdLineAction} for which help will be generate
+    * @param options
+    *           Supported {@link CmdLineOption}s
+    * @return Help message for specified action
+    */
+   public String printActionHelp(CmdLineAction action, Set<CmdLineOption> options);
+
+   /**
+    * Generates help messages given {@link CmdLineAction}s.
+    * 
+    * @param actions
+    *           {@link CmdLineAction}s to print help for
+    * @return Help message for given {@link CmdLineAction}s
+    */
+   public String printActionsHelp(Set<CmdLineAction> actions);
+
+   /**
+    * Generates help message for given {@link CmdLineOption}s.
+    * 
+    * @param options
+    *           {@link CmdLineOption}s for which help message will be generated
+    * @return Help message for given {@link CmdLineOption}s
+    */
+   public String printOptionsHelp(Set<CmdLineOption> options);
+
+   /**
+    * Generate validation error message for results of failed validations.
+    * 
+    * @param results
+    *           {@link List} of FAILed validations
+    * @return Generated validation error message
+    */
+   public String printOptionValidationErrors(List<Result> results);
+
+   /**
+    * Generates missing required options error message from given
+    * {@link CmdLineOption}s which where required and not specified.
+    * 
+    * @param missingOptions
+    *           {@link Set} of {@link CmdLineOption}s which where required and
+    *           not set.
+    * @return Generated missing required options error message.
+    */
+   public String printRequiredOptionsMissingError(
+         Set<CmdLineOption> missingOptions);
+}

Propchange: oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/printer/CmdLinePrinter.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/printer/StdCmdLinePrinter.java
URL: http://svn.apache.org/viewvc/oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/printer/StdCmdLinePrinter.java?rev=1200439&view=auto
==============================================================================
--- oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/printer/StdCmdLinePrinter.java (added)
+++ oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/printer/StdCmdLinePrinter.java Thu Nov 10 17:27:28 2011
@@ -0,0 +1,262 @@
+/*
+ * 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.oodt.cas.cli.printer;
+
+//OODT static imports
+import static org.apache.oodt.cas.cli.util.CmdLineUtils.asGroupOption;
+import static org.apache.oodt.cas.cli.util.CmdLineUtils.determineOptional;
+import static org.apache.oodt.cas.cli.util.CmdLineUtils.determineRequired;
+import static org.apache.oodt.cas.cli.util.CmdLineUtils.determineRequiredSubOptions;
+import static org.apache.oodt.cas.cli.util.CmdLineUtils.getFormattedString;
+import static org.apache.oodt.cas.cli.util.CmdLineUtils.isGroupOption;
+import static org.apache.oodt.cas.cli.util.CmdLineUtils.sortOptionsByRequiredStatus;
+
+//JDK imports
+import java.util.List;
+import java.util.Set;
+
+//Apache imports
+import org.apache.commons.lang.StringUtils;
+
+//OODT imports
+import org.apache.oodt.cas.cli.action.CmdLineAction;
+import org.apache.oodt.cas.cli.option.ActionCmdLineOption;
+import org.apache.oodt.cas.cli.option.AdvancedCmdLineOption;
+import org.apache.oodt.cas.cli.option.CmdLineOption;
+import org.apache.oodt.cas.cli.option.GroupCmdLineOption;
+import org.apache.oodt.cas.cli.option.GroupSubOption;
+import org.apache.oodt.cas.cli.option.validator.CmdLineOptionValidator.Result;
+import org.apache.oodt.cas.cli.util.CmdLineUtils;
+
+import com.google.common.collect.Lists;
+
+/**
+ * Standard {@link CmdLinePrinter}.
+ * 
+ * @author bfoster (Brian Foster)
+ */
+public class StdCmdLinePrinter implements CmdLinePrinter {
+
+   @Override
+   public String printActionHelp(CmdLineAction action,
+         Set<CmdLineOption> options) {
+      StringBuffer sb = new StringBuffer("");
+      sb.append(getHeader(action)).append("\n");
+
+      sb.append(getRequiredSubHeader()).append("\n");
+      Set<CmdLineOption> requiredOptions = determineRequired(action, options);
+      List<CmdLineOption> sortedRequiredOptions = sortOptionsByRequiredStatus(requiredOptions);
+      for (CmdLineOption option : sortedRequiredOptions) {
+         sb.append(getRequiredOptionHelp(action, option)).append("\n");
+      }
+
+      sb.append(getOptionalSubHeader()).append("\n");
+      Set<CmdLineOption> optionalOptions = determineOptional(action, options);
+      List<CmdLineOption> sortedOptionalOptions = sortOptionsByRequiredStatus(optionalOptions);
+      for (CmdLineOption option : sortedOptionalOptions) {
+         sb.append(getOptionalOptionHelp(action, option)).append("\n");
+      }
+
+      sb.append(getFooter(action)).append("\n");
+      return sb.toString();
+   }
+
+   protected String getHeader(CmdLineAction action) {
+      return "Action Help for '" + action.getName() + "'";
+   }
+
+   protected String getRequiredSubHeader() {
+      return " - Required:";
+   }
+
+   protected String getRequiredOptionHelp(CmdLineAction action,
+         CmdLineOption option) {
+      if (option instanceof GroupCmdLineOption) {
+         return getGroupHelp(action, (GroupCmdLineOption) option, "    ");
+      } else {
+         return getOptionHelp(action, option, "    ");
+      }
+   }
+
+   protected String getOptionalSubHeader() {
+      return " - Optional:";
+   }
+
+   protected String getOptionalOptionHelp(CmdLineAction action,
+         CmdLineOption option) {
+      if (option instanceof GroupCmdLineOption) {
+         return getGroupHelp(action, (GroupCmdLineOption) option, "    ");
+      } else {
+         return getOptionHelp(action, option, "    ");
+      }
+   }
+
+   protected String getFooter(CmdLineAction action) {
+      return "";
+   }
+
+   protected String getOptionHelp(CmdLineAction action, CmdLineOption option,
+         String indent) {
+      String argDescription = null;
+      if (option instanceof AdvancedCmdLineOption) {
+         argDescription = ((AdvancedCmdLineOption) option).getHandler()
+               .getArgDescription(action, option);
+      }
+
+      String argHelp = null;
+      if (option instanceof ActionCmdLineOption && option.hasArgs()) {
+         argHelp = action.getName();
+      } else {
+         argHelp = (option.hasArgs() ? " <"
+               + (argDescription != null ? argDescription : option
+                     .getArgsDescription()) + ">" : "");
+      }
+      return indent + "-" + option.getShortOption() + " [--"
+            + option.getLongOption() + "]" + argHelp;
+   }
+
+   protected String getGroupHelp(CmdLineAction action,
+         GroupCmdLineOption option, String indent) {
+      String helpString = getOptionHelp(action, option, indent) + "\n";
+      Set<CmdLineOption> subOptions = determineRequiredSubOptions(action,
+            (GroupCmdLineOption) option);
+      if (subOptions.isEmpty()) {
+         if (!option.getSubOptions().isEmpty()) {
+            helpString += indent + "  One of:";
+            for (GroupSubOption subOption : option.getSubOptions()) {
+               helpString += "\n"
+                     + getOptionHelp(action, subOption.getOption(), "   "
+                           + indent);
+            }
+         }
+      } else {
+         for (CmdLineOption subOption : subOptions) {
+            if (subOption instanceof GroupCmdLineOption) {
+               helpString += getGroupHelp(action,
+                     (GroupCmdLineOption) subOption, "  " + indent);
+            } else {
+               helpString += getOptionHelp(action, subOption, "  " + indent);
+            }
+         }
+      }
+      return helpString;
+   }
+
+   @Override
+   public String printActionsHelp(Set<CmdLineAction> actions) {
+      StringBuffer sb = new StringBuffer("");
+      sb.append("Actions:").append("\n");
+      for (CmdLineAction action : actions) {
+         sb.append("  Action:").append("\n");
+         sb.append("    Name: ").append(action.getName()).append("\n");
+         sb.append("    Description: ").append(action.getDescription())
+               .append("\n").append("\n");
+      }
+      return sb.toString();
+   }
+
+   @Override
+   public String printOptionsHelp(Set<CmdLineOption> options) {
+      StringBuffer sb = new StringBuffer("");
+      List<CmdLineOption> sortedOptions = sortOptionsByRequiredStatus(options);
+      sb.append(getHeader()).append("\n");
+      for (CmdLineOption option : sortedOptions) {
+         sb.append(getOptionHelp(option, "")).append("\n");
+      }
+      sb.append(getFooter()).append("\n");
+      return sb.toString();
+   }
+
+   protected String getHeader() {
+      StringBuffer sb = new StringBuffer("");
+      sb.append("-----------------------------------------------------------------------------------------------------------------\n");
+      sb.append("|" + StringUtils.rightPad(" Short", 7) + "|"
+            + StringUtils.rightPad(" Long", 50) + "| Description\n");
+      sb.append("-----------------------------------------------------------------------------------------------------------------\n");
+      return sb.toString();
+   }
+
+   protected String getOptionHelp(CmdLineOption option, String indent) {
+      String argName = option.hasArgs() ? " <" + option.getArgsDescription()
+            + ">" : "";
+      String optionUsage = indent + "-"
+            + StringUtils.rightPad(option.getShortOption() + ",", 7) + "--"
+            + StringUtils.rightPad((option.getLongOption() + argName), 49 - indent.length())
+            + option.getDescription();
+
+      optionUsage = " " + optionUsage;
+
+      if (!option.getRequirementRules().isEmpty()) {
+         optionUsage += "\n"
+               + getFormattedString("Requirement Rules:", 62, 113)
+               + getFormattedString(option.getRequirementRules().toString(),
+                     63, 113);
+      }
+
+      if (option instanceof AdvancedCmdLineOption) {
+         if (((AdvancedCmdLineOption) option).hasHandler()) {
+            optionUsage += "\n"
+                  + getFormattedString("Handler:", 62, 113)
+                  + getFormattedString(((AdvancedCmdLineOption) option)
+                        .getHandler().getHelp(option), 63, 113);
+         }
+      } else if (isGroupOption(option)) {
+         GroupCmdLineOption groupOption = asGroupOption(option);
+         optionUsage += "\n";
+         optionUsage += "   SubOptions:\n";
+         optionUsage += "   > Required:\n";
+         
+         List<CmdLineOption> optionalOptions = Lists.newArrayList();
+         for (GroupSubOption subOption : groupOption.getSubOptions()) {
+            if (subOption.isRequired()) {
+               optionUsage += getOptionHelp(subOption.getOption(), "     ");
+            } else {
+               optionalOptions.add(subOption.getOption());
+            }
+         }
+         optionUsage += "   > Optional:\n";
+         for (CmdLineOption optionalOption : optionalOptions) {
+            optionUsage += getOptionHelp(optionalOption, "     ");
+         }
+      }
+
+      return optionUsage;
+   }
+
+   protected String getFooter() {
+      return "-----------------------------------------------------------------------------------------------------------------";
+   }
+
+   @Override
+   public String printOptionValidationErrors(List<Result> results) {
+      StringBuffer sb = new StringBuffer("Validation Failures:");
+      for (Result result : results) {
+         sb.append(" - ").append(result.getMessage()).append("\n");
+      }
+      return sb.toString();
+   }
+
+   @Override
+   public String printRequiredOptionsMissingError(
+         Set<CmdLineOption> missingOptions) {
+      StringBuffer sb = new StringBuffer("Missing required options:\n");
+      for (CmdLineOption option : missingOptions) {
+         sb.append(" - ").append(option.toString()).append("\n");
+      }
+      return sb.toString();
+   }
+}

Propchange: oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/printer/StdCmdLinePrinter.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/util/CmdLineIterable.java
URL: http://svn.apache.org/viewvc/oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/util/CmdLineIterable.java?rev=1200439&r1=1200438&r2=1200439&view=diff
==============================================================================
--- oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/util/CmdLineIterable.java (original)
+++ oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/util/CmdLineIterable.java Thu Nov 10 17:27:28 2011
@@ -39,7 +39,7 @@ public class CmdLineIterable<T> implemen
    public CmdLineIterable(List<T> args) {
       Validate.notNull(args);
 
-      curIndex = 0;
+      curIndex = -1;
       this.args = args;
    }
 
@@ -56,11 +56,15 @@ public class CmdLineIterable<T> implemen
    }
 
    public void incrementIndex() {
-      curIndex++;
+      if (curIndex < args.size()) {
+         curIndex++;
+      }
    }
 
    public void descrementIndex() {
-      curIndex--;
+      if (curIndex > 0) {
+         curIndex--;
+      }
    }
 
    public T incrementAndGet() {
@@ -83,11 +87,13 @@ public class CmdLineIterable<T> implemen
    }
 
    public boolean hasNext() {
-      return curIndex < args.size();
+      return curIndex + 1 < args.size();
    }
 
    public T getCurrentArg() {
-      if (hasNext()) {
+      if (curIndex == -1) {
+         return incrementAndGet();
+      } else if (curIndex > -1 && curIndex < args.size()) {
          return args.get(curIndex);
       } else {
          return null;
@@ -103,9 +109,9 @@ public class CmdLineIterable<T> implemen
 
          public T next() {
             if (!hasNext()) {
-               throw new IndexOutOfBoundsException(curIndex + "");
+               throw new IndexOutOfBoundsException((curIndex + 1) + "");
             }
-            return getAndIncrement();
+            return incrementAndGet();
          }
 
          public void remove() {

Modified: oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/util/CmdLineUtils.java
URL: http://svn.apache.org/viewvc/oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/util/CmdLineUtils.java?rev=1200439&r1=1200438&r2=1200439&view=diff
==============================================================================
--- oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/util/CmdLineUtils.java (original)
+++ oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/util/CmdLineUtils.java Thu Nov 10 17:27:28 2011
@@ -255,10 +255,21 @@ public class CmdLineUtils {
       Validate.notNull(optionName);
       Validate.notNull(options);
 
-      for (CmdLineOption option : options)
+      for (CmdLineOption option : options) {
          if (option.getLongOption().equals(optionName)
-               || option.getShortOption().equals(optionName))
+               || option.getShortOption().equals(optionName)) {
             return option;
+         } else if (isGroupOption(option)) {
+            Set<CmdLineOption> subOptions = Sets.newHashSet(); 
+            for (GroupSubOption subOption : asGroupOption(option).getSubOptions()) {
+               subOptions.add(subOption.getOption());
+            }
+            CmdLineOption foundOption = getOptionByName(optionName, subOptions);
+            if (foundOption != null) {
+               return foundOption;
+            }
+         }
+      }
       return null;
    }
 
@@ -524,18 +535,57 @@ public class CmdLineUtils {
     *           {@link ActionCmdLineOption}
     * @return The found {@link ActionCmdLineOption}, or null if not found
     */
-   public static ActionCmdLineOption findActionOption(Set<CmdLineOption> options) {
+   public static ActionCmdLineOption findFirstActionOption(
+         Set<CmdLineOption> options) {
       Validate.notNull(options);
 
       for (CmdLineOption option : options) {
          if (isActionOption(option)) {
             return (ActionCmdLineOption) option;
+         } else if (isGroupOption(option)) {
+            GroupCmdLineOption groupOption = (GroupCmdLineOption) option;
+            Set<CmdLineOption> subOptions = Sets.newHashSet();
+            for (GroupSubOption subOption : groupOption.getSubOptions()) {
+               subOptions.add(subOption.getOption());
+            }
+            ActionCmdLineOption foundOption = findFirstActionOption(subOptions);
+            if (foundOption != null) {
+               return foundOption;
+            }
          }
       }
       return null;
    }
 
    /**
+    * Finds all {@link CmdLineOption}s that are {@link ActionCmdLineOption}s.
+    * 
+    * @param options
+    *           The {@link CmdLineOption}s to look through for
+    *           {@link ActionCmdLineOption}s
+    * @return All {@link ActionCmdLineOption}s found
+    */
+   public static List<ActionCmdLineOption> findActionOptions(
+         Set<CmdLineOption> options) {
+      Validate.notNull(options);
+
+      List<ActionCmdLineOption> actionOptions = Lists.newArrayList();
+      for (CmdLineOption option : options) {
+         if (isActionOption(option)) {
+            actionOptions.add((ActionCmdLineOption) option);
+         } else if (isGroupOption(option)) {
+            GroupCmdLineOption groupOption = (GroupCmdLineOption) option;
+            Set<CmdLineOption> subOptions = Sets.newHashSet();
+            for (GroupSubOption subOption : groupOption.getSubOptions()) {
+               subOptions.add(subOption.getOption());
+            }
+            actionOptions.addAll(findActionOptions(subOptions));
+         }
+      }
+      return actionOptions;
+   }
+
+   /**
     * Find {@link ActionCmdLineOption} in {@link Set} of {@link CmdLineOption}s.
     * 
     * @param options
@@ -724,30 +774,46 @@ public class CmdLineUtils {
     * 
     * @param option
     *           The {@link CmdLineOptionInstance} to be validated
-    * @return True if {@link CmdLineOptionInstance} passed validation, false
-    *         otherwise
+    * @return {@link CmdLineOptionValidator.Result}s from running
+    *         {@link CmdLineOptionValidator}s.
     */
-   public static boolean validate(CmdLineOptionInstance option) {
+   public static List<CmdLineOptionValidator.Result> validate(
+         CmdLineOptionInstance option) {
       Validate.notNull(option);
 
+      List<CmdLineOptionValidator.Result> results = Lists.newArrayList();
       if (option.isValidatable()) {
          for (CmdLineOptionValidator validator : ((ValidatableCmdLineOption) option
                .getOption()).getValidators()) {
-            if (!validator.validate(option)) {
-               return false;
-            }
+            results.add(validator.validate(option));
          }
       }
 
       if (option.isGroup()) {
          for (CmdLineOptionInstance subOption : option.getSubOptions()) {
-            if (!validate(subOption)) {
-               return false;
-            }
+            results.addAll(validate(subOption));
          }
       }
+      return results;
+   }
 
-      return true;
+   /**
+    * Finds the {@link CmdLineOptionValidator.Result}s with grade of FAIL.
+    * 
+    * @param results
+    *           The {@link CmdLineOptionValidator.Result}s which are checked if
+    *           they have a failing grade.
+    * @return {@link CmdLineOptionValidator.Result}s with grade of FAIL.
+    */
+   public static List<CmdLineOptionValidator.Result> determineFailedValidation(
+         List<CmdLineOptionValidator.Result> results) {
+      List<CmdLineOptionValidator.Result> failedResults = Lists.newArrayList();
+      for (CmdLineOptionValidator.Result result : results) {
+         if (result.getGrade().equals(CmdLineOptionValidator.Result.Grade.FAIL)) {
+            failedResults.add(result);
+         }
+      }
+      return failedResults;
    }
 
    /**



Re: svn commit: r1200439 [1/2] - in /oodt/trunk/cli/src: main/java/org/apache/oodt/cas/cli/ main/java/org/apache/oodt/cas/cli/action/ main/java/org/apache/oodt/cas/cli/action/store/ main/java/org/apache/oodt/cas/cli/action/store/spring/ main/java/org/a...

Posted by "Mattmann, Chris A (388J)" <ch...@jpl.nasa.gov>.
woot!

On Nov 10, 2011, at 9:27 AM, <bf...@apache.org> <bf...@apache.org> wrote:

> Author: bfoster
> Date: Thu Nov 10 17:27:28 2011
> New Revision: 1200439
>
> URL: http://svn.apache.org/viewvc?rev=1200439&view=rev
> Log:
> - bug fixes
> - CmdLinePrinter cleanedup
> - stacktrace printout controlled and cleaned up
> - can use offline now... fixed spring schemalocation
> - updated unit-tests
>
> Added:
>    oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/exception/CmdLineActionException.java   (with props)
>    oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/exception/CmdLineActionExecutionException.java   (with props)
>    oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/exception/CmdLineActionStoreException.java   (with props)
>    oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/exception/CmdLineOptionStoreException.java   (with props)
>    oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/exception/CmdLineParserException.java   (with props)
>    oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/exception/CmdLineUtilityException.java   (with props)
>    oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/presenter/
>      - copied from r1198889, oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/help/presenter/
>    oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/presenter/CmdLinePresenter.java   (with props)
>    oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/presenter/StdCmdLinePresenter.java   (with props)
>    oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/printer/
>    oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/printer/CmdLinePrinter.java   (with props)
>    oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/printer/StdCmdLinePrinter.java   (with props)
> Removed:
>    oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/help/presenter/
>    oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/help/printer/
>    oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/presenter/CmdLineOptionHelpPresenter.java
>    oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/presenter/StdCmdLineOptionHelpPresenter.java
> Modified:
>    oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/CmdLineArgs.java
>    oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/CmdLineUtility.java
>    oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/action/CmdLineAction.java
>    oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/action/store/CmdLineActionStore.java
>    oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/action/store/CmdLineActionStoreFactory.java
>    oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/action/store/spring/SpringCmdLineActionStore.java
>    oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/action/store/spring/SpringCmdLineActionStoreFactory.java
>    oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/contruct/StdCmdLineConstructor.java
>    oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/store/CmdLineOptionStore.java
>    oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/store/spring/SpringCmdLineOptionStore.java
>    oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/store/spring/SpringCmdLineOptionStoreFactory.java
>    oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/validator/AllowedArgsCmdLineOptionValidator.java
>    oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/validator/ArgRegExpCmdLineOptionValidator.java
>    oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/validator/ClassExistsCmdLineOptionValidator.java
>    oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/validator/CmdLineOptionValidator.java
>    oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/validator/FileExistCmdLineOptionValidator.java
>    oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/validator/NoRestrictionsCmdLineOptionValidator.java
>    oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/parser/CmdLineParser.java
>    oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/parser/StdCmdLineParser.java
>    oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/util/CmdLineIterable.java
>    oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/util/CmdLineUtils.java
>    oodt/trunk/cli/src/test/org/apache/oodt/cas/cli/TestCmdLineUtility.java
>    oodt/trunk/cli/src/test/org/apache/oodt/cas/cli/action/store/spring/TestSpringCmdLineActionStore.java
>    oodt/trunk/cli/src/test/org/apache/oodt/cas/cli/option/store/spring/TestSpringCmdLineOptionStore.java
>    oodt/trunk/cli/src/test/org/apache/oodt/cas/cli/option/validator/TestAllowedArgsCmdLineOptionValidator.java
>    oodt/trunk/cli/src/test/org/apache/oodt/cas/cli/option/validator/TestArgRegExpCmdLineOptionValidator.java
>    oodt/trunk/cli/src/test/org/apache/oodt/cas/cli/option/validator/TestClassExistsCmdLineOptionValidator.java
>    oodt/trunk/cli/src/test/org/apache/oodt/cas/cli/option/validator/TestFileExistCmdLineOptionValidator.java
>    oodt/trunk/cli/src/test/org/apache/oodt/cas/cli/option/validator/TestNoRestrictionsCmdLineOptionValidator.java
>    oodt/trunk/cli/src/test/org/apache/oodt/cas/cli/parser/TestStdCmdLineOptionParser.java
>    oodt/trunk/cli/src/test/org/apache/oodt/cas/cli/util/TestCmdLineIterable.java
>    oodt/trunk/cli/src/test/org/apache/oodt/cas/cli/util/TestCmdLineUtils.java
>    oodt/trunk/cli/src/testdata/cmd-line-actions.xml
>    oodt/trunk/cli/src/testdata/cmd-line-options.xml
>
> Modified: oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/CmdLineArgs.java
> URL: http://svn.apache.org/viewvc/oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/CmdLineArgs.java?rev=1200439&r1=1200438&r2=1200439&view=diff
> ==============================================================================
> --- oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/CmdLineArgs.java (original)
> +++ oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/CmdLineArgs.java Thu Nov 10 17:27:28 2011
> @@ -39,7 +39,7 @@ import org.apache.oodt.cas.cli.option.Pr
> /**
>  * A convenience class for {@link CmdLineUtility} for helping use already parsed
>  * Command-Line arguments.
> - *
> + *
>  * @author bfoster (Brian Foster)
>  */
> public class CmdLineArgs {
>
> Modified: oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/CmdLineUtility.java
> URL: http://svn.apache.org/viewvc/oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/CmdLineUtility.java?rev=1200439&r1=1200438&r2=1200439&view=diff
> ==============================================================================
> --- oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/CmdLineUtility.java (original)
> +++ oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/CmdLineUtility.java Thu Nov 10 17:27:28 2011
> @@ -17,13 +17,15 @@
> package org.apache.oodt.cas.cli;
>
> //OODT static imports
> +import static org.apache.oodt.cas.cli.util.CmdLineUtils.determineFailedValidation;
> import static org.apache.oodt.cas.cli.util.CmdLineUtils.determineRequired;
> -import static org.apache.oodt.cas.cli.util.CmdLineUtils.findActionOption;
> +import static org.apache.oodt.cas.cli.util.CmdLineUtils.findFirstActionOption;
> import static org.apache.oodt.cas.cli.util.CmdLineUtils.findHelpOption;
> +import static org.apache.oodt.cas.cli.util.CmdLineUtils.findPrintSupportedActionsOption;
>
> //JDK imports
> -import java.io.IOException;
> import java.util.HashSet;
> +import java.util.List;
> import java.util.Set;
>
> //Apache imports
> @@ -34,15 +36,12 @@ import org.apache.oodt.cas.cli.action.st
> import org.apache.oodt.cas.cli.action.store.spring.SpringCmdLineActionStoreFactory;
> import org.apache.oodt.cas.cli.contruct.CmdLineConstructor;
> import org.apache.oodt.cas.cli.contruct.StdCmdLineConstructor;
> +import org.apache.oodt.cas.cli.exception.CmdLineActionException;
> +import org.apache.oodt.cas.cli.exception.CmdLineActionExecutionException;
> +import org.apache.oodt.cas.cli.exception.CmdLineActionStoreException;
> import org.apache.oodt.cas.cli.exception.CmdLineConstructionException;
> -import org.apache.oodt.cas.cli.help.presenter.CmdLineOptionHelpPresenter;
> -import org.apache.oodt.cas.cli.help.presenter.StdCmdLineOptionHelpPresenter;
> -import org.apache.oodt.cas.cli.help.printer.CmdLineActionHelpPrinter;
> -import org.apache.oodt.cas.cli.help.printer.CmdLineActionsHelpPrinter;
> -import org.apache.oodt.cas.cli.help.printer.CmdLineOptionsHelpPrinter;
> -import org.apache.oodt.cas.cli.help.printer.StdCmdLineActionHelpPrinter;
> -import org.apache.oodt.cas.cli.help.printer.StdCmdLineActionsHelpPrinter;
> -import org.apache.oodt.cas.cli.help.printer.StdCmdLineOptionsHelpPrinter;
> +import org.apache.oodt.cas.cli.exception.CmdLineOptionStoreException;
> +import org.apache.oodt.cas.cli.exception.CmdLineParserException;
> import org.apache.oodt.cas.cli.option.ActionCmdLineOption;
> import org.apache.oodt.cas.cli.option.CmdLineOption;
> import org.apache.oodt.cas.cli.option.CmdLineOptionInstance;
> @@ -50,12 +49,20 @@ import org.apache.oodt.cas.cli.option.He
> import org.apache.oodt.cas.cli.option.PrintSupportedActionsCmdLineOption;
> import org.apache.oodt.cas.cli.option.store.CmdLineOptionStore;
> import org.apache.oodt.cas.cli.option.store.spring.SpringCmdLineOptionStoreFactory;
> +import org.apache.oodt.cas.cli.option.validator.CmdLineOptionValidator;
> import org.apache.oodt.cas.cli.parser.CmdLineParser;
> import org.apache.oodt.cas.cli.parser.StdCmdLineParser;
> +import org.apache.oodt.cas.cli.presenter.CmdLinePresenter;
> +import org.apache.oodt.cas.cli.presenter.StdCmdLinePresenter;
> +import org.apache.oodt.cas.cli.printer.CmdLinePrinter;
> +import org.apache.oodt.cas.cli.printer.StdCmdLinePrinter;
> import org.apache.oodt.cas.cli.util.CmdLineIterable;
> import org.apache.oodt.cas.cli.util.CmdLineUtils;
> import org.apache.oodt.cas.cli.util.ParsedArg;
>
> +//Google imports
> +import com.google.common.collect.Lists;
> +
> /**
>  * A highly configurable utility class which supports parsing and handling of
>  * command line arguments via its action driven design. After parsing the
> @@ -68,24 +75,23 @@ import org.apache.oodt.cas.cli.util.Pars
>  */
> public class CmdLineUtility {
>
> +   private boolean debugMode;
>    private CmdLineParser parser;
>    private CmdLineConstructor constructor;
>    private CmdLineOptionStore optionStore;
>    private CmdLineActionStore actionStore;
> -   private CmdLineOptionsHelpPrinter optionHelpPrinter;
> -   private CmdLineActionHelpPrinter actionHelpPrinter;
> -   private CmdLineActionsHelpPrinter actionsHelpPrinter;
> -   private CmdLineOptionHelpPresenter helpPresenter;
> +   private CmdLinePrinter printer;
> +   private CmdLinePresenter presenter;
>
>    public CmdLineUtility() {
>       parser = new StdCmdLineParser();
>       constructor = new StdCmdLineConstructor();
>       optionStore = new SpringCmdLineOptionStoreFactory().createStore();
>       actionStore = new SpringCmdLineActionStoreFactory().createStore();
> -      optionHelpPrinter = new StdCmdLineOptionsHelpPrinter();
> -      actionHelpPrinter = new StdCmdLineActionHelpPrinter();
> -      actionsHelpPrinter = new StdCmdLineActionsHelpPrinter();
> -      helpPresenter = new StdCmdLineOptionHelpPresenter();
> +      printer = new StdCmdLinePrinter();
> +      presenter = new StdCmdLinePresenter();
> +
> +      debugMode = Boolean.getBoolean("org.apache.oodt.cas.cli.debug");
>    }
>
>    public CmdLineOptionStore getOptionStore() {
> @@ -104,58 +110,53 @@ public class CmdLineUtility {
>       this.actionStore = actionStore;
>    }
>
> -   public CmdLineOptionsHelpPrinter getOptionHelpPrinter() {
> -      return optionHelpPrinter;
> -   }
> -
> -   public void setOptionHelpPrinter(CmdLineOptionsHelpPrinter optionHelpPrinter) {
> -      this.optionHelpPrinter = optionHelpPrinter;
> -   }
> -
> -   public CmdLineActionHelpPrinter getActionHelpPrinter() {
> -      return actionHelpPrinter;
> +   public CmdLinePrinter getPrinter() {
> +      return printer;
>    }
>
> -   public void setActionHelpPrinter(CmdLineActionHelpPrinter actionHelpPrinter) {
> -      this.actionHelpPrinter = actionHelpPrinter;
> +   public void setPrinter(CmdLinePrinter printer) {
> +      this.printer = printer;
>    }
>
> -   public CmdLineActionsHelpPrinter getActionsHelpPrinter() {
> -      return actionsHelpPrinter;
> +   public CmdLinePresenter getPresenter() {
> +      return presenter;
>    }
>
> -   public void setActionsHelpPrinter(
> -         CmdLineActionsHelpPrinter actionsHelpPrinter) {
> -      this.actionsHelpPrinter = actionsHelpPrinter;
> -   }
> -
> -   public CmdLineOptionHelpPresenter getHelpPresenter() {
> -      return helpPresenter;
> -   }
> -
> -   public void setHelpPresenter(CmdLineOptionHelpPresenter helpPresenter) {
> -      this.helpPresenter = helpPresenter;
> +   public void setPresenter(CmdLinePresenter presenter) {
> +      this.presenter = presenter;
>    }
>
>    public void printOptionHelp(CmdLineArgs cmdLineArgs) {
> -      helpPresenter.presentOptionHelp(optionHelpPrinter.printHelp(cmdLineArgs
> +      presenter.presentOptionHelp(printer.printOptionsHelp(cmdLineArgs
>             .getSupportedOptions()));
>    }
>
>    public void printActionHelp(CmdLineArgs cmdLineArgs) {
>       Validate.notEmpty(cmdLineArgs.getHelpOptionInst().getValues());
>
> -      helpPresenter.presentActionHelp(actionHelpPrinter.printHelp(
> +      presenter.presentActionHelp(printer.printActionHelp(
>             CmdLineUtils.findAction(cmdLineArgs.getHelpOptionInst().getValues()
>                   .get(0), cmdLineArgs.getSupportedActions()),
>             cmdLineArgs.getSupportedOptions()));
>    }
>
>    public void printActionsHelp(CmdLineArgs cmdLineArgs) {
> -      helpPresenter.presentActionsHelp(actionsHelpPrinter.printHelp(cmdLineArgs
> +      presenter.presentActionsHelp(printer.printActionsHelp(cmdLineArgs
>             .getSupportedActions()));
>    }
>
> +   public void printValidationErrors(List<CmdLineOptionValidator.Result> results) {
> +      presenter.presentErrorMessage(printer.printOptionValidationErrors(results));
> +   }
> +
> +   public void printMissingRequiredOptionsError(Set<CmdLineOption> missingOptions) {
> +      presenter.presentErrorMessage(printer.printRequiredOptionsMissingError(missingOptions));
> +   }
> +
> +   public void printErrorMessage(String errorMessage) {
> +      presenter.presentErrorMessage(errorMessage);
> +   }
> +
>    /**
>     * Parses given command line arguments, then checks for help and print
>     * supported actions options, prints them out if found, otherwise performs
> @@ -163,17 +164,18 @@ public class CmdLineUtility {
>     *
>     * @param args
>     *           The who will be parsed and executed.
> -    * @throws IOException
> -    *            On error parsing or executing the args.
> -    * @throws CmdLineConstructionException
> -    *            On error constructing or executing the args.
>     */
> -   public void run(String[] args) throws IOException, CmdLineConstructionException {
> -      CmdLineArgs cmdLineArgs = parse(args);
> -      if (cmdLineArgs.getSpecifiedOptions().isEmpty()) {
> -         printOptionHelp(cmdLineArgs);
> -      } else if (!handleHelp(cmdLineArgs) && !handlePrintSupportedActions(cmdLineArgs)) {
> -         execute(cmdLineArgs);
> +   public void run(String[] args) {
> +      try {
> +         CmdLineArgs cmdLineArgs = parse(args);
> +         if (cmdLineArgs.getSpecifiedOptions().isEmpty()) {
> +            printOptionHelp(cmdLineArgs);
> +         } else if (!handleHelp(cmdLineArgs) && !handlePrintSupportedActions(cmdLineArgs)) {
> +            execute(cmdLineArgs);
> +         }
> +      } catch (Exception e) {
> +         if (debugMode) { e.printStackTrace(); }
> +         printErrorMessage(e.getMessage());
>       }
>    }
>
> @@ -188,8 +190,11 @@ public class CmdLineUtility {
>     *            On error parsing command line arguments.
>     * @throws CmdLineConstructionException
>     *            On error constructing command line arguments.
> +    * @throws CmdLineOptionStoreException
>     */
> -   public CmdLineArgs parse(String[] args) throws IOException, CmdLineConstructionException {
> +   public CmdLineArgs parse(String[] args) throws CmdLineParserException,
> +         CmdLineActionStoreException, CmdLineConstructionException,
> +         CmdLineOptionStoreException {
>       Validate.notNull(parser);
>       Validate.notNull(optionStore);
>
> @@ -197,27 +202,25 @@ public class CmdLineUtility {
>       Set<CmdLineOption> validOptions = optionStore.loadSupportedOptions();
>
>       // Insure help options is present if required.
> -      HelpCmdLineOption helpOption = findHelpOption(validOptions);
> -      if (helpOption == null) {
> -         validOptions.add(helpOption = new HelpCmdLineOption());
> +      if (findHelpOption(validOptions) == null) {
> +         validOptions.add(new HelpCmdLineOption());
>       }
>
> -      // Insure action options is present if required.
> -      ActionCmdLineOption actionOption = findActionOption(validOptions);
> -      if (actionOption == null) {
> -         validOptions.add(actionOption = new ActionCmdLineOption());
> +      // Insure action options are present if required.
> +      if (findFirstActionOption(validOptions) == null) {
> +         validOptions.add(new ActionCmdLineOption());
>       }
>
>       // Insure print supported actions option is present if required.
> -      PrintSupportedActionsCmdLineOption psaOption = CmdLineUtils
> -            .findPrintSupportedActionsOption(validOptions);
> -      if (psaOption == null) {
> -         validOptions.add(psaOption = new PrintSupportedActionsCmdLineOption());
> +      if (findPrintSupportedActionsOption(validOptions) == null) {
> +         validOptions.add(new PrintSupportedActionsCmdLineOption());
>       }
>
>       // Parse command line arguments.
>       return new CmdLineArgs(actionStore.loadSupportedActions(), validOptions,
> -            constructor.construct(new CmdLineIterable<ParsedArg>(parser.parse(args)), validOptions));
> +            constructor.construct(
> +                  new CmdLineIterable<ParsedArg>(parser.parse(args)),
> +                  validOptions));
>    }
>
>    /**
> @@ -263,20 +266,23 @@ public class CmdLineUtility {
>     * @param cmdLineArgs
>     *           The {@link CmdLineArgs} for which execution processing will be
>     *           run.
> -    * @throws IOException
> -    *            If required options are missing or validation fails.
>     */
> -   public static void execute(CmdLineArgs cmdLineArgs) throws IOException {
> +   public void execute(CmdLineArgs cmdLineArgs)
> +         throws CmdLineActionExecutionException, CmdLineActionException {
> +      if (cmdLineArgs.getActionOptionInst() == null) {
> +         throw new CmdLineActionExecutionException(
> +               "Must specify an action option!");
> +      }
>       Set<CmdLineOption> requiredOptionsNotSet = check(cmdLineArgs);
>       if (!requiredOptionsNotSet.isEmpty()) {
> -         throw new IOException("Required options are not set: '"
> -               + requiredOptionsNotSet + "'");
> +         printMissingRequiredOptionsError(requiredOptionsNotSet);
> +         return;
>       }
>
> -      Set<CmdLineOptionInstance> optionsFailedValidation = validate(cmdLineArgs);
> -      if (!optionsFailedValidation.isEmpty()) {
> -         throw new IOException("Options failed validation: '"
> -               + optionsFailedValidation + "'");
> +      List<CmdLineOptionValidator.Result> failedValidationResults = determineFailedValidation(validate(cmdLineArgs));
> +      if (!failedValidationResults.isEmpty()) {
> +         printValidationErrors(failedValidationResults);
> +         return;
>       }
>
>       handle(cmdLineArgs);
> @@ -307,24 +313,23 @@ public class CmdLineUtility {
>    }
>
>    /**
> -    * Runs validation on {@link CmdLineArgs} and returns the options which
> -    * failed validation.
> +    * Runs validation on {@link CmdLineArgs} and returns the validation results.
>     *
>     * @param cmdLineArgs
>     *           The {@link CmdLineArgs} which will be validated.
> -    * @return The {@link CmdLineOptionInstance}s which failed validation.
> +    * @return The {@link CmdLineOptionValidator.Result}s generated when running
> +    *    {@link CmdLineOptionValidator}s.
>     */
> -   public static Set<CmdLineOptionInstance> validate(CmdLineArgs cmdLineArgs) {
> +   public static List<CmdLineOptionValidator.Result> validate(
> +         CmdLineArgs cmdLineArgs) {
>       Validate.notNull(cmdLineArgs);
>
> -      HashSet<CmdLineOptionInstance> optionsFailed = new HashSet<CmdLineOptionInstance>();
> +      List<CmdLineOptionValidator.Result> results = Lists.newArrayList();
>       for (CmdLineOptionInstance optionInst : cmdLineArgs
>             .getSpecifiedOptions()) {
> -         if (!CmdLineUtils.validate(optionInst)) {
> -            optionsFailed.add(optionInst);
> -         }
> +         results.addAll(CmdLineUtils.validate(optionInst));
>       }
> -      return optionsFailed;
> +      return results;
>    }
>
>    /**
>
> Modified: oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/action/CmdLineAction.java
> URL: http://svn.apache.org/viewvc/oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/action/CmdLineAction.java?rev=1200439&r1=1200438&r2=1200439&view=diff
> ==============================================================================
> --- oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/action/CmdLineAction.java (original)
> +++ oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/action/CmdLineAction.java Thu Nov 10 17:27:28 2011
> @@ -16,6 +16,9 @@
>  */
> package org.apache.oodt.cas.cli.action;
>
> +//OODT imports
> +import org.apache.oodt.cas.cli.exception.CmdLineActionException;
> +
> /**
>  * Action which is specified and configured via {@link CmdLineOption}s and
>  * then executed.
> @@ -51,6 +54,6 @@ public abstract class CmdLineAction {
>       return description;
>    }
>
> -   public abstract void execute();
> +   public abstract void execute() throws CmdLineActionException;
>
> }
>
> Modified: oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/action/store/CmdLineActionStore.java
> URL: http://svn.apache.org/viewvc/oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/action/store/CmdLineActionStore.java?rev=1200439&r1=1200438&r2=1200439&view=diff
> ==============================================================================
> --- oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/action/store/CmdLineActionStore.java (original)
> +++ oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/action/store/CmdLineActionStore.java Thu Nov 10 17:27:28 2011
> @@ -21,6 +21,7 @@ import java.util.Set;
>
> //OODT imports
> import org.apache.oodt.cas.cli.action.CmdLineAction;
> +import org.apache.oodt.cas.cli.exception.CmdLineActionStoreException;
>
> /**
>  * Storage for loading supported {@link CmdLineAction}s.
> @@ -29,6 +30,6 @@ import org.apache.oodt.cas.cli.action.Cm
>  */
> public interface CmdLineActionStore {
>
> -   public Set<CmdLineAction> loadSupportedActions();
> -
> +   public Set<CmdLineAction> loadSupportedActions()
> +         throws CmdLineActionStoreException;
> }
>
> Modified: oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/action/store/CmdLineActionStoreFactory.java
> URL: http://svn.apache.org/viewvc/oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/action/store/CmdLineActionStoreFactory.java?rev=1200439&r1=1200438&r2=1200439&view=diff
> ==============================================================================
> --- oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/action/store/CmdLineActionStoreFactory.java (original)
> +++ oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/action/store/CmdLineActionStoreFactory.java Thu Nov 10 17:27:28 2011
> @@ -24,5 +24,4 @@ package org.apache.oodt.cas.cli.action.s
> public interface CmdLineActionStoreFactory {
>
>    public CmdLineActionStore createStore();
> -
> }
>
> Modified: oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/action/store/spring/SpringCmdLineActionStore.java
> URL: http://svn.apache.org/viewvc/oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/action/store/spring/SpringCmdLineActionStore.java?rev=1200439&r1=1200438&r2=1200439&view=diff
> ==============================================================================
> --- oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/action/store/spring/SpringCmdLineActionStore.java (original)
> +++ oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/action/store/spring/SpringCmdLineActionStore.java Thu Nov 10 17:27:28 2011
> @@ -25,6 +25,7 @@ import java.util.Map.Entry;
> //OODT imports
> import org.apache.oodt.cas.cli.action.CmdLineAction;
> import org.apache.oodt.cas.cli.action.store.CmdLineActionStore;
> +import org.apache.oodt.cas.cli.exception.CmdLineActionStoreException;
> import org.springframework.context.ApplicationContext;
> import org.springframework.context.support.FileSystemXmlApplicationContext;
>
> @@ -43,7 +44,9 @@ public class SpringCmdLineActionStore im
>       handleSettingNameForCmdLineActions();
>    }
>
> -   public Set<CmdLineAction> loadSupportedActions() {
> +   @Override
> +   public Set<CmdLineAction> loadSupportedActions()
> +         throws CmdLineActionStoreException {
>       @SuppressWarnings("unchecked")
>       Map<String, CmdLineAction> actionsMap = appContext
>             .getBeansOfType(CmdLineAction.class);
>
> Modified: oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/action/store/spring/SpringCmdLineActionStoreFactory.java
> URL: http://svn.apache.org/viewvc/oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/action/store/spring/SpringCmdLineActionStoreFactory.java?rev=1200439&r1=1200438&r2=1200439&view=diff
> ==============================================================================
> --- oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/action/store/spring/SpringCmdLineActionStoreFactory.java (original)
> +++ oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/action/store/spring/SpringCmdLineActionStoreFactory.java Thu Nov 10 17:27:28 2011
> @@ -17,6 +17,7 @@
> package org.apache.oodt.cas.cli.action.store.spring;
>
> //OODT imports
> +import org.apache.commons.lang.Validate;
> import org.apache.oodt.cas.cli.action.store.CmdLineActionStoreFactory;
>
> /**
> @@ -35,10 +36,8 @@ public class SpringCmdLineActionStoreFac
>    }
>
>    public SpringCmdLineActionStore createStore() {
> -      if (config != null) {
> -         return new SpringCmdLineActionStore(config);
> -      } else {
> -         return null;
> -      }
> +      Validate.notNull(config);
> +
> +      return new SpringCmdLineActionStore(config);
>    }
> }
>
> Modified: oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/contruct/StdCmdLineConstructor.java
> URL: http://svn.apache.org/viewvc/oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/contruct/StdCmdLineConstructor.java?rev=1200439&r1=1200438&r2=1200439&view=diff
> ==============================================================================
> --- oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/contruct/StdCmdLineConstructor.java (original)
> +++ oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/contruct/StdCmdLineConstructor.java Thu Nov 10 17:27:28 2011
> @@ -33,6 +33,7 @@ import java.util.Stack;
> import org.apache.commons.lang.Validate;
>
> //OODT imports
> +import org.apache.oodt.cas.cli.exception.CmdLineConstructionException;
> import org.apache.oodt.cas.cli.option.CmdLineOption;
> import org.apache.oodt.cas.cli.option.CmdLineOptionInstance;
> import org.apache.oodt.cas.cli.option.GroupCmdLineOption;
> @@ -52,7 +53,7 @@ import com.google.common.annotations.Vis
> public class StdCmdLineConstructor implements CmdLineConstructor {
>
>    public Set<CmdLineOptionInstance> construct(CmdLineIterable<ParsedArg> parsedArgs,
> -         Set<CmdLineOption> validOptions) {
> +         Set<CmdLineOption> validOptions) throws CmdLineConstructionException {
>       HashSet<CmdLineOptionInstance> optionInstances = new HashSet<CmdLineOptionInstance>();
>
>       Stack<CmdLineOptionInstance> groupOptions = new Stack<CmdLineOptionInstance>();
> @@ -64,7 +65,7 @@ public class StdCmdLineConstructor imple
>             CmdLineOption option = getOptionByName(arg.getName(),
>                   validOptions);
>             if (option == null) {
> -               throw new RuntimeException("Invalid option: '" + arg.getName() + "'");
> +               throw new CmdLineConstructionException("Invalid option: '" + arg.getName() + "'");
>             }
>
>             // read found option
> @@ -75,20 +76,20 @@ public class StdCmdLineConstructor imple
>
>                CmdLineOptionInstance currentGroup = groupOptions.peek();
>
> -               // Check if option is a subOption for current group.
> +               // Check if option is NOT a subOption for current group.
>                if (!isSubOption(currentGroup.getOption(), option)) {
>
>                   // Check if current group was expecting more subOptions.
>                   Set<CmdLineOption> requiredSubOptions = verifyGroupHasRequiredSubOptions(currentGroup);
>                   if (!requiredSubOptions.isEmpty()) {
> -                     throw new RuntimeException(
> +                     throw new CmdLineConstructionException(
>                            "Missing the following required subOptions for '"
>                                  + currentGroup.getOption()
>                                  + "': "
>                                  + sortOptionsByRequiredStatus(requiredSubOptions));
>
>                   } else if (currentGroup.getSubOptions().isEmpty()) {
> -                     throw new RuntimeException(
> +                     throw new CmdLineConstructionException(
>                            "Must specify a subOption for group option '"
>                                  + currentGroup.getOption() + "'");
>
> @@ -97,6 +98,7 @@ public class StdCmdLineConstructor imple
>                      // pop group and add to list of specified options.
>                      optionInstances.add(groupOptions.pop());
>                   }
> +               // It is a sub-option...
>                } else {
>
>                   // Add option to current group subOptions.
> @@ -110,9 +112,14 @@ public class StdCmdLineConstructor imple
>
>                // Push group as current group.
>                groupOptions.push(specifiedOption);
> -
> +
> +               if (!parsedArgs.hasNext()) {
> +                  throw new CmdLineConstructionException(
> +                        "Must specify a subOption for group option '"
> +                              + specifiedOption.getOption() + "'");
> +               }
>             } else if (option.isSubOption()) {
> -               throw new RuntimeException("Option '" + option
> +               throw new CmdLineConstructionException("Option '" + option
>                      + "' is a subOption, but was used at top level Option");
>
>             } else {
> @@ -121,14 +128,14 @@ public class StdCmdLineConstructor imple
>                optionInstances.add(specifiedOption);
>             }
>          } else {
> -            throw new RuntimeException("Invalid argument: '" + arg + "'");
> +            throw new CmdLineConstructionException("Invalid argument: '" + arg + "'");
>          }
>       }
>       while (!groupOptions.isEmpty()) {
>          CmdLineOptionInstance currentGroup = groupOptions.pop();
>          Set<CmdLineOption> requiredSubOptions = verifyGroupHasRequiredSubOptions(currentGroup);
>          if (!requiredSubOptions.isEmpty()) {
> -            throw new RuntimeException(
> +            throw new CmdLineConstructionException(
>                   "Missing the following required subOptions for '"
>                         + currentGroup.getOption() + "': "
>                         + sortOptionsByRequiredStatus(requiredSubOptions));
> @@ -142,7 +149,7 @@ public class StdCmdLineConstructor imple
>
>    @VisibleForTesting
>    /* package */static CmdLineOptionInstance getOption(CmdLineIterable<ParsedArg> args,
> -         CmdLineOption option) {
> +         CmdLineOption option) throws CmdLineConstructionException {
>       CmdLineOptionInstance specifiedOption = new CmdLineOptionInstance();
>       specifiedOption.setOption(option);
>       List<String> values = getValues(args);
> @@ -152,10 +159,10 @@ public class StdCmdLineConstructor imple
>          if (!values.isEmpty()) {
>             specifiedOption.setValues(values);
>          } else if (!option.hasStaticArgs()) {
> -            throw new RuntimeException("Option " + option + " requires args");
> +            throw new CmdLineConstructionException("Option " + option + " requires args");
>          }
>       } else if (!option.hasArgs() && !values.isEmpty()) {
> -         throw new RuntimeException("Option " + option + " does not support args");
> +         throw new CmdLineConstructionException("Option " + option + " does not support args");
>       }
>       return specifiedOption;
>    }
> @@ -185,11 +192,12 @@ public class StdCmdLineConstructor imple
>    @VisibleForTesting
>    /* package */static List<String> getValues(CmdLineIterable<ParsedArg> args) {
>       List<String> values = new ArrayList<String>();
> -      ParsedArg nextValue = args.getCurrentArg();
> +      ParsedArg nextValue = args.incrementAndGet();
>       while (nextValue != null && nextValue.getType().equals(ParsedArg.Type.VALUE)) {
>          values.add(nextValue.getName());
>          nextValue = args.incrementAndGet();
>       }
> +      args.descrementIndex();
>       return values;
>    }
> }
>
> Added: oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/exception/CmdLineActionException.java
> URL: http://svn.apache.org/viewvc/oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/exception/CmdLineActionException.java?rev=1200439&view=auto
> ==============================================================================
> --- oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/exception/CmdLineActionException.java (added)
> +++ oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/exception/CmdLineActionException.java Thu Nov 10 17:27:28 2011
> @@ -0,0 +1,35 @@
> +/*
> + * 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.oodt.cas.cli.exception;
> +
> +/**
> + * An {@link Exception} thrown when failure to execute a {@link CmdLineAction}.
> + *
> + * @author bfoster (Brian Foster)
> + */
> +public class CmdLineActionException extends Exception {
> +
> +   private static final long serialVersionUID = 6416302963047726032L;
> +
> +   public CmdLineActionException(String msg) {
> +      super(msg);
> +   }
> +
> +   public CmdLineActionException(String msg, Throwable t) {
> +      super(msg, t);
> +   }
> +}
>
> Propchange: oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/exception/CmdLineActionException.java
> ------------------------------------------------------------------------------
>    svn:mime-type = text/plain
>
> Added: oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/exception/CmdLineActionExecutionException.java
> URL: http://svn.apache.org/viewvc/oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/exception/CmdLineActionExecutionException.java?rev=1200439&view=auto
> ==============================================================================
> --- oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/exception/CmdLineActionExecutionException.java (added)
> +++ oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/exception/CmdLineActionExecutionException.java Thu Nov 10 17:27:28 2011
> @@ -0,0 +1,35 @@
> +/*
> + * 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.oodt.cas.cli.exception;
> +
> +/**
> + * An {@link Exception} thrown when failure to execute a {@link CmdLineAction}.
> + *
> + * @author bfoster (Brian Foster)
> + */
> +public class CmdLineActionExecutionException extends Exception {
> +
> +   private static final long serialVersionUID = 4784139793086538249L;
> +
> +   public CmdLineActionExecutionException(String msg) {
> +      super(msg);
> +   }
> +
> +   public CmdLineActionExecutionException(String msg, Throwable t) {
> +      super(msg, t);
> +   }
> +}
>
> Propchange: oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/exception/CmdLineActionExecutionException.java
> ------------------------------------------------------------------------------
>    svn:mime-type = text/plain
>
> Added: oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/exception/CmdLineActionStoreException.java
> URL: http://svn.apache.org/viewvc/oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/exception/CmdLineActionStoreException.java?rev=1200439&view=auto
> ==============================================================================
> --- oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/exception/CmdLineActionStoreException.java (added)
> +++ oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/exception/CmdLineActionStoreException.java Thu Nov 10 17:27:28 2011
> @@ -0,0 +1,35 @@
> +/*
> + * 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.oodt.cas.cli.exception;
> +
> +/**
> + * An {@link Exception} thrown by {@link CmdLineActionStore}.
> + *
> + * @author bfoster (Brian Foster)
> + */
> +public class CmdLineActionStoreException extends Exception {
> +
> +   private static final long serialVersionUID = 4303378887098186113L;
> +
> +   public CmdLineActionStoreException(String msg) {
> +      super(msg);
> +   }
> +
> +   public CmdLineActionStoreException(String msg, Throwable t) {
> +      super(msg, t);
> +   }
> +}
>
> Propchange: oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/exception/CmdLineActionStoreException.java
> ------------------------------------------------------------------------------
>    svn:mime-type = text/plain
>
> Added: oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/exception/CmdLineOptionStoreException.java
> URL: http://svn.apache.org/viewvc/oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/exception/CmdLineOptionStoreException.java?rev=1200439&view=auto
> ==============================================================================
> --- oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/exception/CmdLineOptionStoreException.java (added)
> +++ oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/exception/CmdLineOptionStoreException.java Thu Nov 10 17:27:28 2011
> @@ -0,0 +1,35 @@
> +/*
> + * 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.oodt.cas.cli.exception;
> +
> +/**
> + * An {@link Exception} thrown by {@link CmdLineOptionStore}.
> + *
> + * @author bfoster (Brian Foster)
> + */
> +public class CmdLineOptionStoreException extends Exception {
> +
> +   private static final long serialVersionUID = -5223714380324479058L;
> +
> +   public CmdLineOptionStoreException(String msg) {
> +      super(msg);
> +   }
> +
> +   public CmdLineOptionStoreException(String msg, Throwable t) {
> +      super(msg, t);
> +   }
> +}
>
> Propchange: oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/exception/CmdLineOptionStoreException.java
> ------------------------------------------------------------------------------
>    svn:mime-type = text/plain
>
> Added: oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/exception/CmdLineParserException.java
> URL: http://svn.apache.org/viewvc/oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/exception/CmdLineParserException.java?rev=1200439&view=auto
> ==============================================================================
> --- oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/exception/CmdLineParserException.java (added)
> +++ oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/exception/CmdLineParserException.java Thu Nov 10 17:27:28 2011
> @@ -0,0 +1,35 @@
> +/*
> + * 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.oodt.cas.cli.exception;
> +
> +/**
> + * A {@link Exception} throw when there is an error parsing command line args.
> + *
> + * @author bfoster (Brian Foster)
> + */
> +public class CmdLineParserException extends Exception {
> +
> +   private static final long serialVersionUID = 926637321837303042L;
> +
> +   public CmdLineParserException(String msg) {
> +      super(msg);
> +   }
> +
> +   public CmdLineParserException(String msg, Throwable t) {
> +      super(msg, t);
> +   }
> +}
>
> Propchange: oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/exception/CmdLineParserException.java
> ------------------------------------------------------------------------------
>    svn:mime-type = text/plain
>
> Added: oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/exception/CmdLineUtilityException.java
> URL: http://svn.apache.org/viewvc/oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/exception/CmdLineUtilityException.java?rev=1200439&view=auto
> ==============================================================================
> --- oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/exception/CmdLineUtilityException.java (added)
> +++ oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/exception/CmdLineUtilityException.java Thu Nov 10 17:27:28 2011
> @@ -0,0 +1,35 @@
> +/*
> + * 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.oodt.cas.cli.exception;
> +
> +/**
> + * An {@link Exception} thrown by {@link CmdLineUtility}.
> + *
> + * @author bfoster (Brian Foster)
> + */
> +public class CmdLineUtilityException extends Exception {
> +
> +   private static final long serialVersionUID = 2977147381764985598L;
> +
> +   public CmdLineUtilityException(String msg) {
> +      super(msg);
> +   }
> +
> +   public CmdLineUtilityException(String msg, Throwable t) {
> +      super(msg, t);
> +   }
> +}
>
> Propchange: oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/exception/CmdLineUtilityException.java
> ------------------------------------------------------------------------------
>    svn:mime-type = text/plain
>
> Modified: oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/store/CmdLineOptionStore.java
> URL: http://svn.apache.org/viewvc/oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/store/CmdLineOptionStore.java?rev=1200439&r1=1200438&r2=1200439&view=diff
> ==============================================================================
> --- oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/store/CmdLineOptionStore.java (original)
> +++ oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/store/CmdLineOptionStore.java Thu Nov 10 17:27:28 2011
> @@ -20,6 +20,7 @@ package org.apache.oodt.cas.cli.option.s
> import java.util.Set;
>
> //OODT imports
> +import org.apache.oodt.cas.cli.exception.CmdLineOptionStoreException;
> import org.apache.oodt.cas.cli.option.CmdLineOption;
>
> /**
> @@ -29,6 +30,7 @@ import org.apache.oodt.cas.cli.option.Cm
>  */
> public interface CmdLineOptionStore {
>
> -   public Set<CmdLineOption> loadSupportedOptions();
> +   public Set<CmdLineOption> loadSupportedOptions()
> +      throws CmdLineOptionStoreException;
>
> }
>
> Modified: oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/store/spring/SpringCmdLineOptionStore.java
> URL: http://svn.apache.org/viewvc/oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/store/spring/SpringCmdLineOptionStore.java?rev=1200439&r1=1200438&r2=1200439&view=diff
> ==============================================================================
> --- oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/store/spring/SpringCmdLineOptionStore.java (original)
> +++ oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/store/spring/SpringCmdLineOptionStore.java Thu Nov 10 17:27:28 2011
> @@ -21,6 +21,7 @@ import java.util.Map;
> import java.util.Set;
>
> //OODT imports
> +import org.apache.oodt.cas.cli.exception.CmdLineOptionStoreException;
> import org.apache.oodt.cas.cli.option.CmdLineOption;
> import org.apache.oodt.cas.cli.option.store.CmdLineOptionStore;
>
> @@ -28,6 +29,7 @@ import org.apache.oodt.cas.cli.option.st
> import org.springframework.context.ApplicationContext;
> import org.springframework.context.support.FileSystemXmlApplicationContext;
>
> +//Google imports
> import com.google.common.collect.Sets;
>
> /**
> @@ -43,7 +45,9 @@ public class SpringCmdLineOptionStore im
>       appContext = new FileSystemXmlApplicationContext(springConfig);
>    }
>
> -   public Set<CmdLineOption> loadSupportedOptions() {
> +   @Override
> +   public Set<CmdLineOption> loadSupportedOptions()
> +         throws CmdLineOptionStoreException {
>       @SuppressWarnings("unchecked")
>       Map<String, CmdLineOption> optionsMap = appContext
>             .getBeansOfType(CmdLineOption.class);
>
> Modified: oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/store/spring/SpringCmdLineOptionStoreFactory.java
> URL: http://svn.apache.org/viewvc/oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/store/spring/SpringCmdLineOptionStoreFactory.java?rev=1200439&r1=1200438&r2=1200439&view=diff
> ==============================================================================
> --- oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/store/spring/SpringCmdLineOptionStoreFactory.java (original)
> +++ oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/store/spring/SpringCmdLineOptionStoreFactory.java Thu Nov 10 17:27:28 2011
> @@ -17,6 +17,7 @@
> package org.apache.oodt.cas.cli.option.store.spring;
>
> //OODT imports
> +import org.apache.commons.lang.Validate;
> import org.apache.oodt.cas.cli.option.store.CmdLineOptionStoreFactory;
>
> /**
> @@ -34,12 +35,11 @@ public class SpringCmdLineOptionStoreFac
>             "org.apache.oodt.cas.cli.option.spring.config", null);
>    }
>
> +   @Override
>    public SpringCmdLineOptionStore createStore() {
> -      if (config != null) {
> -         return new SpringCmdLineOptionStore(config);
> -      } else {
> -         return null;
> -      }
> +      Validate.notNull(config);
> +
> +      return new SpringCmdLineOptionStore(config);
>    }
>
>    public void setConfig(String config) {
>
> Modified: oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/validator/AllowedArgsCmdLineOptionValidator.java
> URL: http://svn.apache.org/viewvc/oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/validator/AllowedArgsCmdLineOptionValidator.java?rev=1200439&r1=1200438&r2=1200439&view=diff
> ==============================================================================
> --- oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/validator/AllowedArgsCmdLineOptionValidator.java (original)
> +++ oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/validator/AllowedArgsCmdLineOptionValidator.java Thu Nov 10 17:27:28 2011
> @@ -23,6 +23,7 @@ import java.util.List;
> //OODT imports
> import org.apache.commons.lang.Validate;
> import org.apache.oodt.cas.cli.option.CmdLineOptionInstance;
> +import org.apache.oodt.cas.cli.option.validator.CmdLineOptionValidator.Result.Grade;
>
> /**
>  * A {@link CmdLineOptionValidator} which check args against a supplied list of
> @@ -39,18 +40,19 @@ public class AllowedArgsCmdLineOptionVal
>       this.allowedArgs = new LinkedList<String>();
>    }
>
> -   public boolean validate(CmdLineOptionInstance optionInst) {
> +   @Override
> +   public Result validate(CmdLineOptionInstance optionInst) {
>       Validate.notNull(optionInst);
>
>       for (String value : optionInst.getValues()) {
>          if (!allowedArgs.contains(value)) {
> -            LOG.severe("Option value " + value + " is not allowed for option "
> +            return new Result(Grade.FAIL, "Option value " + value
> +                  + " is not allowed for option "
>                   + optionInst.getOption().getLongOption()
>                   + " - Allowed values = " + this.getAllowedArgs());
> -            return false;
>          }
>       }
> -      return true;
> +      return new Result(Grade.PASS, "Success");
>    }
>
>    public List<String> getAllowedArgs() {
>
> Modified: oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/validator/ArgRegExpCmdLineOptionValidator.java
> URL: http://svn.apache.org/viewvc/oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/validator/ArgRegExpCmdLineOptionValidator.java?rev=1200439&r1=1200438&r2=1200439&view=diff
> ==============================================================================
> --- oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/validator/ArgRegExpCmdLineOptionValidator.java (original)
> +++ oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/validator/ArgRegExpCmdLineOptionValidator.java Thu Nov 10 17:27:28 2011
> @@ -22,6 +22,7 @@ import java.util.regex.Pattern;
> //OODT imports
> import org.apache.commons.lang.Validate;
> import org.apache.oodt.cas.cli.option.CmdLineOptionInstance;
> +import org.apache.oodt.cas.cli.option.validator.CmdLineOptionValidator.Result.Grade;
>
> /**
>  * Performs validation on option instances via allowed args which are regular
> @@ -33,7 +34,7 @@ public class ArgRegExpCmdLineOptionValid
>       AllowedArgsCmdLineOptionValidator {
>
>    @Override
> -   public boolean validate(CmdLineOptionInstance optionInst) {
> +   public Result validate(CmdLineOptionInstance optionInst) {
>       Validate.notNull(optionInst);
>
>       TOP: for (String value : optionInst.getValues()) {
> @@ -42,11 +43,11 @@ public class ArgRegExpCmdLineOptionValid
>                continue TOP;
>             }
>          }
> -         LOG.severe("Option1 value " + value + " is not allowed for option "
> +         return new Result(Grade.FAIL, "Option1 value " + value
> +               + " is not allowed for option "
>                + optionInst.getOption().getLongOption()
>                + " - Allowed values = " + getAllowedArgs());
> -         return false;
>       }
> -      return true;
> +      return new Result(Grade.PASS, "Success");
>    }
> }
>
> Modified: oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/validator/ClassExistsCmdLineOptionValidator.java
> URL: http://svn.apache.org/viewvc/oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/validator/ClassExistsCmdLineOptionValidator.java?rev=1200439&r1=1200438&r2=1200439&view=diff
> ==============================================================================
> --- oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/validator/ClassExistsCmdLineOptionValidator.java (original)
> +++ oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/validator/ClassExistsCmdLineOptionValidator.java Thu Nov 10 17:27:28 2011
> @@ -19,6 +19,7 @@ package org.apache.oodt.cas.cli.option.v
> //OODT imports
> import org.apache.commons.lang.Validate;
> import org.apache.oodt.cas.cli.option.CmdLineOptionInstance;
> +import org.apache.oodt.cas.cli.option.validator.CmdLineOptionValidator.Result.Grade;
>
> /**
>  * Validates arguments which are checked to see if they are valid classpaths.
> @@ -28,19 +29,19 @@ import org.apache.oodt.cas.cli.option.Cm
> public class ClassExistsCmdLineOptionValidator implements
>       CmdLineOptionValidator {
>
> -   public boolean validate(CmdLineOptionInstance optionInst) {
> +   @Override
> +   public Result validate(CmdLineOptionInstance optionInst) {
>       Validate.notNull(optionInst);
>
>       for (String value : optionInst.getValues()) {
>          try {
>             Class.forName(value);
>          } catch (Exception e) {
> -            LOG.severe("Option value " + value + " for option "
> -                  + optionInst.getOption().getLongOption()
> +            return new Result(Grade.FAIL, "Option value " + value
> +                  + " for option " + optionInst.getOption().getLongOption()
>                   + " is not a valid class");
> -            return false;
>          }
>       }
> -      return true;
> +      return new Result(Grade.PASS, "Success");
>    }
> }
>
> Modified: oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/validator/CmdLineOptionValidator.java
> URL: http://svn.apache.org/viewvc/oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/validator/CmdLineOptionValidator.java?rev=1200439&r1=1200438&r2=1200439&view=diff
> ==============================================================================
> --- oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/validator/CmdLineOptionValidator.java (original)
> +++ oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/validator/CmdLineOptionValidator.java Thu Nov 10 17:27:28 2011
> @@ -16,9 +16,6 @@
>  */
> package org.apache.oodt.cas.cli.option.validator;
>
> -//JDK imports
> -import java.util.logging.Logger;
> -
> //OODT imports
> import org.apache.oodt.cas.cli.option.CmdLineOptionInstance;
>
> @@ -29,8 +26,31 @@ import org.apache.oodt.cas.cli.option.Cm
>  */
> public interface CmdLineOptionValidator {
>
> -   static Logger LOG = Logger.getLogger(CmdLineOptionValidator.class.getName());
> -
> -   public boolean validate(CmdLineOptionInstance optionInst);
> -
> +   public class Result {
> +      public enum Grade {
> +         PASS, FAIL;
> +      }
> +
> +      private String message;
> +      private Grade grade;
> +
> +      public Result(Grade grade, String message) {
> +         this.message = message;
> +         this.grade = grade;
> +      }
> +
> +      public String getMessage() {
> +         return message;
> +      }
> +
> +      public Grade getGrade() {
> +         return grade;
> +      }
> +   }
> +
> +   /**
> +    * Throws {@link CmdLineValidationException} if validation fails, otherwise
> +    * method just returns.
> +    */
> +   public Result validate(CmdLineOptionInstance optionInst);
> }
>
> Modified: oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/validator/FileExistCmdLineOptionValidator.java
> URL: http://svn.apache.org/viewvc/oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/validator/FileExistCmdLineOptionValidator.java?rev=1200439&r1=1200438&r2=1200439&view=diff
> ==============================================================================
> --- oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/validator/FileExistCmdLineOptionValidator.java (original)
> +++ oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/validator/FileExistCmdLineOptionValidator.java Thu Nov 10 17:27:28 2011
> @@ -22,6 +22,7 @@ import java.io.File;
> //OODT imports
> import org.apache.commons.lang.Validate;
> import org.apache.oodt.cas.cli.option.CmdLineOptionInstance;
> +import org.apache.oodt.cas.cli.option.validator.CmdLineOptionValidator.Result.Grade;
>
> /**
>  * A {@link CmdLineOptionValidator} which checks args if they are existing
> @@ -31,17 +32,17 @@ import org.apache.oodt.cas.cli.option.Cm
>  */
> public class FileExistCmdLineOptionValidator implements CmdLineOptionValidator {
>
> -   public boolean validate(CmdLineOptionInstance optionInst) {
> +   @Override
> +   public Result validate(CmdLineOptionInstance optionInst) {
>       Validate.notNull(optionInst);
>
>       for (String value : optionInst.getValues()) {
>          if (!new File(value).exists()) {
> -            LOG.severe("Option value " + value + " for option "
> -                  + optionInst.getOption().getLongOption()
> +            return new Result(Grade.FAIL, "Option value " + value
> +                  + " for option " + optionInst.getOption().getLongOption()
>                   + " is not an existing file");
> -            return false;
>          }
>       }
> -      return true;
> +      return new Result(Grade.PASS, "Success");
>    }
> }
>
> Modified: oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/validator/NoRestrictionsCmdLineOptionValidator.java
> URL: http://svn.apache.org/viewvc/oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/validator/NoRestrictionsCmdLineOptionValidator.java?rev=1200439&r1=1200438&r2=1200439&view=diff
> ==============================================================================
> --- oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/validator/NoRestrictionsCmdLineOptionValidator.java (original)
> +++ oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/option/validator/NoRestrictionsCmdLineOptionValidator.java Thu Nov 10 17:27:28 2011
> @@ -18,6 +18,7 @@ package org.apache.oodt.cas.cli.option.v
>
> //OODT imports
> import org.apache.oodt.cas.cli.option.CmdLineOptionInstance;
> +import org.apache.oodt.cas.cli.option.validator.CmdLineOptionValidator.Result.Grade;
>
> /**
>  * A {@link CmdLineOptionValidator} which always returns true.
> @@ -27,7 +28,7 @@ import org.apache.oodt.cas.cli.option.Cm
> public class NoRestrictionsCmdLineOptionValidator implements
>       CmdLineOptionValidator {
>
> -   public boolean validate(CmdLineOptionInstance optionInst) {
> -      return true;
> +   public Result validate(CmdLineOptionInstance optionInst) {
> +      return new Result(Grade.PASS, "Success");
>    }
> }
>
> Modified: oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/parser/CmdLineParser.java
> URL: http://svn.apache.org/viewvc/oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/parser/CmdLineParser.java?rev=1200439&r1=1200438&r2=1200439&view=diff
> ==============================================================================
> --- oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/parser/CmdLineParser.java (original)
> +++ oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/parser/CmdLineParser.java Thu Nov 10 17:27:28 2011
> @@ -17,10 +17,10 @@
> package org.apache.oodt.cas.cli.parser;
>
> //JDK imports
> -import java.io.IOException;
> import java.util.List;
>
> //OODT imports
> +import org.apache.oodt.cas.cli.exception.CmdLineParserException;
> import org.apache.oodt.cas.cli.util.ParsedArg;
>
> /**
> @@ -31,6 +31,6 @@ import org.apache.oodt.cas.cli.util.Pars
>  */
> public interface CmdLineParser {
>
> -   public List<ParsedArg> parse(String[] args) throws IOException;
> +   public List<ParsedArg> parse(String[] args) throws CmdLineParserException;
>
> }
>
> Modified: oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/parser/StdCmdLineParser.java
> URL: http://svn.apache.org/viewvc/oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/parser/StdCmdLineParser.java?rev=1200439&r1=1200438&r2=1200439&view=diff
> ==============================================================================
> --- oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/parser/StdCmdLineParser.java (original)
> +++ oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/parser/StdCmdLineParser.java Thu Nov 10 17:27:28 2011
> @@ -33,10 +33,10 @@
> package org.apache.oodt.cas.cli.parser;
>
> //JDK imports
> -import java.io.IOException;
> import java.util.List;
>
> //OODT imports
> +import org.apache.oodt.cas.cli.exception.CmdLineParserException;
> import org.apache.oodt.cas.cli.util.ParsedArg;
>
> //Google imports
> @@ -51,7 +51,7 @@ import com.google.common.collect.Lists;
>  */
> public class StdCmdLineParser implements CmdLineParser {
>
> -   public List<ParsedArg> parse(String[] args) throws IOException {
> +   public List<ParsedArg> parse(String[] args) throws CmdLineParserException {
>       List<ParsedArg> parsedArgs = Lists.newArrayList();
>
>       for (String arg : args) {
>
> Added: oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/presenter/CmdLinePresenter.java
> URL: http://svn.apache.org/viewvc/oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/presenter/CmdLinePresenter.java?rev=1200439&view=auto
> ==============================================================================
> --- oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/presenter/CmdLinePresenter.java (added)
> +++ oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/presenter/CmdLinePresenter.java Thu Nov 10 17:27:28 2011
> @@ -0,0 +1,34 @@
> +/*
> + * 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.oodt.cas.cli.presenter;
> +
> +/**
> + * Presenter to displaying help messages generated by help printers.
> + *
> + * @author bfoster (Brian Foster)
> + */
> +public interface CmdLinePresenter {
> +
> +   public void presentOptionHelp(String optionHelpMessage);
> +
> +   public void presentActionHelp(String actionHelpMessage);
> +
> +   public void presentActionsHelp(String actionsHelpMessage);
> +
> +   public void presentErrorMessage(String errorMessage);
> +
> +}
>
> Propchange: oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/presenter/CmdLinePresenter.java
> ------------------------------------------------------------------------------
>    svn:mime-type = text/plain
>
> Added: oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/presenter/StdCmdLinePresenter.java
> URL: http://svn.apache.org/viewvc/oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/presenter/StdCmdLinePresenter.java?rev=1200439&view=auto
> ==============================================================================
> --- oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/presenter/StdCmdLinePresenter.java (added)
> +++ oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/presenter/StdCmdLinePresenter.java Thu Nov 10 17:27:28 2011
> @@ -0,0 +1,65 @@
> +/*
> + * 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.oodt.cas.cli.presenter;
> +
> +//JDK imports
> +import java.io.OutputStream;
> +import java.io.PrintStream;
> +
> +//Apache imports
> +import org.apache.commons.lang.Validate;
> +
> +/**
> + * Standard help presenter which sends help messages to {@link System.out}.
> + *
> + * @author bfoster (Brian Foster)
> + */
> +public class StdCmdLinePresenter implements
> +      CmdLinePresenter {
> +
> +   private PrintStream ps;
> +
> +   public StdCmdLinePresenter() {
> +      this(System.out);
> +   }
> +
> +   public StdCmdLinePresenter(OutputStream os) {
> +      Validate.notNull(os);
> +
> +      ps = new PrintStream(os);
> +   }
> +
> +   @Override
> +   public void presentOptionHelp(String optionHelpMessage) {
> +      ps.println(optionHelpMessage);
> +   }
> +
> +   @Override
> +   public void presentActionHelp(String actionHelpMessage) {
> +      ps.println(actionHelpMessage);
> +   }
> +
> +   @Override
> +   public void presentActionsHelp(String actionsHelpMessage) {
> +      ps.println(actionsHelpMessage);
> +   }
> +
> +   @Override
> +   public void presentErrorMessage(String errorMessage) {
> +      ps.println(errorMessage);
> +   }
> +}
>
> Propchange: oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/presenter/StdCmdLinePresenter.java
> ------------------------------------------------------------------------------
>    svn:mime-type = text/plain
>
> Added: oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/printer/CmdLinePrinter.java
> URL: http://svn.apache.org/viewvc/oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/printer/CmdLinePrinter.java?rev=1200439&view=auto
> ==============================================================================
> --- oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/printer/CmdLinePrinter.java (added)
> +++ oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/printer/CmdLinePrinter.java Thu Nov 10 17:27:28 2011
> @@ -0,0 +1,86 @@
> +/*
> + * 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.oodt.cas.cli.printer;
> +
> +//JDK imports
> +import java.util.List;
> +import java.util.Set;
> +
> +//OODT imports
> +import org.apache.oodt.cas.cli.action.CmdLineAction;
> +import org.apache.oodt.cas.cli.option.CmdLineOption;
> +import org.apache.oodt.cas.cli.option.validator.CmdLineOptionValidator.Result;
> +
> +/**
> + * Printer which is responsible for generating a {@link String} representation
> + * of help, validation errors, and missing required options errors.
> + *
> + * @author bfoster (Brian Foster)
> + */
> +public interface CmdLinePrinter {
> +
> +   /**
> +    * Should generate help message for action specified by
> +    * {@link #CmdLineArgs.getSpecifiedAction()}.
> +    *
> +    * @param action
> +    *           {@link CmdLineAction} for which help will be generate
> +    * @param options
> +    *           Supported {@link CmdLineOption}s
> +    * @return Help message for specified action
> +    */
> +   public String printActionHelp(CmdLineAction action, Set<CmdLineOption> options);
> +
> +   /**
> +    * Generates help messages given {@link CmdLineAction}s.
> +    *
> +    * @param actions
> +    *           {@link CmdLineAction}s to print help for
> +    * @return Help message for given {@link CmdLineAction}s
> +    */
> +   public String printActionsHelp(Set<CmdLineAction> actions);
> +
> +   /**
> +    * Generates help message for given {@link CmdLineOption}s.
> +    *
> +    * @param options
> +    *           {@link CmdLineOption}s for which help message will be generated
> +    * @return Help message for given {@link CmdLineOption}s
> +    */
> +   public String printOptionsHelp(Set<CmdLineOption> options);
> +
> +   /**
> +    * Generate validation error message for results of failed validations.
> +    *
> +    * @param results
> +    *           {@link List} of FAILed validations
> +    * @return Generated validation error message
> +    */
> +   public String printOptionValidationErrors(List<Result> results);
> +
> +   /**
> +    * Generates missing required options error message from given
> +    * {@link CmdLineOption}s which where required and not specified.
> +    *
> +    * @param missingOptions
> +    *           {@link Set} of {@link CmdLineOption}s which where required and
> +    *           not set.
> +    * @return Generated missing required options error message.
> +    */
> +   public String printRequiredOptionsMissingError(
> +         Set<CmdLineOption> missingOptions);
> +}
>
> Propchange: oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/printer/CmdLinePrinter.java
> ------------------------------------------------------------------------------
>    svn:mime-type = text/plain
>
> Added: oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/printer/StdCmdLinePrinter.java
> URL: http://svn.apache.org/viewvc/oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/printer/StdCmdLinePrinter.java?rev=1200439&view=auto
> ==============================================================================
> --- oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/printer/StdCmdLinePrinter.java (added)
> +++ oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/printer/StdCmdLinePrinter.java Thu Nov 10 17:27:28 2011
> @@ -0,0 +1,262 @@
> +/*
> + * 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.oodt.cas.cli.printer;
> +
> +//OODT static imports
> +import static org.apache.oodt.cas.cli.util.CmdLineUtils.asGroupOption;
> +import static org.apache.oodt.cas.cli.util.CmdLineUtils.determineOptional;
> +import static org.apache.oodt.cas.cli.util.CmdLineUtils.determineRequired;
> +import static org.apache.oodt.cas.cli.util.CmdLineUtils.determineRequiredSubOptions;
> +import static org.apache.oodt.cas.cli.util.CmdLineUtils.getFormattedString;
> +import static org.apache.oodt.cas.cli.util.CmdLineUtils.isGroupOption;
> +import static org.apache.oodt.cas.cli.util.CmdLineUtils.sortOptionsByRequiredStatus;
> +
> +//JDK imports
> +import java.util.List;
> +import java.util.Set;
> +
> +//Apache imports
> +import org.apache.commons.lang.StringUtils;
> +
> +//OODT imports
> +import org.apache.oodt.cas.cli.action.CmdLineAction;
> +import org.apache.oodt.cas.cli.option.ActionCmdLineOption;
> +import org.apache.oodt.cas.cli.option.AdvancedCmdLineOption;
> +import org.apache.oodt.cas.cli.option.CmdLineOption;
> +import org.apache.oodt.cas.cli.option.GroupCmdLineOption;
> +import org.apache.oodt.cas.cli.option.GroupSubOption;
> +import org.apache.oodt.cas.cli.option.validator.CmdLineOptionValidator.Result;
> +import org.apache.oodt.cas.cli.util.CmdLineUtils;
> +
> +import com.google.common.collect.Lists;
> +
> +/**
> + * Standard {@link CmdLinePrinter}.
> + *
> + * @author bfoster (Brian Foster)
> + */
> +public class StdCmdLinePrinter implements CmdLinePrinter {
> +
> +   @Override
> +   public String printActionHelp(CmdLineAction action,
> +         Set<CmdLineOption> options) {
> +      StringBuffer sb = new StringBuffer("");
> +      sb.append(getHeader(action)).append("\n");
> +
> +      sb.append(getRequiredSubHeader()).append("\n");
> +      Set<CmdLineOption> requiredOptions = determineRequired(action, options);
> +      List<CmdLineOption> sortedRequiredOptions = sortOptionsByRequiredStatus(requiredOptions);
> +      for (CmdLineOption option : sortedRequiredOptions) {
> +         sb.append(getRequiredOptionHelp(action, option)).append("\n");
> +      }
> +
> +      sb.append(getOptionalSubHeader()).append("\n");
> +      Set<CmdLineOption> optionalOptions = determineOptional(action, options);
> +      List<CmdLineOption> sortedOptionalOptions = sortOptionsByRequiredStatus(optionalOptions);
> +      for (CmdLineOption option : sortedOptionalOptions) {
> +         sb.append(getOptionalOptionHelp(action, option)).append("\n");
> +      }
> +
> +      sb.append(getFooter(action)).append("\n");
> +      return sb.toString();
> +   }
> +
> +   protected String getHeader(CmdLineAction action) {
> +      return "Action Help for '" + action.getName() + "'";
> +   }
> +
> +   protected String getRequiredSubHeader() {
> +      return " - Required:";
> +   }
> +
> +   protected String getRequiredOptionHelp(CmdLineAction action,
> +         CmdLineOption option) {
> +      if (option instanceof GroupCmdLineOption) {
> +         return getGroupHelp(action, (GroupCmdLineOption) option, "    ");
> +      } else {
> +         return getOptionHelp(action, option, "    ");
> +      }
> +   }
> +
> +   protected String getOptionalSubHeader() {
> +      return " - Optional:";
> +   }
> +
> +   protected String getOptionalOptionHelp(CmdLineAction action,
> +         CmdLineOption option) {
> +      if (option instanceof GroupCmdLineOption) {
> +         return getGroupHelp(action, (GroupCmdLineOption) option, "    ");
> +      } else {
> +         return getOptionHelp(action, option, "    ");
> +      }
> +   }
> +
> +   protected String getFooter(CmdLineAction action) {
> +      return "";
> +   }
> +
> +   protected String getOptionHelp(CmdLineAction action, CmdLineOption option,
> +         String indent) {
> +      String argDescription = null;
> +      if (option instanceof AdvancedCmdLineOption) {
> +         argDescription = ((AdvancedCmdLineOption) option).getHandler()
> +               .getArgDescription(action, option);
> +      }
> +
> +      String argHelp = null;
> +      if (option instanceof ActionCmdLineOption && option.hasArgs()) {
> +         argHelp = action.getName();
> +      } else {
> +         argHelp = (option.hasArgs() ? " <"
> +               + (argDescription != null ? argDescription : option
> +                     .getArgsDescription()) + ">" : "");
> +      }
> +      return indent + "-" + option.getShortOption() + " [--"
> +            + option.getLongOption() + "]" + argHelp;
> +   }
> +
> +   protected String getGroupHelp(CmdLineAction action,
> +         GroupCmdLineOption option, String indent) {
> +      String helpString = getOptionHelp(action, option, indent) + "\n";
> +      Set<CmdLineOption> subOptions = determineRequiredSubOptions(action,
> +            (GroupCmdLineOption) option);
> +      if (subOptions.isEmpty()) {
> +         if (!option.getSubOptions().isEmpty()) {
> +            helpString += indent + "  One of:";
> +            for (GroupSubOption subOption : option.getSubOptions()) {
> +               helpString += "\n"
> +                     + getOptionHelp(action, subOption.getOption(), "   "
> +                           + indent);
> +            }
> +         }
> +      } else {
> +         for (CmdLineOption subOption : subOptions) {
> +            if (subOption instanceof GroupCmdLineOption) {
> +               helpString += getGroupHelp(action,
> +                     (GroupCmdLineOption) subOption, "  " + indent);
> +            } else {
> +               helpString += getOptionHelp(action, subOption, "  " + indent);
> +            }
> +         }
> +      }
> +      return helpString;
> +   }
> +
> +   @Override
> +   public String printActionsHelp(Set<CmdLineAction> actions) {
> +      StringBuffer sb = new StringBuffer("");
> +      sb.append("Actions:").append("\n");
> +      for (CmdLineAction action : actions) {
> +         sb.append("  Action:").append("\n");
> +         sb.append("    Name: ").append(action.getName()).append("\n");
> +         sb.append("    Description: ").append(action.getDescription())
> +               .append("\n").append("\n");
> +      }
> +      return sb.toString();
> +   }
> +
> +   @Override
> +   public String printOptionsHelp(Set<CmdLineOption> options) {
> +      StringBuffer sb = new StringBuffer("");
> +      List<CmdLineOption> sortedOptions = sortOptionsByRequiredStatus(options);
> +      sb.append(getHeader()).append("\n");
> +      for (CmdLineOption option : sortedOptions) {
> +         sb.append(getOptionHelp(option, "")).append("\n");
> +      }
> +      sb.append(getFooter()).append("\n");
> +      return sb.toString();
> +   }
> +
> +   protected String getHeader() {
> +      StringBuffer sb = new StringBuffer("");
> +      sb.append("-----------------------------------------------------------------------------------------------------------------\n");
> +      sb.append("|" + StringUtils.rightPad(" Short", 7) + "|"
> +            + StringUtils.rightPad(" Long", 50) + "| Description\n");
> +      sb.append("-----------------------------------------------------------------------------------------------------------------\n");
> +      return sb.toString();
> +   }
> +
> +   protected String getOptionHelp(CmdLineOption option, String indent) {
> +      String argName = option.hasArgs() ? " <" + option.getArgsDescription()
> +            + ">" : "";
> +      String optionUsage = indent + "-"
> +            + StringUtils.rightPad(option.getShortOption() + ",", 7) + "--"
> +            + StringUtils.rightPad((option.getLongOption() + argName), 49 - indent.length())
> +            + option.getDescription();
> +
> +      optionUsage = " " + optionUsage;
> +
> +      if (!option.getRequirementRules().isEmpty()) {
> +         optionUsage += "\n"
> +               + getFormattedString("Requirement Rules:", 62, 113)
> +               + getFormattedString(option.getRequirementRules().toString(),
> +                     63, 113);
> +      }
> +
> +      if (option instanceof AdvancedCmdLineOption) {
> +         if (((AdvancedCmdLineOption) option).hasHandler()) {
> +            optionUsage += "\n"
> +                  + getFormattedString("Handler:", 62, 113)
> +                  + getFormattedString(((AdvancedCmdLineOption) option)
> +                        .getHandler().getHelp(option), 63, 113);
> +         }
> +      } else if (isGroupOption(option)) {
> +         GroupCmdLineOption groupOption = asGroupOption(option);
> +         optionUsage += "\n";
> +         optionUsage += "   SubOptions:\n";
> +         optionUsage += "   > Required:\n";
> +
> +         List<CmdLineOption> optionalOptions = Lists.newArrayList();
> +         for (GroupSubOption subOption : groupOption.getSubOptions()) {
> +            if (subOption.isRequired()) {
> +               optionUsage += getOptionHelp(subOption.getOption(), "     ");
> +            } else {
> +               optionalOptions.add(subOption.getOption());
> +            }
> +         }
> +         optionUsage += "   > Optional:\n";
> +         for (CmdLineOption optionalOption : optionalOptions) {
> +            optionUsage += getOptionHelp(optionalOption, "     ");
> +         }
> +      }
> +
> +      return optionUsage;
> +   }
> +
> +   protected String getFooter() {
> +      return "-----------------------------------------------------------------------------------------------------------------";
> +   }
> +
> +   @Override
> +   public String printOptionValidationErrors(List<Result> results) {
> +      StringBuffer sb = new StringBuffer("Validation Failures:");
> +      for (Result result : results) {
> +         sb.append(" - ").append(result.getMessage()).append("\n");
> +      }
> +      return sb.toString();
> +   }
> +
> +   @Override
> +   public String printRequiredOptionsMissingError(
> +         Set<CmdLineOption> missingOptions) {
> +      StringBuffer sb = new StringBuffer("Missing required options:\n");
> +      for (CmdLineOption option : missingOptions) {
> +         sb.append(" - ").append(option.toString()).append("\n");
> +      }
> +      return sb.toString();
> +   }
> +}
>
> Propchange: oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/printer/StdCmdLinePrinter.java
> ------------------------------------------------------------------------------
>    svn:mime-type = text/plain
>
> Modified: oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/util/CmdLineIterable.java
> URL: http://svn.apache.org/viewvc/oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/util/CmdLineIterable.java?rev=1200439&r1=1200438&r2=1200439&view=diff
> ==============================================================================
> --- oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/util/CmdLineIterable.java (original)
> +++ oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/util/CmdLineIterable.java Thu Nov 10 17:27:28 2011
> @@ -39,7 +39,7 @@ public class CmdLineIterable<T> implemen
>    public CmdLineIterable(List<T> args) {
>       Validate.notNull(args);
>
> -      curIndex = 0;
> +      curIndex = -1;
>       this.args = args;
>    }
>
> @@ -56,11 +56,15 @@ public class CmdLineIterable<T> implemen
>    }
>
>    public void incrementIndex() {
> -      curIndex++;
> +      if (curIndex < args.size()) {
> +         curIndex++;
> +      }
>    }
>
>    public void descrementIndex() {
> -      curIndex--;
> +      if (curIndex > 0) {
> +         curIndex--;
> +      }
>    }
>
>    public T incrementAndGet() {
> @@ -83,11 +87,13 @@ public class CmdLineIterable<T> implemen
>    }
>
>    public boolean hasNext() {
> -      return curIndex < args.size();
> +      return curIndex + 1 < args.size();
>    }
>
>    public T getCurrentArg() {
> -      if (hasNext()) {
> +      if (curIndex == -1) {
> +         return incrementAndGet();
> +      } else if (curIndex > -1 && curIndex < args.size()) {
>          return args.get(curIndex);
>       } else {
>          return null;
> @@ -103,9 +109,9 @@ public class CmdLineIterable<T> implemen
>
>          public T next() {
>             if (!hasNext()) {
> -               throw new IndexOutOfBoundsException(curIndex + "");
> +               throw new IndexOutOfBoundsException((curIndex + 1) + "");
>             }
> -            return getAndIncrement();
> +            return incrementAndGet();
>          }
>
>          public void remove() {
>
> Modified: oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/util/CmdLineUtils.java
> URL: http://svn.apache.org/viewvc/oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/util/CmdLineUtils.java?rev=1200439&r1=1200438&r2=1200439&view=diff
> ==============================================================================
> --- oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/util/CmdLineUtils.java (original)
> +++ oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/util/CmdLineUtils.java Thu Nov 10 17:27:28 2011
> @@ -255,10 +255,21 @@ public class CmdLineUtils {
>       Validate.notNull(optionName);
>       Validate.notNull(options);
>
> -      for (CmdLineOption option : options)
> +      for (CmdLineOption option : options) {
>          if (option.getLongOption().equals(optionName)
> -               || option.getShortOption().equals(optionName))
> +               || option.getShortOption().equals(optionName)) {
>             return option;
> +         } else if (isGroupOption(option)) {
> +            Set<CmdLineOption> subOptions = Sets.newHashSet();
> +            for (GroupSubOption subOption : asGroupOption(option).getSubOptions()) {
> +               subOptions.add(subOption.getOption());
> +            }
> +            CmdLineOption foundOption = getOptionByName(optionName, subOptions);
> +            if (foundOption != null) {
> +               return foundOption;
> +            }
> +         }
> +      }
>       return null;
>    }
>
> @@ -524,18 +535,57 @@ public class CmdLineUtils {
>     *           {@link ActionCmdLineOption}
>     * @return The found {@link ActionCmdLineOption}, or null if not found
>     */
> -   public static ActionCmdLineOption findActionOption(Set<CmdLineOption> options) {
> +   public static ActionCmdLineOption findFirstActionOption(
> +         Set<CmdLineOption> options) {
>       Validate.notNull(options);
>
>       for (CmdLineOption option : options) {
>          if (isActionOption(option)) {
>             return (ActionCmdLineOption) option;
> +         } else if (isGroupOption(option)) {
> +            GroupCmdLineOption groupOption = (GroupCmdLineOption) option;
> +            Set<CmdLineOption> subOptions = Sets.newHashSet();
> +            for (GroupSubOption subOption : groupOption.getSubOptions()) {
> +               subOptions.add(subOption.getOption());
> +            }
> +            ActionCmdLineOption foundOption = findFirstActionOption(subOptions);
> +            if (foundOption != null) {
> +               return foundOption;
> +            }
>          }
>       }
>       return null;
>    }
>
>    /**
> +    * Finds all {@link CmdLineOption}s that are {@link ActionCmdLineOption}s.
> +    *
> +    * @param options
> +    *           The {@link CmdLineOption}s to look through for
> +    *           {@link ActionCmdLineOption}s
> +    * @return All {@link ActionCmdLineOption}s found
> +    */
> +   public static List<ActionCmdLineOption> findActionOptions(
> +         Set<CmdLineOption> options) {
> +      Validate.notNull(options);
> +
> +      List<ActionCmdLineOption> actionOptions = Lists.newArrayList();
> +      for (CmdLineOption option : options) {
> +         if (isActionOption(option)) {
> +            actionOptions.add((ActionCmdLineOption) option);
> +         } else if (isGroupOption(option)) {
> +            GroupCmdLineOption groupOption = (GroupCmdLineOption) option;
> +            Set<CmdLineOption> subOptions = Sets.newHashSet();
> +            for (GroupSubOption subOption : groupOption.getSubOptions()) {
> +               subOptions.add(subOption.getOption());
> +            }
> +            actionOptions.addAll(findActionOptions(subOptions));
> +         }
> +      }
> +      return actionOptions;
> +   }
> +
> +   /**
>     * Find {@link ActionCmdLineOption} in {@link Set} of {@link CmdLineOption}s.
>     *
>     * @param options
> @@ -724,30 +774,46 @@ public class CmdLineUtils {
>     *
>     * @param option
>     *           The {@link CmdLineOptionInstance} to be validated
> -    * @return True if {@link CmdLineOptionInstance} passed validation, false
> -    *         otherwise
> +    * @return {@link CmdLineOptionValidator.Result}s from running
> +    *         {@link CmdLineOptionValidator}s.
>     */
> -   public static boolean validate(CmdLineOptionInstance option) {
> +   public static List<CmdLineOptionValidator.Result> validate(
> +         CmdLineOptionInstance option) {
>       Validate.notNull(option);
>
> +      List<CmdLineOptionValidator.Result> results = Lists.newArrayList();
>       if (option.isValidatable()) {
>          for (CmdLineOptionValidator validator : ((ValidatableCmdLineOption) option
>                .getOption()).getValidators()) {
> -            if (!validator.validate(option)) {
> -               return false;
> -            }
> +            results.add(validator.validate(option));
>          }
>       }
>
>       if (option.isGroup()) {
>          for (CmdLineOptionInstance subOption : option.getSubOptions()) {
> -            if (!validate(subOption)) {
> -               return false;
> -            }
> +            results.addAll(validate(subOption));
>          }
>       }
> +      return results;
> +   }
>
> -      return true;
> +   /**
> +    * Finds the {@link CmdLineOptionValidator.Result}s with grade of FAIL.
> +    *
> +    * @param results
> +    *           The {@link CmdLineOptionValidator.Result}s which are checked if
> +    *           they have a failing grade.
> +    * @return {@link CmdLineOptionValidator.Result}s with grade of FAIL.
> +    */
> +   public static List<CmdLineOptionValidator.Result> determineFailedValidation(
> +         List<CmdLineOptionValidator.Result> results) {
> +      List<CmdLineOptionValidator.Result> failedResults = Lists.newArrayList();
> +      for (CmdLineOptionValidator.Result result : results) {
> +         if (result.getGrade().equals(CmdLineOptionValidator.Result.Grade.FAIL)) {
> +            failedResults.add(result);
> +         }
> +      }
> +      return failedResults;
>    }
>
>    /**
>
>


++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Chris Mattmann, Ph.D.
Senior Computer Scientist
NASA Jet Propulsion Laboratory Pasadena, CA 91109 USA
Office: 171-266B, Mailstop: 171-246
Email: chris.a.mattmann@nasa.gov
WWW:   http://sunset.usc.edu/~mattmann/
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Adjunct Assistant Professor, Computer Science Department
University of Southern California, Los Angeles, CA 90089 USA
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++