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/10/31 02:01:20 UTC
svn commit: r1195292 [1/4] - in /oodt/branches/cas-cl: ./
src/main/java/org/apache/oodt/cas/cl/
src/main/java/org/apache/oodt/cas/cl/action/
src/main/java/org/apache/oodt/cas/cl/action/store/
src/main/java/org/apache/oodt/cas/cl/action/store/spring/ sr...
Author: bfoster
Date: Mon Oct 31 01:01:18 2011
New Revision: 1195292
URL: http://svn.apache.org/viewvc?rev=1195292&view=rev
Log:
- formatting changes
Modified:
oodt/branches/cas-cl/pom.xml
oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/CmdLineArgs.java
oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/CmdLineUtility.java
oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/action/CmdLineAction.java
oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/action/PrintMessageAction.java
oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/action/store/CmdLineActionStore.java
oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/action/store/CmdLineActionStoreFactory.java
oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/action/store/spring/SpringCmdLineActionStore.java
oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/action/store/spring/SpringCmdLineActionStoreFactory.java
oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/action/store/spring/SpringSetContextInjectionType.java
oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/help/OptionHelpException.java
oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/help/presenter/CmdLineOptionHelpPresenter.java
oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/help/presenter/StdCmdLineOptionHelpPresenter.java
oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/help/printer/CmdLineActionHelpPrinter.java
oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/help/printer/CmdLineActionsHelpPrinter.java
oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/help/printer/CmdLineOptionsHelpPrinter.java
oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/help/printer/StdCmdLineActionHelpPrinter.java
oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/help/printer/StdCmdLineActionsHelpPrinter.java
oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/help/printer/StdCmdLineOptionsHelpPrinter.java
oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/ActionCmdLineOption.java
oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/AdvancedCmdLineOption.java
oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/CmdLineOption.java
oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/CmdLineOptionInstance.java
oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/GroupCmdLineOption.java
oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/HandleableCmdLineOption.java
oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/HelpCmdLineOption.java
oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/PrintSupportedActionsCmdLineOption.java
oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/SimpleCmdLineOption.java
oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/ValidatableCmdLineOption.java
oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/handler/ApplyToAction.java
oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/handler/ApplyToActionHandler.java
oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/handler/CmdLineOptionHandler.java
oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/require/ActionDependencyRule.java
oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/require/RequirementRule.java
oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/store/CmdLineOptionStore.java
oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/store/CmdLineOptionStoreFactory.java
oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/store/spring/SpringCmdLineOptionStore.java
oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/store/spring/SpringCmdLineOptionStoreFactory.java
oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/validator/AllowedArgsCmdLineOptionValidator.java
oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/validator/ArgRegExpCmdLineOptionValidator.java
oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/validator/ClassExistsCmdLineOptionValidator.java
oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/validator/CmdLineOptionValidator.java
oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/validator/FileExistCmdLineOptionValidator.java
oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/validator/NoRestrictionsCmdLineOptionValidator.java
oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/parser/CmdLineOptionParser.java
oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/parser/StdCmdLineOptionParser.java
oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/util/Args.java
oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/util/CmdLineUtils.java
oodt/branches/cas-cl/src/test/org/apache/oodt/cas/cl/TestCmdLineArgs.java
oodt/branches/cas-cl/src/test/org/apache/oodt/cas/cl/action/store/spring/TestSpringCmdLineActionStore.java
oodt/branches/cas-cl/src/test/org/apache/oodt/cas/cl/option/handler/TestApplyToAction.java
oodt/branches/cas-cl/src/test/org/apache/oodt/cas/cl/option/handler/TestApplyToActionHandler.java
oodt/branches/cas-cl/src/test/org/apache/oodt/cas/cl/option/require/TestActionDependencyRule.java
oodt/branches/cas-cl/src/test/org/apache/oodt/cas/cl/option/store/spring/TestSpringCmdLineOptionStore.java
oodt/branches/cas-cl/src/test/org/apache/oodt/cas/cl/option/validator/TestAllowedArgsCmdLineOptionValidator.java
oodt/branches/cas-cl/src/test/org/apache/oodt/cas/cl/option/validator/TestArgRegExpCmdLineOptionValidator.java
oodt/branches/cas-cl/src/test/org/apache/oodt/cas/cl/option/validator/TestClassExistsCmdLineOptionValidator.java
oodt/branches/cas-cl/src/test/org/apache/oodt/cas/cl/option/validator/TestFileExistCmdLineOptionValidator.java
oodt/branches/cas-cl/src/test/org/apache/oodt/cas/cl/option/validator/TestNoRestrictionsCmdLineOptionValidator.java
oodt/branches/cas-cl/src/test/org/apache/oodt/cas/cl/parser/TestStdCmdLineOptionParser.java
oodt/branches/cas-cl/src/test/org/apache/oodt/cas/cl/test/util/TestOutputStream.java
oodt/branches/cas-cl/src/test/org/apache/oodt/cas/cl/test/util/TestSetContextInjectTypeAction.java
oodt/branches/cas-cl/src/test/org/apache/oodt/cas/cl/test/util/TestUtils.java
oodt/branches/cas-cl/src/test/org/apache/oodt/cas/cl/util/TestArgs.java
oodt/branches/cas-cl/src/test/org/apache/oodt/cas/cl/util/TestCmdLineUtils.java
oodt/branches/cas-cl/src/testdata/cmd-line-actions.xml
oodt/branches/cas-cl/src/testdata/cmd-line-options.xml
Modified: oodt/branches/cas-cl/pom.xml
URL: http://svn.apache.org/viewvc/oodt/branches/cas-cl/pom.xml?rev=1195292&r1=1195291&r2=1195292&view=diff
==============================================================================
--- oodt/branches/cas-cl/pom.xml (original)
+++ oodt/branches/cas-cl/pom.xml Mon Oct 31 01:01:18 2011
@@ -67,9 +67,9 @@
<version>2.0.8</version>
</dependency>
<dependency>
- <groupId>com.google.guava</groupId>
- <artifactId>guava</artifactId>
- <version>10.0.1</version>
+ <groupId>com.google.guava</groupId>
+ <artifactId>guava</artifactId>
+ <version>10.0.1</version>
</dependency>
<dependency>
<groupId>junit</groupId>
Modified: oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/CmdLineArgs.java
URL: http://svn.apache.org/viewvc/oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/CmdLineArgs.java?rev=1195292&r1=1195291&r2=1195292&view=diff
==============================================================================
--- oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/CmdLineArgs.java (original)
+++ oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/CmdLineArgs.java Mon Oct 31 01:01:18 2011
@@ -46,148 +46,149 @@ import org.apache.oodt.cas.cl.option.Pri
*/
public class CmdLineArgs {
- private CmdLineAction specifiedAction;
- private Set<CmdLineAction> supportedActions;
+ private CmdLineAction specifiedAction;
+ private Set<CmdLineAction> supportedActions;
- private HelpCmdLineOption helpOption;
- private CmdLineOptionInstance helpOptionInst;
- private ActionCmdLineOption actionOption;
- private CmdLineOptionInstance actionOptionInst;
- private PrintSupportedActionsCmdLineOption psaOption;
- private CmdLineOptionInstance psaOptionInst;
- private Set<CmdLineOption> supportedOptions;
- private Set<CmdLineOption> customSupportedOptions;
- private Set<CmdLineOptionInstance> specifiedOptions;
- private Set<CmdLineOptionInstance> customSpecifiedOptions;
-
- /* package */ CmdLineArgs(Set<CmdLineAction> supportedActions,
- Set<CmdLineOption> supportedOptions,
- Set<CmdLineOptionInstance> specifiedOptions) {
- Validate.notNull(supportedActions);
- Validate.notNull(supportedOptions);
- Validate.notNull(specifiedOptions);
-
- helpOption = findHelpOption(supportedOptions);
- helpOptionInst = findSpecifiedOption(helpOption, specifiedOptions);
- actionOption = findActionOption(supportedOptions);
- actionOptionInst = findSpecifiedOption(actionOption, specifiedOptions);
- psaOption = findPrintSupportedActionsOption(supportedOptions);
- psaOptionInst = findSpecifiedOption(psaOption, specifiedOptions);
-
- this.supportedOptions = new HashSet<CmdLineOption>(supportedOptions);
-
- customSupportedOptions = new HashSet<CmdLineOption>(supportedOptions);
- customSupportedOptions.remove(helpOption);
- customSupportedOptions.remove(actionOption);
- customSupportedOptions.remove(psaOption);
-
- this.specifiedOptions = new HashSet<CmdLineOptionInstance>(specifiedOptions);
-
- customSpecifiedOptions = new HashSet<CmdLineOptionInstance>(
- specifiedOptions);
- if (helpOptionInst != null) {
- customSpecifiedOptions.remove(helpOptionInst);
- }
- if (actionOptionInst != null) {
- customSpecifiedOptions.remove(actionOptionInst);
- }
- if (psaOptionInst != null) {
- customSpecifiedOptions.remove(psaOptionInst);
- }
-
- this.supportedActions = supportedActions;
- if (actionOptionInst != null) {
- specifiedAction = findAction(actionOptionInst, supportedActions);
- }
- }
-
- /**
- * @return The {@link HelpCmdLineOption}
- */
- public HelpCmdLineOption getHelpOption() {
- return helpOption;
- }
-
- /**
- * @return The {@link CmdLineOptionInstance} which is the specified
- * {@link HelpCmdLineOption}, or null if it was not specified
- */
- public CmdLineOptionInstance getHelpOptionInst() {
- return helpOptionInst;
- }
-
- /**
- * @return The {@link ActionCmdLineOption}
- */
- public ActionCmdLineOption getActionOption() {
- return actionOption;
- }
-
- /**
- * @return The {@link CmdLineOptionInstance} which is the specified
- * {@link ActionCmdLineOption}, or null if it was not specified
- */
- public CmdLineOptionInstance getActionOptionInst() {
- return actionOptionInst;
- }
-
- /**
- * @return The {@link PrintSupportedActionsCmdLineOption}
- */
- public PrintSupportedActionsCmdLineOption getPrintSupportedActionsOption() {
- return psaOption;
- }
-
- /**
- * @return The {@link CmdLineOptionInstance} which is the specified
- * {@link PrintSupportedActionsCmdLineOption}, or null if it was not
- * specified
- */
- public CmdLineOptionInstance getPrintSupportedActionsOptionInst() {
- return psaOptionInst;
- }
-
- /**
- * @return All supported {@link CmdLineOption}s
- */
- public Set<CmdLineOption> getSupportedOptions() {
- return supportedOptions;
- }
-
- /**
- * @return Supported {@link CmdLineOption}s less Help, Action,
- * PrintSupportActions options
- */
- public Set<CmdLineOption> getCustomSupportedOptions() {
- return customSupportedOptions;
- }
-
- /**
- * @return All specified {@link CmdLineOptionInstance}s
- */
- public Set<CmdLineOptionInstance> getSpecifiedOptions() {
- return specifiedOptions;
- }
-
- /**
- * @return Specified {@link CmdLineOptionInstance}s less Help, Action,
- * PrintSupportedActions option instances
- */
- public Set<CmdLineOptionInstance> getCustomSpecifiedOptions() {
- return customSpecifiedOptions;
- }
-
- /**
- * @return All supported {@link CmdLineAction}s
- */
- public Set<CmdLineAction> getSupportedActions() {
- return supportedActions;
- }
-
- /**
- * @return The {@link CmdLineAction} which was specified
- */
- public CmdLineAction getSpecifiedAction() {
- return specifiedAction;
- }
+ private HelpCmdLineOption helpOption;
+ private CmdLineOptionInstance helpOptionInst;
+ private ActionCmdLineOption actionOption;
+ private CmdLineOptionInstance actionOptionInst;
+ private PrintSupportedActionsCmdLineOption psaOption;
+ private CmdLineOptionInstance psaOptionInst;
+ private Set<CmdLineOption> supportedOptions;
+ private Set<CmdLineOption> customSupportedOptions;
+ private Set<CmdLineOptionInstance> specifiedOptions;
+ private Set<CmdLineOptionInstance> customSpecifiedOptions;
+
+ /* package */CmdLineArgs(Set<CmdLineAction> supportedActions,
+ Set<CmdLineOption> supportedOptions,
+ Set<CmdLineOptionInstance> specifiedOptions) {
+ Validate.notNull(supportedActions);
+ Validate.notNull(supportedOptions);
+ Validate.notNull(specifiedOptions);
+
+ helpOption = findHelpOption(supportedOptions);
+ helpOptionInst = findSpecifiedOption(helpOption, specifiedOptions);
+ actionOption = findActionOption(supportedOptions);
+ actionOptionInst = findSpecifiedOption(actionOption, specifiedOptions);
+ psaOption = findPrintSupportedActionsOption(supportedOptions);
+ psaOptionInst = findSpecifiedOption(psaOption, specifiedOptions);
+
+ this.supportedOptions = new HashSet<CmdLineOption>(supportedOptions);
+
+ customSupportedOptions = new HashSet<CmdLineOption>(supportedOptions);
+ customSupportedOptions.remove(helpOption);
+ customSupportedOptions.remove(actionOption);
+ customSupportedOptions.remove(psaOption);
+
+ this.specifiedOptions = new HashSet<CmdLineOptionInstance>(
+ specifiedOptions);
+
+ customSpecifiedOptions = new HashSet<CmdLineOptionInstance>(
+ specifiedOptions);
+ if (helpOptionInst != null) {
+ customSpecifiedOptions.remove(helpOptionInst);
+ }
+ if (actionOptionInst != null) {
+ customSpecifiedOptions.remove(actionOptionInst);
+ }
+ if (psaOptionInst != null) {
+ customSpecifiedOptions.remove(psaOptionInst);
+ }
+
+ this.supportedActions = supportedActions;
+ if (actionOptionInst != null) {
+ specifiedAction = findAction(actionOptionInst, supportedActions);
+ }
+ }
+
+ /**
+ * @return The {@link HelpCmdLineOption}
+ */
+ public HelpCmdLineOption getHelpOption() {
+ return helpOption;
+ }
+
+ /**
+ * @return The {@link CmdLineOptionInstance} which is the specified
+ * {@link HelpCmdLineOption}, or null if it was not specified
+ */
+ public CmdLineOptionInstance getHelpOptionInst() {
+ return helpOptionInst;
+ }
+
+ /**
+ * @return The {@link ActionCmdLineOption}
+ */
+ public ActionCmdLineOption getActionOption() {
+ return actionOption;
+ }
+
+ /**
+ * @return The {@link CmdLineOptionInstance} which is the specified
+ * {@link ActionCmdLineOption}, or null if it was not specified
+ */
+ public CmdLineOptionInstance getActionOptionInst() {
+ return actionOptionInst;
+ }
+
+ /**
+ * @return The {@link PrintSupportedActionsCmdLineOption}
+ */
+ public PrintSupportedActionsCmdLineOption getPrintSupportedActionsOption() {
+ return psaOption;
+ }
+
+ /**
+ * @return The {@link CmdLineOptionInstance} which is the specified
+ * {@link PrintSupportedActionsCmdLineOption}, or null if it was not
+ * specified
+ */
+ public CmdLineOptionInstance getPrintSupportedActionsOptionInst() {
+ return psaOptionInst;
+ }
+
+ /**
+ * @return All supported {@link CmdLineOption}s
+ */
+ public Set<CmdLineOption> getSupportedOptions() {
+ return supportedOptions;
+ }
+
+ /**
+ * @return Supported {@link CmdLineOption}s less Help, Action,
+ * PrintSupportActions options
+ */
+ public Set<CmdLineOption> getCustomSupportedOptions() {
+ return customSupportedOptions;
+ }
+
+ /**
+ * @return All specified {@link CmdLineOptionInstance}s
+ */
+ public Set<CmdLineOptionInstance> getSpecifiedOptions() {
+ return specifiedOptions;
+ }
+
+ /**
+ * @return Specified {@link CmdLineOptionInstance}s less Help, Action,
+ * PrintSupportedActions option instances
+ */
+ public Set<CmdLineOptionInstance> getCustomSpecifiedOptions() {
+ return customSpecifiedOptions;
+ }
+
+ /**
+ * @return All supported {@link CmdLineAction}s
+ */
+ public Set<CmdLineAction> getSupportedActions() {
+ return supportedActions;
+ }
+
+ /**
+ * @return The {@link CmdLineAction} which was specified
+ */
+ public CmdLineAction getSpecifiedAction() {
+ return specifiedAction;
+ }
}
Modified: oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/CmdLineUtility.java
URL: http://svn.apache.org/viewvc/oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/CmdLineUtility.java?rev=1195292&r1=1195291&r2=1195292&view=diff
==============================================================================
--- oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/CmdLineUtility.java (original)
+++ oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/CmdLineUtility.java Mon Oct 31 01:01:18 2011
@@ -52,245 +52,277 @@ import org.apache.oodt.cas.cl.util.Args;
import org.apache.oodt.cas.cl.util.CmdLineUtils;
/**
- * A highly configurable utility class which supports parsing and handling of
- * command line arguments via its action driven design. After parsing the
+ * A highly configurable utility class which supports parsing and handling of
+ * command line arguments via its action driven design. After parsing the
* command line arguments it will check for required arguments not specified,
- * validate the arguments, run the arguments handlers and then invoke the specified
- * action. It also supports print out help messages and printing supported actions.
- *
+ * validate the arguments, run the arguments handlers and then invoke the
+ * specified action. It also supports print out help messages and printing
+ * supported actions.
+ *
* @author bfoster (Brian Foster)
*/
public class CmdLineUtility {
- private CmdLineOptionParser parser;
- private CmdLineOptionStore optionStore;
- private CmdLineActionStore actionStore;
- private CmdLineOptionsHelpPrinter optionHelpPrinter;
- private CmdLineActionHelpPrinter actionHelpPrinter;
- private CmdLineActionsHelpPrinter actionsHelpPrinter;
- private CmdLineOptionHelpPresenter helpPresenter;
-
- public CmdLineUtility() {
- parser = new StdCmdLineOptionParser();
- optionStore = new SpringCmdLineOptionStoreFactory().createStore();
- actionStore = new SpringCmdLineActionStoreFactory().createStore();
- optionHelpPrinter = new StdCmdLineOptionsHelpPrinter();
- actionHelpPrinter = new StdCmdLineActionHelpPrinter();
- helpPresenter = new StdCmdLineOptionHelpPresenter();
- }
-
- public CmdLineOptionStore getOptionStore() {
- return optionStore;
- }
-
- public void setOptionStore(CmdLineOptionStore optionStore) {
- this.optionStore = optionStore;
- }
-
- public CmdLineActionStore getActionStore() {
- return actionStore;
- }
-
- public void setActionStore(CmdLineActionStore actionStore) {
- this.actionStore = actionStore;
- }
-
- public CmdLineOptionsHelpPrinter getOptionHelpPrinter() {
- return optionHelpPrinter;
- }
-
- public void setOptionHelpPrinter(CmdLineOptionsHelpPrinter optionHelpPrinter) {
- this.optionHelpPrinter = optionHelpPrinter;
- }
-
- public CmdLineActionHelpPrinter getActionHelpPrinter() {
- return actionHelpPrinter;
- }
-
- public void setActionHelpPrinter(CmdLineActionHelpPrinter actionHelpPrinter) {
- this.actionHelpPrinter = actionHelpPrinter;
- }
-
- public CmdLineActionsHelpPrinter getActionsHelpPrinter() {
- return actionsHelpPrinter;
- }
-
- public void setActionsHelpPrinter(CmdLineActionsHelpPrinter actionsHelpPrinter) {
- this.actionsHelpPrinter = actionsHelpPrinter;
- }
-
- public CmdLineOptionHelpPresenter getHelpPresenter() {
- return helpPresenter;
- }
-
- public void setHelpPresenter(CmdLineOptionHelpPresenter helpPresenter) {
- this.helpPresenter = helpPresenter;
- }
-
- public void printOptionHelp(CmdLineArgs cmdLineArgs) {
- helpPresenter.presentOptionHelp(optionHelpPrinter.printHelp(cmdLineArgs
- .getSupportedOptions()));
- }
-
- public void printActionHelp(CmdLineArgs cmdLineArgs) {
- Validate.notEmpty(cmdLineArgs.getHelpOptionInst().getValues());
-
- helpPresenter.presentActionHelp(actionHelpPrinter.printHelp(
- CmdLineUtils.findAction(cmdLineArgs.getHelpOptionInst().getValues()
- .get(0), cmdLineArgs.getSupportedActions()),
- cmdLineArgs.getCustomSupportedOptions()));
- }
-
- public void printActionsHelp(CmdLineArgs cmdLineArgs) {
- helpPresenter.presentActionsHelp(actionsHelpPrinter.printHelp(cmdLineArgs
- .getSupportedActions()));
- }
-
- /**
- * Parses given command line arguments, then checks for help and print supported actions
- * options, prints them out if found, otherwise performs execution on the arguments -
- * see execute(CmdLineArgs).
- *
- * @param args The who will be parsed and executed.
- * @throws IOException On error parsing or executing the args.
- */
- public void run(String[] args) throws IOException {
- CmdLineArgs cmdLineArgs = parse(args);
- if (!handleHelp(cmdLineArgs) && !handlePrintSupportedActions(cmdLineArgs)) {
- execute(cmdLineArgs);
- }
- }
-
- /**
- * Parses the given command line arguments and converts it to {@link CmdLineArgs}.
- *
- * @param args The command line arguments to parse.
- * @return The parsed command line arguments in {@link CmdLineArgs} form.
- * @throws IOException On error parsing command line arguments.
- */
- public CmdLineArgs parse(String[] args) throws IOException {
- Validate.notNull(parser);
- Validate.notNull(optionStore);
-
- // Load supported options.
- Set<CmdLineOption> validOptions = optionStore.loadSupportedOptions();
-
- // Insure help options is present if required.
- HelpCmdLineOption helpOption = findHelpOption(validOptions);
- if (helpOption == null) {
- validOptions.add(helpOption = new HelpCmdLineOption());
- }
-
- // Insure action options is present if required.
- ActionCmdLineOption actionOption = findActionOption(validOptions);
- if (actionOption == null) {
- validOptions.add(actionOption = new ActionCmdLineOption());
- }
-
- // Insure print supported actions option is present if required.
- PrintSupportedActionsCmdLineOption psaOption = CmdLineUtils.findPrintSupportedActionsOption(validOptions);
- if (psaOption == null) {
- validOptions.add(psaOption = new PrintSupportedActionsCmdLineOption());
- }
-
- // Parse command line arguments.
- return new CmdLineArgs(actionStore.loadSupportedActions(), validOptions, parser.parse(new Args(args), validOptions));
- }
-
- /**
- * Checks if help option was specified and if so prints out help.
- *
- * @param cmdLineArgs The {@link CmdLineArgs} which will be checked for help option
- * @return True if help was printed, false otherwise
- */
- public boolean handleHelp(CmdLineArgs cmdLineArgs) {
- if (cmdLineArgs.getHelpOptionInst() != null) {
- if (cmdLineArgs.getHelpOptionInst().getSubOptions().isEmpty()) {
- printOptionHelp(cmdLineArgs);
- } else {
- printActionHelp(cmdLineArgs);
- }
- return true;
- }
- return false;
- }
-
- /**
- * Checks if print supported actions option was specified and if so prints out supported actions.
- *
- * @param cmdLineArgs The {@link CmdLineArgs} which will be checked for print supported action options
- * @return True if supported actions was printed, false otherwise
- */
- public boolean handlePrintSupportedActions(CmdLineArgs cmdLineArgs) {
- if (cmdLineArgs.getPrintSupportedActionsOptionInst() != null) {
- printActionsHelp(cmdLineArgs);
- return true;
- }
- return false;
- }
-
- /**
- * Checks if required options are set and validation passes, then runs handlers and executes its action.
- *
- * @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 {
- Set<CmdLineOption> requiredOptionsNotSet = check(cmdLineArgs);
- if (!requiredOptionsNotSet.isEmpty()) {
- throw new IOException("Required options are not set: '" + requiredOptionsNotSet + "'");
- }
-
- Set<CmdLineOptionInstance> optionsFailedValidation = validate(cmdLineArgs);
- if (!optionsFailedValidation.isEmpty()) {
- throw new IOException("Options failed validation: '" + optionsFailedValidation + "'");
- }
-
- handle(cmdLineArgs);
-
- cmdLineArgs.getSpecifiedAction().execute();
- }
-
- /**
- * Checks for required options which are not set and returns the ones it finds.
- *
- * @param cmdLineArgs The {@link CmdLineArgs} which will be check for required options.
- * @return The required {@link CmdLineOption}s not specified.
- */
- public static Set<CmdLineOption> check(CmdLineArgs cmdLineArgs) {
- Set<CmdLineOption> requiredOptions = determineRequired(cmdLineArgs.getSpecifiedAction(), cmdLineArgs.getCustomSupportedOptions());
- HashSet<CmdLineOption> requiredOptionsNotSet = new HashSet<CmdLineOption>(requiredOptions);
- for (CmdLineOptionInstance specifiedOption : cmdLineArgs.getCustomSpecifiedOptions()) {
- requiredOptionsNotSet.remove(specifiedOption.getOption());
- }
- return requiredOptionsNotSet;
- }
-
- /**
- * Runs validation on {@link CmdLineArgs} and returns the options which failed validation.
- *
- * @param cmdLineArgs The {@link CmdLineArgs} which will be validated.
- * @return The {@link CmdLineOptionInstance}s which failed validation.
- */
- public static Set<CmdLineOptionInstance> validate(CmdLineArgs cmdLineArgs) {
- Validate.notNull(cmdLineArgs);
-
- HashSet<CmdLineOptionInstance> optionsFailed = new HashSet<CmdLineOptionInstance>();
- for (CmdLineOptionInstance optionInst : cmdLineArgs.getCustomSpecifiedOptions()) {
- if (!CmdLineUtils.validate(optionInst)) {
- optionsFailed.add(optionInst);
- }
- }
- return optionsFailed;
- }
-
- /**
- * Runs the {@link CmdLineOptionHandler}s for {@link CmdLineArgs} given.
- * @param cmdLineArgs The {@link CmdLineArgs} whose option handlers will be run.
- */
- public static void handle(CmdLineArgs cmdLineArgs) {
- for (CmdLineOptionInstance option : cmdLineArgs.getCustomSpecifiedOptions()) {
- CmdLineUtils.handle(cmdLineArgs.getSpecifiedAction(), option);
- }
- }
+ private CmdLineOptionParser parser;
+ private CmdLineOptionStore optionStore;
+ private CmdLineActionStore actionStore;
+ private CmdLineOptionsHelpPrinter optionHelpPrinter;
+ private CmdLineActionHelpPrinter actionHelpPrinter;
+ private CmdLineActionsHelpPrinter actionsHelpPrinter;
+ private CmdLineOptionHelpPresenter helpPresenter;
+
+ public CmdLineUtility() {
+ parser = new StdCmdLineOptionParser();
+ optionStore = new SpringCmdLineOptionStoreFactory().createStore();
+ actionStore = new SpringCmdLineActionStoreFactory().createStore();
+ optionHelpPrinter = new StdCmdLineOptionsHelpPrinter();
+ actionHelpPrinter = new StdCmdLineActionHelpPrinter();
+ helpPresenter = new StdCmdLineOptionHelpPresenter();
+ }
+
+ public CmdLineOptionStore getOptionStore() {
+ return optionStore;
+ }
+
+ public void setOptionStore(CmdLineOptionStore optionStore) {
+ this.optionStore = optionStore;
+ }
+
+ public CmdLineActionStore getActionStore() {
+ return actionStore;
+ }
+
+ public void setActionStore(CmdLineActionStore actionStore) {
+ this.actionStore = actionStore;
+ }
+
+ public CmdLineOptionsHelpPrinter getOptionHelpPrinter() {
+ return optionHelpPrinter;
+ }
+
+ public void setOptionHelpPrinter(CmdLineOptionsHelpPrinter optionHelpPrinter) {
+ this.optionHelpPrinter = optionHelpPrinter;
+ }
+
+ public CmdLineActionHelpPrinter getActionHelpPrinter() {
+ return actionHelpPrinter;
+ }
+
+ public void setActionHelpPrinter(CmdLineActionHelpPrinter actionHelpPrinter) {
+ this.actionHelpPrinter = actionHelpPrinter;
+ }
+
+ public CmdLineActionsHelpPrinter getActionsHelpPrinter() {
+ return actionsHelpPrinter;
+ }
+
+ public void setActionsHelpPrinter(
+ CmdLineActionsHelpPrinter actionsHelpPrinter) {
+ this.actionsHelpPrinter = actionsHelpPrinter;
+ }
+
+ public CmdLineOptionHelpPresenter getHelpPresenter() {
+ return helpPresenter;
+ }
+
+ public void setHelpPresenter(CmdLineOptionHelpPresenter helpPresenter) {
+ this.helpPresenter = helpPresenter;
+ }
+
+ public void printOptionHelp(CmdLineArgs cmdLineArgs) {
+ helpPresenter.presentOptionHelp(optionHelpPrinter.printHelp(cmdLineArgs
+ .getSupportedOptions()));
+ }
+
+ public void printActionHelp(CmdLineArgs cmdLineArgs) {
+ Validate.notEmpty(cmdLineArgs.getHelpOptionInst().getValues());
+
+ helpPresenter.presentActionHelp(actionHelpPrinter.printHelp(
+ CmdLineUtils.findAction(cmdLineArgs.getHelpOptionInst().getValues()
+ .get(0), cmdLineArgs.getSupportedActions()),
+ cmdLineArgs.getCustomSupportedOptions()));
+ }
+
+ public void printActionsHelp(CmdLineArgs cmdLineArgs) {
+ helpPresenter.presentActionsHelp(actionsHelpPrinter.printHelp(cmdLineArgs
+ .getSupportedActions()));
+ }
+
+ /**
+ * Parses given command line arguments, then checks for help and print
+ * supported actions options, prints them out if found, otherwise performs
+ * execution on the arguments - see execute(CmdLineArgs).
+ *
+ * @param args
+ * The who will be parsed and executed.
+ * @throws IOException
+ * On error parsing or executing the args.
+ */
+ public void run(String[] args) throws IOException {
+ CmdLineArgs cmdLineArgs = parse(args);
+ if (!handleHelp(cmdLineArgs) && !handlePrintSupportedActions(cmdLineArgs)) {
+ execute(cmdLineArgs);
+ }
+ }
+
+ /**
+ * Parses the given command line arguments and converts it to
+ * {@link CmdLineArgs}.
+ *
+ * @param args
+ * The command line arguments to parse.
+ * @return The parsed command line arguments in {@link CmdLineArgs} form.
+ * @throws IOException
+ * On error parsing command line arguments.
+ */
+ public CmdLineArgs parse(String[] args) throws IOException {
+ Validate.notNull(parser);
+ Validate.notNull(optionStore);
+
+ // Load supported options.
+ Set<CmdLineOption> validOptions = optionStore.loadSupportedOptions();
+
+ // Insure help options is present if required.
+ HelpCmdLineOption helpOption = findHelpOption(validOptions);
+ if (helpOption == null) {
+ validOptions.add(helpOption = new HelpCmdLineOption());
+ }
+
+ // Insure action options is present if required.
+ ActionCmdLineOption actionOption = findActionOption(validOptions);
+ if (actionOption == null) {
+ validOptions.add(actionOption = new ActionCmdLineOption());
+ }
+
+ // Insure print supported actions option is present if required.
+ PrintSupportedActionsCmdLineOption psaOption = CmdLineUtils
+ .findPrintSupportedActionsOption(validOptions);
+ if (psaOption == null) {
+ validOptions.add(psaOption = new PrintSupportedActionsCmdLineOption());
+ }
+
+ // Parse command line arguments.
+ return new CmdLineArgs(actionStore.loadSupportedActions(), validOptions,
+ parser.parse(new Args(args), validOptions));
+ }
+
+ /**
+ * Checks if help option was specified and if so prints out help.
+ *
+ * @param cmdLineArgs
+ * The {@link CmdLineArgs} which will be checked for help option
+ * @return True if help was printed, false otherwise
+ */
+ public boolean handleHelp(CmdLineArgs cmdLineArgs) {
+ if (cmdLineArgs.getHelpOptionInst() != null) {
+ if (cmdLineArgs.getHelpOptionInst().getSubOptions().isEmpty()) {
+ printOptionHelp(cmdLineArgs);
+ } else {
+ printActionHelp(cmdLineArgs);
+ }
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * Checks if print supported actions option was specified and if so prints
+ * out supported actions.
+ *
+ * @param cmdLineArgs
+ * The {@link CmdLineArgs} which will be checked for print
+ * supported action options
+ * @return True if supported actions was printed, false otherwise
+ */
+ public boolean handlePrintSupportedActions(CmdLineArgs cmdLineArgs) {
+ if (cmdLineArgs.getPrintSupportedActionsOptionInst() != null) {
+ printActionsHelp(cmdLineArgs);
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * Checks if required options are set and validation passes, then runs
+ * handlers and executes its action.
+ *
+ * @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 {
+ Set<CmdLineOption> requiredOptionsNotSet = check(cmdLineArgs);
+ if (!requiredOptionsNotSet.isEmpty()) {
+ throw new IOException("Required options are not set: '"
+ + requiredOptionsNotSet + "'");
+ }
+
+ Set<CmdLineOptionInstance> optionsFailedValidation = validate(cmdLineArgs);
+ if (!optionsFailedValidation.isEmpty()) {
+ throw new IOException("Options failed validation: '"
+ + optionsFailedValidation + "'");
+ }
+
+ handle(cmdLineArgs);
+
+ cmdLineArgs.getSpecifiedAction().execute();
+ }
+
+ /**
+ * Checks for required options which are not set and returns the ones it
+ * finds.
+ *
+ * @param cmdLineArgs
+ * The {@link CmdLineArgs} which will be check for required
+ * options.
+ * @return The required {@link CmdLineOption}s not specified.
+ */
+ public static Set<CmdLineOption> check(CmdLineArgs cmdLineArgs) {
+ Set<CmdLineOption> requiredOptions = determineRequired(
+ cmdLineArgs.getSpecifiedAction(),
+ cmdLineArgs.getCustomSupportedOptions());
+ HashSet<CmdLineOption> requiredOptionsNotSet = new HashSet<CmdLineOption>(
+ requiredOptions);
+ for (CmdLineOptionInstance specifiedOption : cmdLineArgs
+ .getCustomSpecifiedOptions()) {
+ requiredOptionsNotSet.remove(specifiedOption.getOption());
+ }
+ return requiredOptionsNotSet;
+ }
+
+ /**
+ * Runs validation on {@link CmdLineArgs} and returns the options which
+ * failed validation.
+ *
+ * @param cmdLineArgs
+ * The {@link CmdLineArgs} which will be validated.
+ * @return The {@link CmdLineOptionInstance}s which failed validation.
+ */
+ public static Set<CmdLineOptionInstance> validate(CmdLineArgs cmdLineArgs) {
+ Validate.notNull(cmdLineArgs);
+
+ HashSet<CmdLineOptionInstance> optionsFailed = new HashSet<CmdLineOptionInstance>();
+ for (CmdLineOptionInstance optionInst : cmdLineArgs
+ .getCustomSpecifiedOptions()) {
+ if (!CmdLineUtils.validate(optionInst)) {
+ optionsFailed.add(optionInst);
+ }
+ }
+ return optionsFailed;
+ }
+
+ /**
+ * Runs the {@link CmdLineOptionHandler}s for {@link CmdLineArgs} given.
+ *
+ * @param cmdLineArgs
+ * The {@link CmdLineArgs} whose option handlers will be run.
+ */
+ public static void handle(CmdLineArgs cmdLineArgs) {
+ for (CmdLineOptionInstance option : cmdLineArgs
+ .getCustomSpecifiedOptions()) {
+ CmdLineUtils.handle(cmdLineArgs.getSpecifiedAction(), option);
+ }
+ }
}
Modified: oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/action/CmdLineAction.java
URL: http://svn.apache.org/viewvc/oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/action/CmdLineAction.java?rev=1195292&r1=1195291&r2=1195292&view=diff
==============================================================================
--- oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/action/CmdLineAction.java (original)
+++ oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/action/CmdLineAction.java Mon Oct 31 01:01:18 2011
@@ -17,39 +17,40 @@
package org.apache.oodt.cas.cl.action;
/**
- * Action which is specified and configurated via {@link CmdLineOption}s
- * and then executed.
- *
+ * Action which is specified and configurated via {@link CmdLineOption}s and
+ * then executed.
+ *
* @author bfoster (Brian Foster)
*/
public abstract class CmdLineAction {
- private String name;
- private String description;
+ private String name;
+ private String description;
- public CmdLineAction() {}
+ public CmdLineAction() {
+ }
- public CmdLineAction(String name, String description) {
- this.name = name;
- this.description = description;
- }
+ public CmdLineAction(String name, String description) {
+ this.name = name;
+ this.description = description;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+ public String getDescription() {
+ return description;
+ }
- public void setName(String name) {
- this.name = name;
- }
-
- public String getName() {
- return name;
- }
-
- public void setDescription(String description) {
- this.description = description;
- }
-
- public String getDescription() {
- return description;
- }
-
- public abstract void execute();
+ public abstract void execute();
}
Modified: oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/action/PrintMessageAction.java
URL: http://svn.apache.org/viewvc/oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/action/PrintMessageAction.java?rev=1195292&r1=1195291&r2=1195292&view=diff
==============================================================================
--- oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/action/PrintMessageAction.java (original)
+++ oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/action/PrintMessageAction.java Mon Oct 31 01:01:18 2011
@@ -26,43 +26,43 @@ import org.springframework.beans.factory
/**
* A {@link CmdLineAction} which prints out a given message.
- *
+ *
* @author bfoster (Brian Foster)
*/
public class PrintMessageAction extends CmdLineAction {
- private String message;
- private OutputStream os;
+ private String message;
+ private OutputStream os;
- public PrintMessageAction() {
- os = System.out;
- }
-
- @Override
- public void execute() {
- Validate.notNull(message);
-
- PrintStream ps = new PrintStream(os);
- ps.println(message);
- ps.close();
- }
-
- @Required
- public void setMessage(String message) {
- this.message = message;
- }
-
- public String getMessage() {
- return message;
- }
-
- public void setOutputStream(OutputStream os) {
- Validate.notNull(os);
-
- this.os = os;
- }
-
- public OutputStream getOutputStream() {
- return os;
- }
+ public PrintMessageAction() {
+ os = System.out;
+ }
+
+ @Override
+ public void execute() {
+ Validate.notNull(message);
+
+ PrintStream ps = new PrintStream(os);
+ ps.println(message);
+ ps.close();
+ }
+
+ @Required
+ public void setMessage(String message) {
+ this.message = message;
+ }
+
+ public String getMessage() {
+ return message;
+ }
+
+ public void setOutputStream(OutputStream os) {
+ Validate.notNull(os);
+
+ this.os = os;
+ }
+
+ public OutputStream getOutputStream() {
+ return os;
+ }
}
Modified: oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/action/store/CmdLineActionStore.java
URL: http://svn.apache.org/viewvc/oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/action/store/CmdLineActionStore.java?rev=1195292&r1=1195291&r2=1195292&view=diff
==============================================================================
--- oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/action/store/CmdLineActionStore.java (original)
+++ oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/action/store/CmdLineActionStore.java Mon Oct 31 01:01:18 2011
@@ -24,11 +24,11 @@ import org.apache.oodt.cas.cl.action.Cmd
/**
* Storage for loading supported {@link CmdLineAction}s.
- *
+ *
* @author bfoster (Brian Foster)
*/
public interface CmdLineActionStore {
- public Set<CmdLineAction> loadSupportedActions();
+ public Set<CmdLineAction> loadSupportedActions();
}
Modified: oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/action/store/CmdLineActionStoreFactory.java
URL: http://svn.apache.org/viewvc/oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/action/store/CmdLineActionStoreFactory.java?rev=1195292&r1=1195291&r2=1195292&view=diff
==============================================================================
--- oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/action/store/CmdLineActionStoreFactory.java (original)
+++ oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/action/store/CmdLineActionStoreFactory.java Mon Oct 31 01:01:18 2011
@@ -18,11 +18,11 @@ package org.apache.oodt.cas.cl.action.st
/**
* Factory for creating {@link CmdLineActionStore}s.
- *
+ *
* @author bfoster (Brian Foster)
*/
public interface CmdLineActionStoreFactory {
- public CmdLineActionStore createStore();
+ public CmdLineActionStore createStore();
}
Modified: oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/action/store/spring/SpringCmdLineActionStore.java
URL: http://svn.apache.org/viewvc/oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/action/store/spring/SpringCmdLineActionStore.java?rev=1195292&r1=1195291&r2=1195292&view=diff
==============================================================================
--- oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/action/store/spring/SpringCmdLineActionStore.java (original)
+++ oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/action/store/spring/SpringCmdLineActionStore.java Mon Oct 31 01:01:18 2011
@@ -30,45 +30,45 @@ import org.springframework.context.suppo
/**
* A Spring Framework based {@link CmdLineActionStore}.
- *
+ *
* @author bfoster (Brian Foster)
*/
public class SpringCmdLineActionStore implements CmdLineActionStore {
- private ApplicationContext appContext;
+ private ApplicationContext appContext;
- public SpringCmdLineActionStore(String springConfig) {
- appContext = new FileSystemXmlApplicationContext(springConfig);
- handleSpringSetContextInjectionType();
- handleSettingNameForCmdLineActions();
- }
-
- public Set<CmdLineAction> loadSupportedActions() {
- @SuppressWarnings("unchecked")
- Map<String, CmdLineAction> actionsMap = appContext
- .getBeansOfType(CmdLineAction.class);
- return new HashSet<CmdLineAction>(actionsMap.values());
- }
-
- protected ApplicationContext getApplicationContext() {
- return appContext;
- }
-
- private void handleSpringSetContextInjectionType() {
- @SuppressWarnings("unchecked")
- Map<String, SpringSetContextInjectionType> beans = appContext
- .getBeansOfType(SpringSetContextInjectionType.class);
- for (SpringSetContextInjectionType bean : beans.values()) {
- bean.setContext(appContext);
- }
- }
-
- private void handleSettingNameForCmdLineActions() {
- @SuppressWarnings("unchecked")
- Map<String, CmdLineAction> beans = appContext
- .getBeansOfType(CmdLineAction.class);
- for (Entry<String, CmdLineAction> entry : beans.entrySet()) {
- entry.getValue().setName(entry.getKey());
- }
- }
+ public SpringCmdLineActionStore(String springConfig) {
+ appContext = new FileSystemXmlApplicationContext(springConfig);
+ handleSpringSetContextInjectionType();
+ handleSettingNameForCmdLineActions();
+ }
+
+ public Set<CmdLineAction> loadSupportedActions() {
+ @SuppressWarnings("unchecked")
+ Map<String, CmdLineAction> actionsMap = appContext
+ .getBeansOfType(CmdLineAction.class);
+ return new HashSet<CmdLineAction>(actionsMap.values());
+ }
+
+ protected ApplicationContext getApplicationContext() {
+ return appContext;
+ }
+
+ private void handleSpringSetContextInjectionType() {
+ @SuppressWarnings("unchecked")
+ Map<String, SpringSetContextInjectionType> beans = appContext
+ .getBeansOfType(SpringSetContextInjectionType.class);
+ for (SpringSetContextInjectionType bean : beans.values()) {
+ bean.setContext(appContext);
+ }
+ }
+
+ private void handleSettingNameForCmdLineActions() {
+ @SuppressWarnings("unchecked")
+ Map<String, CmdLineAction> beans = appContext
+ .getBeansOfType(CmdLineAction.class);
+ for (Entry<String, CmdLineAction> entry : beans.entrySet()) {
+ entry.getValue().setName(entry.getKey());
+ }
+ }
}
Modified: oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/action/store/spring/SpringCmdLineActionStoreFactory.java
URL: http://svn.apache.org/viewvc/oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/action/store/spring/SpringCmdLineActionStoreFactory.java?rev=1195292&r1=1195291&r2=1195292&view=diff
==============================================================================
--- oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/action/store/spring/SpringCmdLineActionStoreFactory.java (original)
+++ oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/action/store/spring/SpringCmdLineActionStoreFactory.java Mon Oct 31 01:01:18 2011
@@ -21,22 +21,24 @@ import org.apache.oodt.cas.cl.action.sto
/**
* Factory for creating {@link SpringCmdLineActionStore}s.
- *
+ *
* @author bfoster (Brian Foster)
*/
-public class SpringCmdLineActionStoreFactory implements CmdLineActionStoreFactory {
+public class SpringCmdLineActionStoreFactory implements
+ CmdLineActionStoreFactory {
- private String config;
+ private String config;
- public SpringCmdLineActionStoreFactory() {
- config = System.getProperty("org.apache.oodt.cas.cl.option.action.spring.config", null);
- }
+ public SpringCmdLineActionStoreFactory() {
+ config = System.getProperty(
+ "org.apache.oodt.cas.cl.option.action.spring.config", null);
+ }
- public SpringCmdLineActionStore createStore() {
- if (config != null) {
- return new SpringCmdLineActionStore(config);
- } else {
- return null;
- }
- }
+ public SpringCmdLineActionStore createStore() {
+ if (config != null) {
+ return new SpringCmdLineActionStore(config);
+ } else {
+ return null;
+ }
+ }
}
Modified: oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/action/store/spring/SpringSetContextInjectionType.java
URL: http://svn.apache.org/viewvc/oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/action/store/spring/SpringSetContextInjectionType.java?rev=1195292&r1=1195291&r2=1195292&view=diff
==============================================================================
--- oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/action/store/spring/SpringSetContextInjectionType.java (original)
+++ oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/action/store/spring/SpringSetContextInjectionType.java Mon Oct 31 01:01:18 2011
@@ -21,14 +21,14 @@ import org.springframework.context.Appli
/**
* Interface which if implemented will have the Spring Framework
- * {@link ApplicationContext} injected via the setter method
- * after loading from Spring XML configuration.
- *
+ * {@link ApplicationContext} injected via the setter method after loading from
+ * Spring XML configuration.
+ *
* @author bfoster (Brian Foster)
*/
public interface SpringSetContextInjectionType {
- public void setContext(ApplicationContext appContext);
+ public void setContext(ApplicationContext appContext);
- public ApplicationContext getContext();
+ public ApplicationContext getContext();
}
Modified: oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/help/OptionHelpException.java
URL: http://svn.apache.org/viewvc/oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/help/OptionHelpException.java?rev=1195292&r1=1195291&r2=1195292&view=diff
==============================================================================
--- oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/help/OptionHelpException.java (original)
+++ oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/help/OptionHelpException.java Mon Oct 31 01:01:18 2011
@@ -20,21 +20,21 @@ package org.apache.oodt.cas.cl.help;
import java.io.IOException;
/**
- * Exception thrown to express that help {@link CmdLineOption} should be
- * given to see help message.
+ * Exception thrown to express that help {@link CmdLineOption} should be given
+ * to see help message.
*
* @author bfoster (Brian Foster)
*/
public class OptionHelpException extends IOException {
- private static final long serialVersionUID = -8198106641155733222L;
+ private static final long serialVersionUID = -8198106641155733222L;
+
+ public OptionHelpException() {
+ super();
+ }
+
+ public OptionHelpException(String message) {
+ super(message);
+ }
- public OptionHelpException() {
- super();
- }
-
- public OptionHelpException(String message) {
- super(message);
- }
-
}
Modified: oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/help/presenter/CmdLineOptionHelpPresenter.java
URL: http://svn.apache.org/viewvc/oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/help/presenter/CmdLineOptionHelpPresenter.java?rev=1195292&r1=1195291&r2=1195292&view=diff
==============================================================================
--- oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/help/presenter/CmdLineOptionHelpPresenter.java (original)
+++ oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/help/presenter/CmdLineOptionHelpPresenter.java Mon Oct 31 01:01:18 2011
@@ -18,15 +18,15 @@ package org.apache.oodt.cas.cl.help.pres
/**
* Presenter to displaying help messages generated by help printers.
- *
+ *
* @author bfoster (Brian Foster)
*/
public interface CmdLineOptionHelpPresenter {
- public void presentOptionHelp(String optionHelpMessage);
+ public void presentOptionHelp(String optionHelpMessage);
- public void presentActionHelp(String actionHelpMessage);
+ public void presentActionHelp(String actionHelpMessage);
- public void presentActionsHelp(String actionsHelpMessage);
+ public void presentActionsHelp(String actionsHelpMessage);
}
Modified: oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/help/presenter/StdCmdLineOptionHelpPresenter.java
URL: http://svn.apache.org/viewvc/oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/help/presenter/StdCmdLineOptionHelpPresenter.java?rev=1195292&r1=1195291&r2=1195292&view=diff
==============================================================================
--- oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/help/presenter/StdCmdLineOptionHelpPresenter.java (original)
+++ oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/help/presenter/StdCmdLineOptionHelpPresenter.java Mon Oct 31 01:01:18 2011
@@ -21,26 +21,27 @@ import java.io.PrintStream;
/**
* Standard help presenter which sends help messages to {@link System.out}.
- *
+ *
* @author bfoster (Brian Foster)
*/
-public class StdCmdLineOptionHelpPresenter implements CmdLineOptionHelpPresenter {
+public class StdCmdLineOptionHelpPresenter implements
+ CmdLineOptionHelpPresenter {
- private PrintStream ps;
+ private PrintStream ps;
- public StdCmdLineOptionHelpPresenter() {
- ps = new PrintStream(System.out);
- }
-
- public void presentOptionHelp(String optionHelpMessage) {
- ps.println(optionHelpMessage);
- }
-
- public void presentActionHelp(String actionHelpMessage) {
- ps.println(actionHelpMessage);
- }
-
- public void presentActionsHelp(String actionsHelpMessage) {
- ps.println(actionsHelpMessage);
- }
+ public StdCmdLineOptionHelpPresenter() {
+ ps = new PrintStream(System.out);
+ }
+
+ public void presentOptionHelp(String optionHelpMessage) {
+ ps.println(optionHelpMessage);
+ }
+
+ public void presentActionHelp(String actionHelpMessage) {
+ ps.println(actionHelpMessage);
+ }
+
+ public void presentActionsHelp(String actionsHelpMessage) {
+ ps.println(actionsHelpMessage);
+ }
}
Modified: oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/help/printer/CmdLineActionHelpPrinter.java
URL: http://svn.apache.org/viewvc/oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/help/printer/CmdLineActionHelpPrinter.java?rev=1195292&r1=1195291&r2=1195292&view=diff
==============================================================================
--- oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/help/printer/CmdLineActionHelpPrinter.java (original)
+++ oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/help/printer/CmdLineActionHelpPrinter.java Mon Oct 31 01:01:18 2011
@@ -24,21 +24,23 @@ import org.apache.oodt.cas.cl.action.Cmd
import org.apache.oodt.cas.cl.option.CmdLineOption;
/**
- * Help printer responsible for generating help message for using
- * a given {@link CmdLineAction}.
- *
+ * Help printer responsible for generating help message for using a given
+ * {@link CmdLineAction}.
+ *
* @author bfoster (Brian Foster)
*/
public interface CmdLineActionHelpPrinter {
- /**
- * 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 printHelp(CmdLineAction action, Set<CmdLineOption> options);
+ /**
+ * 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 printHelp(CmdLineAction action, Set<CmdLineOption> options);
}
Modified: oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/help/printer/CmdLineActionsHelpPrinter.java
URL: http://svn.apache.org/viewvc/oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/help/printer/CmdLineActionsHelpPrinter.java?rev=1195292&r1=1195291&r2=1195292&view=diff
==============================================================================
--- oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/help/printer/CmdLineActionsHelpPrinter.java (original)
+++ oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/help/printer/CmdLineActionsHelpPrinter.java Mon Oct 31 01:01:18 2011
@@ -23,19 +23,20 @@ import java.util.Set;
import org.apache.oodt.cas.cl.action.CmdLineAction;
/**
- * Help printer responsible for generating print help message for
- * supported {@link CmdLineAction}s.
- *
+ * Help printer responsible for generating print help message for supported
+ * {@link CmdLineAction}s.
+ *
* @author bfoster (Brian Foster)
*/
public interface CmdLineActionsHelpPrinter {
- /**
- * 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 printHelp(Set<CmdLineAction> actions);
+ /**
+ * 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 printHelp(Set<CmdLineAction> actions);
}
Modified: oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/help/printer/CmdLineOptionsHelpPrinter.java
URL: http://svn.apache.org/viewvc/oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/help/printer/CmdLineOptionsHelpPrinter.java?rev=1195292&r1=1195291&r2=1195292&view=diff
==============================================================================
--- oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/help/printer/CmdLineOptionsHelpPrinter.java (original)
+++ oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/help/printer/CmdLineOptionsHelpPrinter.java Mon Oct 31 01:01:18 2011
@@ -25,18 +25,18 @@ import org.apache.oodt.cas.cl.option.Cmd
/**
* Help printer responsible for generating help message for given
* {@link CmdLineOption}s.
- *
+ *
* @author bfoster (Brian Foster)
*/
public interface CmdLineOptionsHelpPrinter {
- /**
- * 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 printHelp(Set<CmdLineOption> options);
+ /**
+ * 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 printHelp(Set<CmdLineOption> options);
}
Modified: oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/help/printer/StdCmdLineActionHelpPrinter.java
URL: http://svn.apache.org/viewvc/oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/help/printer/StdCmdLineActionHelpPrinter.java?rev=1195292&r1=1195291&r2=1195292&view=diff
==============================================================================
--- oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/help/printer/StdCmdLineActionHelpPrinter.java (original)
+++ oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/help/printer/StdCmdLineActionHelpPrinter.java Mon Oct 31 01:01:18 2011
@@ -31,64 +31,63 @@ import org.apache.oodt.cas.cl.option.Cmd
/**
* Standard help printer for printing help for a {@link CmdLineAction}.
- *
+ *
* @author bfoster (Brian Foster)
*/
-public class StdCmdLineActionHelpPrinter implements
- CmdLineActionHelpPrinter {
+public class StdCmdLineActionHelpPrinter implements CmdLineActionHelpPrinter {
- /**
- * {@inheritDoc}
- */
- public String printHelp(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(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(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(CmdLineOption option) {
- return getOptionHelp(option);
- }
-
- protected String getOptionalSubHeader() {
- return " - Optional:";
- }
-
- protected String getOptionalOptionHelp(CmdLineOption option) {
- return getOptionHelp(option);
- }
-
- protected String getFooter(CmdLineAction action) {
- return "";
- }
-
- protected String getOptionHelp(CmdLineOption option) {
- return " -" + option.getShortOption() + " [--" + option.getLongOption()
- + "] "
- + (option.hasArgs() ? "<" + option.getArgsDescription() + ">" : "");
- }
+ /**
+ * {@inheritDoc}
+ */
+ public String printHelp(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(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(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(CmdLineOption option) {
+ return getOptionHelp(option);
+ }
+
+ protected String getOptionalSubHeader() {
+ return " - Optional:";
+ }
+
+ protected String getOptionalOptionHelp(CmdLineOption option) {
+ return getOptionHelp(option);
+ }
+
+ protected String getFooter(CmdLineAction action) {
+ return "";
+ }
+
+ protected String getOptionHelp(CmdLineOption option) {
+ return " -" + option.getShortOption() + " [--"
+ + option.getLongOption() + "] "
+ + (option.hasArgs() ? "<" + option.getArgsDescription() + ">" : "");
+ }
}
Modified: oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/help/printer/StdCmdLineActionsHelpPrinter.java
URL: http://svn.apache.org/viewvc/oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/help/printer/StdCmdLineActionsHelpPrinter.java?rev=1195292&r1=1195291&r2=1195292&view=diff
==============================================================================
--- oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/help/printer/StdCmdLineActionsHelpPrinter.java (original)
+++ oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/help/printer/StdCmdLineActionsHelpPrinter.java Mon Oct 31 01:01:18 2011
@@ -24,38 +24,38 @@ import org.apache.oodt.cas.cl.action.Cmd
/**
* Standard help printer which prints supported actions help in the format of:
+ *
* <pre>
* Actions:
* Action:
* Name: ActionName
* Description: Action Description
- *
+ *
* Action:
* Name: ActionName
* Description: Action Description
- *
+ *
* ...
* ...
* ...
* </pre>
- *
+ *
* @author bfoster (Brian Foster)
*/
-public class StdCmdLineActionsHelpPrinter
- implements CmdLineActionsHelpPrinter {
+public class StdCmdLineActionsHelpPrinter implements CmdLineActionsHelpPrinter {
- /**
- * {@inheritDoc}
- */
- public String printHelp(Set<CmdLineAction> actions) {
- StringBuffer sb = new StringBuffer("");
- for (CmdLineAction action : actions) {
- sb.append("Actions:").append("\n");
- 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();
- }
+ /**
+ * {@inheritDoc}
+ */
+ public String printHelp(Set<CmdLineAction> actions) {
+ StringBuffer sb = new StringBuffer("");
+ for (CmdLineAction action : actions) {
+ sb.append("Actions:").append("\n");
+ 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();
+ }
}
Modified: oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/help/printer/StdCmdLineOptionsHelpPrinter.java
URL: http://svn.apache.org/viewvc/oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/help/printer/StdCmdLineOptionsHelpPrinter.java?rev=1195292&r1=1195291&r2=1195292&view=diff
==============================================================================
--- oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/help/printer/StdCmdLineOptionsHelpPrinter.java (original)
+++ oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/help/printer/StdCmdLineOptionsHelpPrinter.java Mon Oct 31 01:01:18 2011
@@ -33,61 +33,64 @@ import org.apache.oodt.cas.cl.option.Cmd
/**
* Standard help printer for {@link CmdLineOption}s.
- *
+ *
* @author bfoster (Brian Foster)
*/
public class StdCmdLineOptionsHelpPrinter implements CmdLineOptionsHelpPrinter {
- /**
- * {@inheritDoc}
- */
- public String printHelp(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 argName = option.hasArgs() ? " <" + option.getArgsDescription() + ">" : "";
- String optionUsage = "-"
- + StringUtils.rightPad(option.getShortOption() + ",", 7) + "--"
- + StringUtils.rightPad((option.getLongOption() + argName), 49)
- + option.getDescription();
- if (option instanceof AdvancedCmdLineOption) {
- if (((AdvancedCmdLineOption) option).hasHandler()) {
- optionUsage += getFormattedString(((AdvancedCmdLineOption) option).getHandler().getHelp(option),
- 62, 113);
- }
- }
-
- if (option.isRequired()) {
- optionUsage = " " + optionUsage;
- } else if (!option.getRequirementRules().isEmpty()) {
- optionUsage = "{" + optionUsage + "}";
- optionUsage += "\n" + getFormattedString("RequiredOptions: "
- + option.getRequirementRules(), 62, 113);
- } else {
- optionUsage = "[" + optionUsage + "]";
- }
-
- return optionUsage;
- }
-
- protected String getFooter() {
- return "-----------------------------------------------------------------------------------------------------------------";
- }
+ /**
+ * {@inheritDoc}
+ */
+ public String printHelp(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 argName = option.hasArgs() ? " <" + option.getArgsDescription()
+ + ">" : "";
+ String optionUsage = "-"
+ + StringUtils.rightPad(option.getShortOption() + ",", 7) + "--"
+ + StringUtils.rightPad((option.getLongOption() + argName), 49)
+ + option.getDescription();
+ if (option instanceof AdvancedCmdLineOption) {
+ if (((AdvancedCmdLineOption) option).hasHandler()) {
+ optionUsage += getFormattedString(((AdvancedCmdLineOption) option)
+ .getHandler().getHelp(option), 62, 113);
+ }
+ }
+
+ if (option.isRequired()) {
+ optionUsage = " " + optionUsage;
+ } else if (!option.getRequirementRules().isEmpty()) {
+ optionUsage = "{" + optionUsage + "}";
+ optionUsage += "\n"
+ + getFormattedString(
+ "RequiredOptions: " + option.getRequirementRules(), 62,
+ 113);
+ } else {
+ optionUsage = "[" + optionUsage + "]";
+ }
+
+ return optionUsage;
+ }
+
+ protected String getFooter() {
+ return "-----------------------------------------------------------------------------------------------------------------";
+ }
}
Modified: oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/ActionCmdLineOption.java
URL: http://svn.apache.org/viewvc/oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/ActionCmdLineOption.java?rev=1195292&r1=1195291&r2=1195292&view=diff
==============================================================================
--- oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/ActionCmdLineOption.java (original)
+++ oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/ActionCmdLineOption.java Mon Oct 31 01:01:18 2011
@@ -1,17 +1,39 @@
+/*
+ * 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.cl.option;
+/**
+ * {@link CmdLineOption} for specifying {@link CmdLineAction}.
+ *
+ * @author bfoster (Brian Foster)
+ */
public class ActionCmdLineOption extends SimpleCmdLineOption {
- public ActionCmdLineOption() {
- this("a", "action", "This is the name of the action to trigger", true);
- }
+ public ActionCmdLineOption() {
+ this("a", "action", "This is the name of the action to trigger", true);
+ }
- public ActionCmdLineOption(String shortOption, String longOption, String description, boolean hasArgs) {
- super(shortOption, longOption, description, hasArgs);
- this.setArgsDescription("action-name");
- this.setRequired(true);
- this.setType(String.class);
- this.setPerformAndQuit(false);
- }
+ public ActionCmdLineOption(String shortOption, String longOption,
+ String description, boolean hasArgs) {
+ super(shortOption, longOption, description, hasArgs);
+ this.setArgsDescription("action-name");
+ this.setRequired(true);
+ this.setType(String.class);
+ this.setPerformAndQuit(false);
+ }
}
Modified: oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/AdvancedCmdLineOption.java
URL: http://svn.apache.org/viewvc/oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/AdvancedCmdLineOption.java?rev=1195292&r1=1195291&r2=1195292&view=diff
==============================================================================
--- oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/AdvancedCmdLineOption.java (original)
+++ oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/AdvancedCmdLineOption.java Mon Oct 31 01:01:18 2011
@@ -1,60 +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.cl.option;
+//JDK imports
import java.util.ArrayList;
import java.util.List;
+//OODT imports
import org.apache.oodt.cas.cl.option.handler.CmdLineOptionHandler;
import org.apache.oodt.cas.cl.option.validator.CmdLineOptionValidator;
-public class AdvancedCmdLineOption extends SimpleCmdLineOption implements ValidatableCmdLineOption, HandleableCmdLineOption {
-
- private boolean isAction;
- private CmdLineOptionHandler handler;
- private List<CmdLineOptionValidator> validators;
- private boolean performAndQuit;
-
- public AdvancedCmdLineOption() {
- super();
- validators = new ArrayList<CmdLineOptionValidator>();
- }
-
- public AdvancedCmdLineOption(String shortOption, String longOption, String description, boolean hasArgs) {
- super(shortOption, longOption, description, hasArgs);
- }
-
- public void setAction(boolean isAction) {
- this.isAction = isAction;
- }
-
- public boolean isAction() {
- return isAction;
- }
-
- public void setHandler(CmdLineOptionHandler handler) {
- this.handler = handler;
- }
-
- public CmdLineOptionHandler getHandler() {
- return handler;
- }
-
- public boolean hasHandler() {
- return handler != null;
- }
-
- public List<CmdLineOptionValidator> getValidators() {
- return this.validators;
- }
-
- public void setValidators(List<CmdLineOptionValidator> validators) {
- this.validators = validators;
- }
-
- public boolean isPerformAndQuit() {
- return performAndQuit;
- }
-
- public void setPerformAndQuit(boolean performAndQuit) {
- this.performAndQuit = performAndQuit;
- }
+/**
+ * Advanced version of a {@link CmdLineOption} which supports validation and
+ * option handling.
+ *
+ * @author bfoster (Brian Foster)
+ */
+public class AdvancedCmdLineOption extends SimpleCmdLineOption implements
+ ValidatableCmdLineOption, HandleableCmdLineOption {
+
+ private boolean isAction;
+ private CmdLineOptionHandler handler;
+ private List<CmdLineOptionValidator> validators;
+ private boolean performAndQuit;
+
+ public AdvancedCmdLineOption() {
+ super();
+ validators = new ArrayList<CmdLineOptionValidator>();
+ }
+
+ public AdvancedCmdLineOption(String shortOption, String longOption,
+ String description, boolean hasArgs) {
+ super(shortOption, longOption, description, hasArgs);
+ }
+
+ public void setAction(boolean isAction) {
+ this.isAction = isAction;
+ }
+
+ public boolean isAction() {
+ return isAction;
+ }
+
+ public void setHandler(CmdLineOptionHandler handler) {
+ this.handler = handler;
+ }
+
+ public CmdLineOptionHandler getHandler() {
+ return handler;
+ }
+
+ public boolean hasHandler() {
+ return handler != null;
+ }
+
+ public List<CmdLineOptionValidator> getValidators() {
+ return this.validators;
+ }
+
+ public void setValidators(List<CmdLineOptionValidator> validators) {
+ this.validators = validators;
+ }
+
+ public boolean isPerformAndQuit() {
+ return performAndQuit;
+ }
+
+ public void setPerformAndQuit(boolean performAndQuit) {
+ this.performAndQuit = performAndQuit;
+ }
}
Modified: oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/CmdLineOption.java
URL: http://svn.apache.org/viewvc/oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/CmdLineOption.java?rev=1195292&r1=1195291&r2=1195292&view=diff
==============================================================================
--- oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/CmdLineOption.java (original)
+++ oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/CmdLineOption.java Mon Oct 31 01:01:18 2011
@@ -24,54 +24,54 @@ import org.apache.oodt.cas.cl.option.req
/**
* Command Line option interface spec.
- *
+ *
* @author bfoster (Brian Foster)
*/
public interface CmdLineOption {
- public void setLongOption(String longOption);
+ public void setLongOption(String longOption);
- public String getLongOption();
+ public String getLongOption();
- public void setShortOption(String shortOption);
+ public void setShortOption(String shortOption);
- public String getShortOption();
+ public String getShortOption();
- public void setDescription(String description);
+ public void setDescription(String description);
- public String getDescription();
+ public String getDescription();
- public void setType(Class<?> type);
+ public void setType(Class<?> type);
- public Class<?> getType();
+ public Class<?> getType();
- public void setRepeating(boolean repeating);
+ public void setRepeating(boolean repeating);
- public boolean isRepeating();
+ public boolean isRepeating();
- public void setHasArgs(boolean hasArgs);
+ public void setHasArgs(boolean hasArgs);
- public boolean hasArgs();
+ public boolean hasArgs();
- public void setArgsDescription(String argDescription);
+ public void setArgsDescription(String argDescription);
- public String getArgsDescription();
+ public String getArgsDescription();
- public void setDefaultArgs(List<String> values);
+ public void setDefaultArgs(List<String> values);
- public List<String> getDefaultArgs();
+ public List<String> getDefaultArgs();
- public boolean hasDefaultArgs();
+ public boolean hasDefaultArgs();
- public void setRequired(boolean required);
+ public void setRequired(boolean required);
- public boolean isRequired();
+ public boolean isRequired();
- public void setRequirementRules(List<RequirementRule> requirementRules);
+ public void setRequirementRules(List<RequirementRule> requirementRules);
- public List<RequirementRule> getRequirementRules();
+ public List<RequirementRule> getRequirementRules();
- public boolean equals(Object obj);
+ public boolean equals(Object obj);
- public int hashCode();
+ public int hashCode();
}
Modified: oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/CmdLineOptionInstance.java
URL: http://svn.apache.org/viewvc/oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/CmdLineOptionInstance.java?rev=1195292&r1=1195291&r2=1195292&view=diff
==============================================================================
--- oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/CmdLineOptionInstance.java (original)
+++ oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/CmdLineOptionInstance.java Mon Oct 31 01:01:18 2011
@@ -26,106 +26,105 @@ import java.util.Set;
import org.apache.commons.lang.Validate;
/**
- * A specified {@link CmdLineOption} with its specified argument
- * values.
- *
+ * A specified {@link CmdLineOption} with its specified argument values.
+ *
* @author bfoster (Brian Foster)
*/
public class CmdLineOptionInstance {
- private CmdLineOption option;
- private List<String> values;
- private Set<CmdLineOptionInstance> subOptions;
-
- public CmdLineOptionInstance() {
- values = new ArrayList<String>();
- subOptions = new HashSet<CmdLineOptionInstance>();
- }
-
- public CmdLineOptionInstance(CmdLineOption option, List<String> values) {
- Validate.notNull(option);
- Validate.notNull(values);
-
- this.option = option;
- this.values = values;
- subOptions = new HashSet<CmdLineOptionInstance>();
- }
-
- public void setOption(CmdLineOption option) {
- this.option = option;
- }
-
- public CmdLineOption getOption() {
- return option;
- }
-
- public boolean isGroup() {
- return option instanceof GroupCmdLineOption;
- }
-
- public boolean isAction() {
- return option instanceof ActionCmdLineOption;
- }
-
- public boolean isHelp() {
- return option instanceof HelpCmdLineOption;
- }
-
- public boolean isPrintSupportedActions() {
- return option instanceof PrintSupportedActionsCmdLineOption;
- }
-
- public boolean isValidatable() {
- return option instanceof ValidatableCmdLineOption;
- }
-
- public boolean isHandleable() {
- return option instanceof HandleableCmdLineOption;
- }
-
- public void setValues(List<String> values) {
- Validate.notNull(values);
-
- this.values = new ArrayList<String>(values);
- }
-
- public void addValue(String value) {
- values.add(value);
- }
-
- public List<String> getValues() {
- if (values.isEmpty() && option.hasDefaultArgs()) {
- return option.getDefaultArgs();
- } else {
- return values;
- }
- }
-
- public void setSubOptions(List<CmdLineOptionInstance> subOptions) {
- Validate.isTrue(isGroup(), "Must be group option to have subOptions");
- Validate.notNull(subOptions, "Cannot set subOptions to NULL");
-
- this.subOptions = new HashSet<CmdLineOptionInstance>(subOptions);
- }
-
- public void addSubOption(CmdLineOptionInstance subOption) {
- Validate.isTrue(isGroup(), "Must be group option to have subOptions");
- Validate.notNull(subOption, "Cannot add NULL subOption");
-
- this.subOptions.add(subOption);
- }
-
- public Set<CmdLineOptionInstance> getSubOptions() {
- return subOptions;
- }
-
- public boolean equals(Object obj) {
- if (obj instanceof CmdLineOptionInstance) {
- CmdLineOptionInstance compareObj = (CmdLineOptionInstance) obj;
- return compareObj.option.equals(this.option)
- && compareObj.values.equals(this.values);
- } else {
- return false;
- }
- }
+ private CmdLineOption option;
+ private List<String> values;
+ private Set<CmdLineOptionInstance> subOptions;
+
+ public CmdLineOptionInstance() {
+ values = new ArrayList<String>();
+ subOptions = new HashSet<CmdLineOptionInstance>();
+ }
+
+ public CmdLineOptionInstance(CmdLineOption option, List<String> values) {
+ Validate.notNull(option);
+ Validate.notNull(values);
+
+ this.option = option;
+ this.values = values;
+ subOptions = new HashSet<CmdLineOptionInstance>();
+ }
+
+ public void setOption(CmdLineOption option) {
+ this.option = option;
+ }
+
+ public CmdLineOption getOption() {
+ return option;
+ }
+
+ public boolean isGroup() {
+ return option instanceof GroupCmdLineOption;
+ }
+
+ public boolean isAction() {
+ return option instanceof ActionCmdLineOption;
+ }
+
+ public boolean isHelp() {
+ return option instanceof HelpCmdLineOption;
+ }
+
+ public boolean isPrintSupportedActions() {
+ return option instanceof PrintSupportedActionsCmdLineOption;
+ }
+
+ public boolean isValidatable() {
+ return option instanceof ValidatableCmdLineOption;
+ }
+
+ public boolean isHandleable() {
+ return option instanceof HandleableCmdLineOption;
+ }
+
+ public void setValues(List<String> values) {
+ Validate.notNull(values);
+
+ this.values = new ArrayList<String>(values);
+ }
+
+ public void addValue(String value) {
+ values.add(value);
+ }
+
+ public List<String> getValues() {
+ if (values.isEmpty() && option.hasDefaultArgs()) {
+ return option.getDefaultArgs();
+ } else {
+ return values;
+ }
+ }
+
+ public void setSubOptions(List<CmdLineOptionInstance> subOptions) {
+ Validate.isTrue(isGroup(), "Must be group option to have subOptions");
+ Validate.notNull(subOptions, "Cannot set subOptions to NULL");
+
+ this.subOptions = new HashSet<CmdLineOptionInstance>(subOptions);
+ }
+
+ public void addSubOption(CmdLineOptionInstance subOption) {
+ Validate.isTrue(isGroup(), "Must be group option to have subOptions");
+ Validate.notNull(subOption, "Cannot add NULL subOption");
+
+ this.subOptions.add(subOption);
+ }
+
+ public Set<CmdLineOptionInstance> getSubOptions() {
+ return subOptions;
+ }
+
+ public boolean equals(Object obj) {
+ if (obj instanceof CmdLineOptionInstance) {
+ CmdLineOptionInstance compareObj = (CmdLineOptionInstance) obj;
+ return compareObj.option.equals(this.option)
+ && compareObj.values.equals(this.values);
+ } else {
+ return false;
+ }
+ }
}