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 [2/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...
Modified: oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/GroupCmdLineOption.java
URL: http://svn.apache.org/viewvc/oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/GroupCmdLineOption.java?rev=1195292&r1=1195291&r2=1195292&view=diff
==============================================================================
--- oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/GroupCmdLineOption.java (original)
+++ oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/GroupCmdLineOption.java Mon Oct 31 01:01:18 2011
@@ -24,82 +24,83 @@ import java.util.Set;
import org.apache.commons.lang.Validate;
/**
- * {@link CmdLineOption} which is a group option (i.e. supports
- * sub-{@link CmdLineOption}s.
+ * {@link CmdLineOption} which is a group option (i.e. supports sub-
+ * {@link CmdLineOption}s.
*
* @author bfoster (Brian Foster)
*/
public class GroupCmdLineOption extends SimpleCmdLineOption {
- private Set<SubOption> subOptions;
- private boolean allowAnySubOption;
+ private Set<SubOption> subOptions;
+ private boolean allowAnySubOption;
- public GroupCmdLineOption() {
- super();
- this.setHasArgs(false);
- this.setAllowAnySubOptions(false);
- subOptions = new HashSet<SubOption>();
- }
-
- public GroupCmdLineOption(String shortOption, String longOption,
- String description, boolean hasArgs) {
- super(shortOption, longOption, description, hasArgs);
- }
-
- public void setAllowAnySubOptions(boolean allowAnySubOption) {
- this.allowAnySubOption = allowAnySubOption;
- }
-
- public boolean isAllowAnySubOptions() {
- return subOptions.isEmpty() && allowAnySubOption;
- }
-
- public void setSubOptions(Set<SubOption> subOptions) {
- Validate.notNull(subOptions, "Cannot set subOptions to NULL");
-
- this.subOptions = new HashSet<SubOption>(subOptions);
- }
-
- public void addSubOption(SubOption subOption) {
- Validate.notNull(subOption, "Cannot add NULL subOption");
-
- subOptions.add(subOption);
- }
-
- public Set<SubOption> getSubOptions() {
- return subOptions;
- }
-
- public boolean hasSubOptions() {
- return subOptions != null && !subOptions.isEmpty();
- }
-
- public static class SubOption {
-
- private CmdLineOption option;
- private boolean required;
-
- public SubOption() {}
-
- public SubOption(CmdLineOption option, boolean required) {
- this.option = option;
- this.required = required;
- }
-
- public void setOption(CmdLineOption option) {
- this.option = option;
- }
-
- public CmdLineOption getOption() {
- return option;
- }
-
- public void setRequired(boolean required) {
- this.required = required;
- }
-
- public boolean isRequired() {
- return required;
- }
- }
+ public GroupCmdLineOption() {
+ super();
+ this.setHasArgs(false);
+ this.setAllowAnySubOptions(false);
+ subOptions = new HashSet<SubOption>();
+ }
+
+ public GroupCmdLineOption(String shortOption, String longOption,
+ String description, boolean hasArgs) {
+ super(shortOption, longOption, description, hasArgs);
+ }
+
+ public void setAllowAnySubOptions(boolean allowAnySubOption) {
+ this.allowAnySubOption = allowAnySubOption;
+ }
+
+ public boolean isAllowAnySubOptions() {
+ return subOptions.isEmpty() && allowAnySubOption;
+ }
+
+ public void setSubOptions(Set<SubOption> subOptions) {
+ Validate.notNull(subOptions, "Cannot set subOptions to NULL");
+
+ this.subOptions = new HashSet<SubOption>(subOptions);
+ }
+
+ public void addSubOption(SubOption subOption) {
+ Validate.notNull(subOption, "Cannot add NULL subOption");
+
+ subOptions.add(subOption);
+ }
+
+ public Set<SubOption> getSubOptions() {
+ return subOptions;
+ }
+
+ public boolean hasSubOptions() {
+ return subOptions != null && !subOptions.isEmpty();
+ }
+
+ public static class SubOption {
+
+ private CmdLineOption option;
+ private boolean required;
+
+ public SubOption() {
+ }
+
+ public SubOption(CmdLineOption option, boolean required) {
+ this.option = option;
+ this.required = required;
+ }
+
+ public void setOption(CmdLineOption option) {
+ this.option = option;
+ }
+
+ public CmdLineOption getOption() {
+ return option;
+ }
+
+ public void setRequired(boolean required) {
+ this.required = required;
+ }
+
+ public boolean isRequired() {
+ return required;
+ }
+ }
}
Modified: oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/HandleableCmdLineOption.java
URL: http://svn.apache.org/viewvc/oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/HandleableCmdLineOption.java?rev=1195292&r1=1195291&r2=1195292&view=diff
==============================================================================
--- oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/HandleableCmdLineOption.java (original)
+++ oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/HandleableCmdLineOption.java Mon Oct 31 01:01:18 2011
@@ -22,12 +22,12 @@ import org.apache.oodt.cas.cl.option.han
/**
* A {@link CmdLineOption} which has a {@link CmdLineOptionHandler} should
* implement this interface.
- *
+ *
* @author bfoster (Brian Foster)
*/
public interface HandleableCmdLineOption {
- public void setHandler(CmdLineOptionHandler handler);
+ public void setHandler(CmdLineOptionHandler handler);
- public CmdLineOptionHandler getHandler();
+ public CmdLineOptionHandler getHandler();
}
Modified: oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/HelpCmdLineOption.java
URL: http://svn.apache.org/viewvc/oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/HelpCmdLineOption.java?rev=1195292&r1=1195291&r2=1195292&view=diff
==============================================================================
--- oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/HelpCmdLineOption.java (original)
+++ oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/HelpCmdLineOption.java Mon Oct 31 01:01:18 2011
@@ -18,17 +18,17 @@ package org.apache.oodt.cas.cl.option;
/**
* The Help {@link CmdLineOption}.
- *
+ *
* @author bfoster (Brian Foster)
*/
public class HelpCmdLineOption extends SimpleCmdLineOption {
- public HelpCmdLineOption() {
- this("h", "help", "Prints help menu", false);
- }
+ public HelpCmdLineOption() {
+ this("h", "help", "Prints help menu", false);
+ }
- public HelpCmdLineOption(String shortOption, String longOption,
- String description, boolean hasArgs) {
- super(shortOption, longOption, description, hasArgs);
- }
+ public HelpCmdLineOption(String shortOption, String longOption,
+ String description, boolean hasArgs) {
+ super(shortOption, longOption, description, hasArgs);
+ }
}
Modified: oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/PrintSupportedActionsCmdLineOption.java
URL: http://svn.apache.org/viewvc/oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/PrintSupportedActionsCmdLineOption.java?rev=1195292&r1=1195291&r2=1195292&view=diff
==============================================================================
--- oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/PrintSupportedActionsCmdLineOption.java (original)
+++ oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/PrintSupportedActionsCmdLineOption.java Mon Oct 31 01:01:18 2011
@@ -17,18 +17,18 @@
package org.apache.oodt.cas.cl.option;
/**
- * The Print Supported Actions {@link CmdLineOption}.
- *
+ * The Print Supported Actions {@link CmdLineOption}.
+ *
* @author bfoster (Brian Foster)
*/
public class PrintSupportedActionsCmdLineOption extends SimpleCmdLineOption {
- public PrintSupportedActionsCmdLineOption() {
- super("psa", "printSupportedActions", "Print Supported Actions", false);
- }
+ public PrintSupportedActionsCmdLineOption() {
+ super("psa", "printSupportedActions", "Print Supported Actions", false);
+ }
- public PrintSupportedActionsCmdLineOption(String shortOption, String longOption,
- String description, boolean hasArgs) {
- super(shortOption, longOption, description, hasArgs);
- }
+ public PrintSupportedActionsCmdLineOption(String shortOption,
+ String longOption, String description, boolean hasArgs) {
+ super(shortOption, longOption, description, hasArgs);
+ }
}
Modified: oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/SimpleCmdLineOption.java
URL: http://svn.apache.org/viewvc/oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/SimpleCmdLineOption.java?rev=1195292&r1=1195291&r2=1195292&view=diff
==============================================================================
--- oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/SimpleCmdLineOption.java (original)
+++ oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/SimpleCmdLineOption.java Mon Oct 31 01:01:18 2011
@@ -25,163 +25,163 @@ import org.apache.oodt.cas.cl.option.req
/**
* {@link CmdLineOption} which implements the basic methods for any
- * {@link CmdLineOption}. Can be used as-is or extends to add
- * additional option features.
- *
+ * {@link CmdLineOption}. Can be used as-is or extends to add additional option
+ * features.
+ *
* @author bfoster (Brian Foster)
*/
public class SimpleCmdLineOption implements CmdLineOption {
- private String shortOption;
+ private String shortOption;
- private String longOption;
+ private String longOption;
- private String description;
+ private String description;
- private boolean repeating;
+ private boolean repeating;
- private String argsDescription;
-
- private boolean required;
-
- private List<RequirementRule> requirementRules;
-
- private boolean hasArgs;
-
- private List<String> defaultArgs;
-
- private boolean performAndQuit;
-
- private Class<?> type;
-
- public SimpleCmdLineOption() {
- argsDescription = "arg";
- repeating = false;
- required = false;
- hasArgs = false;
- performAndQuit = false;
- type = String.class;
- requirementRules = new ArrayList<RequirementRule>();
- }
-
- public SimpleCmdLineOption(String shortOption, String longOption,
- String description, boolean hasArgs) {
- this();
- this.shortOption = shortOption;
- this.longOption = longOption;
- this.description = description;
- this.hasArgs = hasArgs;
- }
-
- public Class<?> getType() {
- return type;
- }
-
- public void setType(Class<?> type) {
- this.type = type;
- }
-
- public String getShortOption() {
- return shortOption;
- }
-
- public void setShortOption(String shortOption) {
- this.shortOption = shortOption;
- }
-
- public String getLongOption() {
- return longOption;
- }
-
- public void setLongOption(String longOption) {
- this.longOption = longOption;
- }
-
- public String getDescription() {
- return description;
- }
-
- public void setDescription(String description) {
- this.description = description;
- }
-
- public boolean isRepeating() {
- return repeating;
- }
-
- public void setRepeating(boolean repeating) {
- this.repeating = repeating;
- }
-
- public boolean hasArgs() {
- return hasArgs;
- }
-
- public void setHasArgs(boolean hasArgs) {
- this.hasArgs = hasArgs;
- }
-
- public void setArgsDescription(String argDescription) {
- this.argsDescription = argDescription;
- }
-
- public String getArgsDescription() {
- return argsDescription;
- }
-
- public void setDefaultArgs(List<String> defaultArgs) {
- this.defaultArgs = defaultArgs;
- }
-
- public List<String> getDefaultArgs() {
- return defaultArgs;
- }
-
- public boolean hasDefaultArgs() {
- return defaultArgs != null;
- }
-
- public void setRequired(boolean required) {
- this.required = required;
- }
-
- public boolean isRequired() {
- return required;
- }
-
- public List<RequirementRule> getRequirementRules() {
- return this.requirementRules;
- }
-
- public void setRequirementRules(List<RequirementRule> requirementRules) {
- this.requirementRules = requirementRules;
- }
-
- public boolean isPerformAndQuit() {
- return performAndQuit;
- }
-
- public void setPerformAndQuit(boolean performAndQuit) {
- this.performAndQuit = performAndQuit;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (obj instanceof CmdLineOption) {
- SimpleCmdLineOption compareObj = (SimpleCmdLineOption) obj;
- return compareObj.shortOption.equals(this.shortOption)
- || compareObj.longOption.equals(this.longOption);
- } else
- return false;
- }
-
- @Override
- public int hashCode() {
- return shortOption.hashCode();
- }
-
- public String toString() {
- return "Action [longOption='" + longOption + "',shortOption='"
- + shortOption + "',description='" + description + "']";
- }
+ private String argsDescription;
+
+ private boolean required;
+
+ private List<RequirementRule> requirementRules;
+
+ private boolean hasArgs;
+
+ private List<String> defaultArgs;
+
+ private boolean performAndQuit;
+
+ private Class<?> type;
+
+ public SimpleCmdLineOption() {
+ argsDescription = "arg";
+ repeating = false;
+ required = false;
+ hasArgs = false;
+ performAndQuit = false;
+ type = String.class;
+ requirementRules = new ArrayList<RequirementRule>();
+ }
+
+ public SimpleCmdLineOption(String shortOption, String longOption,
+ String description, boolean hasArgs) {
+ this();
+ this.shortOption = shortOption;
+ this.longOption = longOption;
+ this.description = description;
+ this.hasArgs = hasArgs;
+ }
+
+ public Class<?> getType() {
+ return type;
+ }
+
+ public void setType(Class<?> type) {
+ this.type = type;
+ }
+
+ public String getShortOption() {
+ return shortOption;
+ }
+
+ public void setShortOption(String shortOption) {
+ this.shortOption = shortOption;
+ }
+
+ public String getLongOption() {
+ return longOption;
+ }
+
+ public void setLongOption(String longOption) {
+ this.longOption = longOption;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+ public boolean isRepeating() {
+ return repeating;
+ }
+
+ public void setRepeating(boolean repeating) {
+ this.repeating = repeating;
+ }
+
+ public boolean hasArgs() {
+ return hasArgs;
+ }
+
+ public void setHasArgs(boolean hasArgs) {
+ this.hasArgs = hasArgs;
+ }
+
+ public void setArgsDescription(String argDescription) {
+ this.argsDescription = argDescription;
+ }
+
+ public String getArgsDescription() {
+ return argsDescription;
+ }
+
+ public void setDefaultArgs(List<String> defaultArgs) {
+ this.defaultArgs = defaultArgs;
+ }
+
+ public List<String> getDefaultArgs() {
+ return defaultArgs;
+ }
+
+ public boolean hasDefaultArgs() {
+ return defaultArgs != null;
+ }
+
+ public void setRequired(boolean required) {
+ this.required = required;
+ }
+
+ public boolean isRequired() {
+ return required;
+ }
+
+ public List<RequirementRule> getRequirementRules() {
+ return this.requirementRules;
+ }
+
+ public void setRequirementRules(List<RequirementRule> requirementRules) {
+ this.requirementRules = requirementRules;
+ }
+
+ public boolean isPerformAndQuit() {
+ return performAndQuit;
+ }
+
+ public void setPerformAndQuit(boolean performAndQuit) {
+ this.performAndQuit = performAndQuit;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (obj instanceof CmdLineOption) {
+ SimpleCmdLineOption compareObj = (SimpleCmdLineOption) obj;
+ return compareObj.shortOption.equals(this.shortOption)
+ || compareObj.longOption.equals(this.longOption);
+ } else
+ return false;
+ }
+
+ @Override
+ public int hashCode() {
+ return shortOption.hashCode();
+ }
+
+ public String toString() {
+ return "Action [longOption='" + longOption + "',shortOption='"
+ + shortOption + "',description='" + description + "']";
+ }
}
Modified: oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/ValidatableCmdLineOption.java
URL: http://svn.apache.org/viewvc/oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/ValidatableCmdLineOption.java?rev=1195292&r1=1195291&r2=1195292&view=diff
==============================================================================
--- oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/ValidatableCmdLineOption.java (original)
+++ oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/ValidatableCmdLineOption.java Mon Oct 31 01:01:18 2011
@@ -23,15 +23,15 @@ import java.util.List;
import org.apache.oodt.cas.cl.option.validator.CmdLineOptionValidator;
/**
- * A {@link CmdLineOption} which has {@link CmdLineOptionValidator}s
- * should implement this interface.
+ * A {@link CmdLineOption} which has {@link CmdLineOptionValidator}s should
+ * implement this interface.
*
* @author bfoster (Brian Foster)
*/
public interface ValidatableCmdLineOption {
- public void setValidators(List<CmdLineOptionValidator> validators);
+ public void setValidators(List<CmdLineOptionValidator> validators);
- public List<CmdLineOptionValidator> getValidators();
+ public List<CmdLineOptionValidator> getValidators();
}
Modified: oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/handler/ApplyToAction.java
URL: http://svn.apache.org/viewvc/oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/handler/ApplyToAction.java?rev=1195292&r1=1195291&r2=1195292&view=diff
==============================================================================
--- oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/handler/ApplyToAction.java (original)
+++ oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/handler/ApplyToAction.java Mon Oct 31 01:01:18 2011
@@ -17,36 +17,37 @@
package org.apache.oodt.cas.cl.option.handler;
/**
- * Mapping of {@link CmdLineAction} name to its method which should be called
- * by {@link ApplyToActionHandler} when injecting argument value.
- *
+ * Mapping of {@link CmdLineAction} name to its method which should be called by
+ * {@link ApplyToActionHandler} when injecting argument value.
+ *
* @author bfoster (Brian Foster)
*/
public class ApplyToAction {
- private String actionName;
- private String methodName;
+ private String actionName;
+ private String methodName;
- public ApplyToAction() {}
+ public ApplyToAction() {
+ }
- public ApplyToAction(String actionName, String methodName) {
- this.actionName = actionName;
- this.methodName = methodName;
- }
-
- public String getActionName() {
- return actionName;
- }
-
- public void setActionName(String actionName) {
- this.actionName = actionName;
- }
-
- public String getMethodName() {
- return methodName;
- }
-
- public void setMethodName(String methodName) {
- this.methodName = methodName;
- }
+ public ApplyToAction(String actionName, String methodName) {
+ this.actionName = actionName;
+ this.methodName = methodName;
+ }
+
+ public String getActionName() {
+ return actionName;
+ }
+
+ public void setActionName(String actionName) {
+ this.actionName = actionName;
+ }
+
+ public String getMethodName() {
+ return methodName;
+ }
+
+ public void setMethodName(String methodName) {
+ this.methodName = methodName;
+ }
}
Modified: oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/handler/ApplyToActionHandler.java
URL: http://svn.apache.org/viewvc/oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/handler/ApplyToActionHandler.java?rev=1195292&r1=1195291&r2=1195292&view=diff
==============================================================================
--- oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/handler/ApplyToActionHandler.java (original)
+++ oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/handler/ApplyToActionHandler.java Mon Oct 31 01:01:18 2011
@@ -35,61 +35,61 @@ import org.apache.oodt.cas.cl.option.Cmd
import com.google.common.annotations.VisibleForTesting;
/**
- * {@link CmdLineOptionHandler} which applies {@link CmdLineOption} values
- * to given {@link CmdLineAction}.
- *
+ * {@link CmdLineOptionHandler} which applies {@link CmdLineOption} values to
+ * given {@link CmdLineAction}.
+ *
* @author bfoster (Brian Foster)
*/
public class ApplyToActionHandler implements CmdLineOptionHandler {
- private List<ApplyToAction> applyToActions;
+ private List<ApplyToAction> applyToActions;
- public void setApplyToActions(List<ApplyToAction> applyToActions) {
- this.applyToActions = applyToActions;
- }
-
- public List<ApplyToAction> getApplyToActions() {
- return applyToActions;
- }
-
- public void handleOption(CmdLineAction action,
- CmdLineOptionInstance optionInstance) {
- try {
- Class<?> type = optionInstance.getOption().getType();
- List<?> vals = (optionInstance.getValues().isEmpty()) ? convertToType(
- Arrays.asList(new String[] { "true" }), type = Boolean.TYPE)
- : convertToType(optionInstance.getValues(), type);
- String methodName = getMethodName(action.getName());
- if (methodName != null) {
- action.getClass()
- .getMethod(methodName, type)
- .invoke(action, vals.toArray(new Object[vals.size()]));
- } else {
- action
- .getClass()
- .getMethod(
- "set" + StringUtils.capitalize(
- optionInstance.getOption().getLongOption()), type)
- .invoke(action, vals.toArray(new Object[vals.size()]));
- }
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
- }
-
- @VisibleForTesting
- protected String getMethodName(String actionName) {
- if (applyToActions != null) {
- for (ApplyToAction applyToAction : applyToActions) {
- if (applyToAction.getActionName().equals(actionName)) {
- return applyToAction.getMethodName();
- }
- }
- }
- return null;
- }
-
- public String getHelp(CmdLineOption option) {
- return "Will invoke 'set" + option.getLongOption() + "' on action selected";
- }
+ public void setApplyToActions(List<ApplyToAction> applyToActions) {
+ this.applyToActions = applyToActions;
+ }
+
+ public List<ApplyToAction> getApplyToActions() {
+ return applyToActions;
+ }
+
+ public void handleOption(CmdLineAction action,
+ CmdLineOptionInstance optionInstance) {
+ try {
+ Class<?> type = optionInstance.getOption().getType();
+ List<?> vals = (optionInstance.getValues().isEmpty()) ? convertToType(
+ Arrays.asList(new String[] { "true" }), type = Boolean.TYPE)
+ : convertToType(optionInstance.getValues(), type);
+ String methodName = getMethodName(action.getName());
+ if (methodName != null) {
+ action.getClass().getMethod(methodName, type)
+ .invoke(action, vals.toArray(new Object[vals.size()]));
+ } else {
+ action.getClass()
+ .getMethod(
+ "set"
+ + StringUtils.capitalize(optionInstance
+ .getOption().getLongOption()), type)
+ .invoke(action, vals.toArray(new Object[vals.size()]));
+ }
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ @VisibleForTesting
+ protected String getMethodName(String actionName) {
+ if (applyToActions != null) {
+ for (ApplyToAction applyToAction : applyToActions) {
+ if (applyToAction.getActionName().equals(actionName)) {
+ return applyToAction.getMethodName();
+ }
+ }
+ }
+ return null;
+ }
+
+ public String getHelp(CmdLineOption option) {
+ return "Will invoke 'set" + option.getLongOption()
+ + "' on action selected";
+ }
}
Modified: oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/handler/CmdLineOptionHandler.java
URL: http://svn.apache.org/viewvc/oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/handler/CmdLineOptionHandler.java?rev=1195292&r1=1195291&r2=1195292&view=diff
==============================================================================
--- oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/handler/CmdLineOptionHandler.java (original)
+++ oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/handler/CmdLineOptionHandler.java Mon Oct 31 01:01:18 2011
@@ -23,20 +23,24 @@ import org.apache.oodt.cas.cl.option.Cmd
/**
* Handles a {@link CmdLineOption}'s values in relation to given
- * {@link CmdLineAction}s.
- *
+ * {@link CmdLineAction}s.
+ *
* @author bfoster (Brian Foster)
*/
public interface CmdLineOptionHandler {
- public abstract void handleOption(CmdLineAction selectedAction, CmdLineOptionInstance optionInstance);
+ public abstract void handleOption(CmdLineAction selectedAction,
+ CmdLineOptionInstance optionInstance);
- /**
- * Gets the {@link CmdLineOptionHandler}s help message when associated with given {@link CmdLineOption}.
- *
- * @param option The {@link CmdLineOption} to which this {@link CmdLineOptionHandler} was associated with
- * @return The help message for this {@link CmdLineOptionHandler}
- */
- public abstract String getHelp(CmdLineOption option);
+ /**
+ * Gets the {@link CmdLineOptionHandler}s help message when associated with
+ * given {@link CmdLineOption}.
+ *
+ * @param option
+ * The {@link CmdLineOption} to which this
+ * {@link CmdLineOptionHandler} was associated with
+ * @return The help message for this {@link CmdLineOptionHandler}
+ */
+ public abstract String getHelp(CmdLineOption option);
}
Modified: oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/require/ActionDependencyRule.java
URL: http://svn.apache.org/viewvc/oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/require/ActionDependencyRule.java?rev=1195292&r1=1195291&r2=1195292&view=diff
==============================================================================
--- oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/require/ActionDependencyRule.java (original)
+++ oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/require/ActionDependencyRule.java Mon Oct 31 01:01:18 2011
@@ -29,39 +29,40 @@ import org.apache.oodt.cas.cl.action.Cmd
* @author bfoster (Brian Foster)
*/
public class ActionDependencyRule implements RequirementRule {
- String actionName;
- Relation relation;
+ String actionName;
+ Relation relation;
- public ActionDependencyRule() {}
+ public ActionDependencyRule() {
+ }
- public ActionDependencyRule(String actionName, Relation relation) {
- this.actionName = actionName;
- this.relation = relation;
- }
-
- public String getActionName() {
- return actionName;
- }
-
- public void setActionName(String actionName) {
- this.actionName = actionName;
- }
-
- public Relation getRelation() {
- return relation;
- }
-
- public void setRelation(Relation relation) {
- this.relation = relation;
- }
-
- public Relation getRelation(CmdLineAction action) {
- Validate.notNull(actionName);
- Validate.notNull(relation);
-
- if (action.getName().equals(actionName)) {
- return relation;
- }
- return Relation.NONE;
- }
+ public ActionDependencyRule(String actionName, Relation relation) {
+ this.actionName = actionName;
+ this.relation = relation;
+ }
+
+ public String getActionName() {
+ return actionName;
+ }
+
+ public void setActionName(String actionName) {
+ this.actionName = actionName;
+ }
+
+ public Relation getRelation() {
+ return relation;
+ }
+
+ public void setRelation(Relation relation) {
+ this.relation = relation;
+ }
+
+ public Relation getRelation(CmdLineAction action) {
+ Validate.notNull(actionName);
+ Validate.notNull(relation);
+
+ if (action.getName().equals(actionName)) {
+ return relation;
+ }
+ return Relation.NONE;
+ }
}
Modified: oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/require/RequirementRule.java
URL: http://svn.apache.org/viewvc/oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/require/RequirementRule.java?rev=1195292&r1=1195291&r2=1195292&view=diff
==============================================================================
--- oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/require/RequirementRule.java (original)
+++ oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/require/RequirementRule.java Mon Oct 31 01:01:18 2011
@@ -20,15 +20,17 @@ package org.apache.oodt.cas.cl.option.re
import org.apache.oodt.cas.cl.action.CmdLineAction;
/**
- * A {@link CmdLineOption} requirement rule which specifies if it is
- * required, optional, or not required at all.
- *
+ * A {@link CmdLineOption} requirement rule which specifies if it is required,
+ * optional, or not required at all.
+ *
* @author bfoster (Brian Foster)
*/
public interface RequirementRule {
- public enum Relation { REQUIRED, OPTIONAL, NONE }
+ public enum Relation {
+ REQUIRED, OPTIONAL, NONE
+ }
- public Relation getRelation(CmdLineAction action);
+ public Relation getRelation(CmdLineAction action);
}
Modified: oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/store/CmdLineOptionStore.java
URL: http://svn.apache.org/viewvc/oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/store/CmdLineOptionStore.java?rev=1195292&r1=1195291&r2=1195292&view=diff
==============================================================================
--- oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/store/CmdLineOptionStore.java (original)
+++ oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/store/CmdLineOptionStore.java Mon Oct 31 01:01:18 2011
@@ -24,11 +24,11 @@ import org.apache.oodt.cas.cl.option.Cmd
/**
* Storage for loading supported {@link CmdLineOption}s.
- *
+ *
* @author bfoster (Brian Foster)
*/
public interface CmdLineOptionStore {
- public Set<CmdLineOption> loadSupportedOptions();
+ public Set<CmdLineOption> loadSupportedOptions();
}
Modified: oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/store/CmdLineOptionStoreFactory.java
URL: http://svn.apache.org/viewvc/oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/store/CmdLineOptionStoreFactory.java?rev=1195292&r1=1195291&r2=1195292&view=diff
==============================================================================
--- oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/store/CmdLineOptionStoreFactory.java (original)
+++ oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/store/CmdLineOptionStoreFactory.java Mon Oct 31 01:01:18 2011
@@ -18,11 +18,11 @@ package org.apache.oodt.cas.cl.option.st
/**
* Factory for creating {@link CmdLineOptionStore}s.
- *
+ *
* @author bfoster (Brian Foster)
*/
public interface CmdLineOptionStoreFactory {
- public CmdLineOptionStore createStore();
+ public CmdLineOptionStore createStore();
}
Modified: oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/store/spring/SpringCmdLineOptionStore.java
URL: http://svn.apache.org/viewvc/oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/store/spring/SpringCmdLineOptionStore.java?rev=1195292&r1=1195291&r2=1195292&view=diff
==============================================================================
--- oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/store/spring/SpringCmdLineOptionStore.java (original)
+++ oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/store/spring/SpringCmdLineOptionStore.java Mon Oct 31 01:01:18 2011
@@ -31,25 +31,25 @@ import org.springframework.context.suppo
/**
* Spring Framework based {@link CmdLineOptionStore}.
- *
+ *
* @author bfoster (Brian Foster)
*/
public class SpringCmdLineOptionStore implements CmdLineOptionStore {
- private ApplicationContext appContext;
+ private ApplicationContext appContext;
- public SpringCmdLineOptionStore(String springConfig) {
- appContext = new FileSystemXmlApplicationContext(springConfig);
- }
+ public SpringCmdLineOptionStore(String springConfig) {
+ appContext = new FileSystemXmlApplicationContext(springConfig);
+ }
- public Set<CmdLineOption> loadSupportedOptions() {
- @SuppressWarnings("unchecked")
- Map<String, CmdLineOption> optionsMap = appContext
- .getBeansOfType(CmdLineOption.class);
- return new HashSet<CmdLineOption>(optionsMap.values());
- }
+ public Set<CmdLineOption> loadSupportedOptions() {
+ @SuppressWarnings("unchecked")
+ Map<String, CmdLineOption> optionsMap = appContext
+ .getBeansOfType(CmdLineOption.class);
+ return new HashSet<CmdLineOption>(optionsMap.values());
+ }
- protected ApplicationContext getApplicationContext() {
- return appContext;
- }
+ protected ApplicationContext getApplicationContext() {
+ return appContext;
+ }
}
Modified: oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/store/spring/SpringCmdLineOptionStoreFactory.java
URL: http://svn.apache.org/viewvc/oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/store/spring/SpringCmdLineOptionStoreFactory.java?rev=1195292&r1=1195291&r2=1195292&view=diff
==============================================================================
--- oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/store/spring/SpringCmdLineOptionStoreFactory.java (original)
+++ oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/store/spring/SpringCmdLineOptionStoreFactory.java Mon Oct 31 01:01:18 2011
@@ -21,26 +21,28 @@ import org.apache.oodt.cas.cl.option.sto
/**
* Factory for creating {@link SpringCmdLineOptionStore}.
- *
+ *
* @author bfoster (Brian Foster)
*/
-public class SpringCmdLineOptionStoreFactory implements CmdLineOptionStoreFactory {
+public class SpringCmdLineOptionStoreFactory implements
+ CmdLineOptionStoreFactory {
- private String config;
+ private String config;
- public SpringCmdLineOptionStoreFactory() {
- config = System.getProperty("org.apache.oodt.cas.cl.option.store.spring.config", null);
- }
+ public SpringCmdLineOptionStoreFactory() {
+ config = System.getProperty(
+ "org.apache.oodt.cas.cl.option.store.spring.config", null);
+ }
- public SpringCmdLineOptionStore createStore() {
- if (config != null) {
- return new SpringCmdLineOptionStore(config);
- } else {
- return null;
- }
- }
+ public SpringCmdLineOptionStore createStore() {
+ if (config != null) {
+ return new SpringCmdLineOptionStore(config);
+ } else {
+ return null;
+ }
+ }
- public void setConfig(String config) {
- this.config = config;
- }
+ public void setConfig(String config) {
+ this.config = config;
+ }
}
Modified: oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/validator/AllowedArgsCmdLineOptionValidator.java
URL: http://svn.apache.org/viewvc/oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/validator/AllowedArgsCmdLineOptionValidator.java?rev=1195292&r1=1195291&r2=1195292&view=diff
==============================================================================
--- oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/validator/AllowedArgsCmdLineOptionValidator.java (original)
+++ oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/validator/AllowedArgsCmdLineOptionValidator.java Mon Oct 31 01:01:18 2011
@@ -27,38 +27,38 @@ import org.apache.oodt.cas.cl.option.Cmd
/**
* A {@link CmdLineOptionValidator} which check args against a supplied list of
* valid allowed arguments.
- *
+ *
* @author bfoster (Brian Foster)
*/
public class AllowedArgsCmdLineOptionValidator implements
- CmdLineOptionValidator {
+ CmdLineOptionValidator {
- private List<String> allowedArgs;
+ private List<String> allowedArgs;
- public AllowedArgsCmdLineOptionValidator() {
- this.allowedArgs = new LinkedList<String>();
- }
-
- public boolean 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 "
- + optionInst.getOption().getLongOption() + " - Allowed values = "
- + this.getAllowedArgs());
- return false;
- }
- }
- return true;
- }
-
- public List<String> getAllowedArgs() {
- return allowedArgs;
- }
-
- public void setAllowedArgs(List<String> allowedArgs) {
- this.allowedArgs = allowedArgs;
- }
+ public AllowedArgsCmdLineOptionValidator() {
+ this.allowedArgs = new LinkedList<String>();
+ }
+
+ public boolean 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 "
+ + optionInst.getOption().getLongOption()
+ + " - Allowed values = " + this.getAllowedArgs());
+ return false;
+ }
+ }
+ return true;
+ }
+
+ public List<String> getAllowedArgs() {
+ return allowedArgs;
+ }
+
+ public void setAllowedArgs(List<String> allowedArgs) {
+ this.allowedArgs = allowedArgs;
+ }
}
Modified: oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/validator/ArgRegExpCmdLineOptionValidator.java
URL: http://svn.apache.org/viewvc/oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/validator/ArgRegExpCmdLineOptionValidator.java?rev=1195292&r1=1195291&r2=1195292&view=diff
==============================================================================
--- oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/validator/ArgRegExpCmdLineOptionValidator.java (original)
+++ oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/validator/ArgRegExpCmdLineOptionValidator.java Mon Oct 31 01:01:18 2011
@@ -26,29 +26,27 @@ import org.apache.oodt.cas.cl.option.Cmd
/**
* Performs validation on option instances via allowed args which are regular
* expressions for allowed argument values.
- *
+ *
* @author bfoster (Brian Foster)
*/
public class ArgRegExpCmdLineOptionValidator extends
- AllowedArgsCmdLineOptionValidator {
+ AllowedArgsCmdLineOptionValidator {
- @Override
- public boolean validate(CmdLineOptionInstance optionInst) {
- Validate.notNull(optionInst);
-
- TOP:
- for (String value : optionInst.getValues()) {
- for (String regex : getAllowedArgs()) {
- if (Pattern.matches(regex, value)) {
- continue TOP;
- }
- }
- LOG.severe("Option1 value " + value + " is not allowed for option "
- + optionInst.getOption().getLongOption() + " - Allowed values = "
- + getAllowedArgs());
- return false;
- }
- return true;
- }
+ @Override
+ public boolean validate(CmdLineOptionInstance optionInst) {
+ Validate.notNull(optionInst);
+ TOP: for (String value : optionInst.getValues()) {
+ for (String regex : getAllowedArgs()) {
+ if (Pattern.matches(regex, value)) {
+ continue TOP;
+ }
+ }
+ LOG.severe("Option1 value " + value + " is not allowed for option "
+ + optionInst.getOption().getLongOption()
+ + " - Allowed values = " + getAllowedArgs());
+ return false;
+ }
+ return true;
+ }
}
Modified: oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/validator/ClassExistsCmdLineOptionValidator.java
URL: http://svn.apache.org/viewvc/oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/validator/ClassExistsCmdLineOptionValidator.java?rev=1195292&r1=1195291&r2=1195292&view=diff
==============================================================================
--- oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/validator/ClassExistsCmdLineOptionValidator.java (original)
+++ oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/validator/ClassExistsCmdLineOptionValidator.java Mon Oct 31 01:01:18 2011
@@ -22,25 +22,25 @@ import org.apache.oodt.cas.cl.option.Cmd
/**
* Validates arguments which are checked to see if they are valid classpaths.
- *
+ *
* @author bfoster (Brian Foster)
*/
public class ClassExistsCmdLineOptionValidator implements
- CmdLineOptionValidator {
+ CmdLineOptionValidator {
- public boolean 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() + " is not a valid class");
- return false;
- }
- }
- return true;
- }
+ public boolean 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()
+ + " is not a valid class");
+ return false;
+ }
+ }
+ return true;
+ }
}
Modified: oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/validator/CmdLineOptionValidator.java
URL: http://svn.apache.org/viewvc/oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/validator/CmdLineOptionValidator.java?rev=1195292&r1=1195291&r2=1195292&view=diff
==============================================================================
--- oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/validator/CmdLineOptionValidator.java (original)
+++ oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/validator/CmdLineOptionValidator.java Mon Oct 31 01:01:18 2011
@@ -14,8 +14,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
-
package org.apache.oodt.cas.cl.option.validator;
//JDK imports
@@ -25,17 +23,14 @@ import java.util.logging.Logger;
import org.apache.oodt.cas.cl.option.CmdLineOptionInstance;
/**
+ * Validator for specified values of {@link CmdLineOption}s.
*
- * @author bfoster
- * @version $Revision$
- *
- * <p>Describe your class here</p>.
+ * @author bfoster (Brian Foster)
*/
public interface CmdLineOptionValidator {
- static Logger LOG = Logger
- .getLogger(CmdLineOptionValidator.class.getName());
+ static Logger LOG = Logger.getLogger(CmdLineOptionValidator.class.getName());
- public boolean validate(CmdLineOptionInstance optionInst);
+ public boolean validate(CmdLineOptionInstance optionInst);
}
Modified: oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/validator/FileExistCmdLineOptionValidator.java
URL: http://svn.apache.org/viewvc/oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/validator/FileExistCmdLineOptionValidator.java?rev=1195292&r1=1195291&r2=1195292&view=diff
==============================================================================
--- oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/validator/FileExistCmdLineOptionValidator.java (original)
+++ oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/validator/FileExistCmdLineOptionValidator.java Mon Oct 31 01:01:18 2011
@@ -24,24 +24,24 @@ import org.apache.commons.lang.Validate;
import org.apache.oodt.cas.cl.option.CmdLineOptionInstance;
/**
- * A {@link CmdLineOptionValidator} which checks args if they are existing files.
- *
+ * A {@link CmdLineOptionValidator} which checks args if they are existing
+ * files.
+ *
* @author bfoster (Brian Foster)
*/
public class FileExistCmdLineOptionValidator implements CmdLineOptionValidator {
- public boolean 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()
- + " is not an existing file");
- return false;
- }
- }
- return true;
- }
+ public boolean 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()
+ + " is not an existing file");
+ return false;
+ }
+ }
+ return true;
+ }
}
Modified: oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/validator/NoRestrictionsCmdLineOptionValidator.java
URL: http://svn.apache.org/viewvc/oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/validator/NoRestrictionsCmdLineOptionValidator.java?rev=1195292&r1=1195291&r2=1195292&view=diff
==============================================================================
--- oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/validator/NoRestrictionsCmdLineOptionValidator.java (original)
+++ oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/validator/NoRestrictionsCmdLineOptionValidator.java Mon Oct 31 01:01:18 2011
@@ -21,14 +21,13 @@ import org.apache.oodt.cas.cl.option.Cmd
/**
* A {@link CmdLineOptionValidator} which always returns true.
- *
+ *
* @author bfoster (Brian Foster)
*/
public class NoRestrictionsCmdLineOptionValidator implements
- CmdLineOptionValidator {
-
- public boolean validate(CmdLineOptionInstance optionInst) {
- return true;
- }
+ CmdLineOptionValidator {
+ public boolean validate(CmdLineOptionInstance optionInst) {
+ return true;
+ }
}
Modified: oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/parser/CmdLineOptionParser.java
URL: http://svn.apache.org/viewvc/oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/parser/CmdLineOptionParser.java?rev=1195292&r1=1195291&r2=1195292&view=diff
==============================================================================
--- oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/parser/CmdLineOptionParser.java (original)
+++ oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/parser/CmdLineOptionParser.java Mon Oct 31 01:01:18 2011
@@ -33,6 +33,7 @@ import org.apache.oodt.cas.cl.util.Args;
*/
public interface CmdLineOptionParser {
- public Set<CmdLineOptionInstance> parse(Args args, Set<CmdLineOption> validOptions) throws IOException;
+ public Set<CmdLineOptionInstance> parse(Args args,
+ Set<CmdLineOption> validOptions) throws IOException;
}
Modified: oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/parser/StdCmdLineOptionParser.java
URL: http://svn.apache.org/viewvc/oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/parser/StdCmdLineOptionParser.java?rev=1195292&r1=1195291&r2=1195292&view=diff
==============================================================================
--- oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/parser/StdCmdLineOptionParser.java (original)
+++ oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/parser/StdCmdLineOptionParser.java Mon Oct 31 01:01:18 2011
@@ -51,157 +51,161 @@ import com.google.common.annotations.Vis
*/
public class StdCmdLineOptionParser implements CmdLineOptionParser {
- public Set<CmdLineOptionInstance> parse(Args args,
- Set<CmdLineOption> validOptions) throws IOException {
- HashSet<CmdLineOptionInstance> optionInstances = new HashSet<CmdLineOptionInstance>();
-
- CmdLineOption helpOption = findHelpOption(validOptions);
- if (helpOption == null) {
- throw new OptionHelpException(
- "Must specify a help option in set of valid options");
- }
-
- if (args.numArgs() < 1) {
- throw new OptionHelpException("Must specify options : type -"
- + helpOption.getShortOption() + " or --" + helpOption.getLongOption()
- + " for info");
- }
-
- Stack<CmdLineOptionInstance> groupOptions = new Stack<CmdLineOptionInstance>();
- for (String arg : args) {
-
- if (isOption(arg)) {
-
- // check if option is a valid one
- CmdLineOption option = getOptionByName(getOptionName(arg), validOptions);
- if (option == null) {
- throw new IOException("Invalid option: '" + arg + "'");
- }
-
- // read found option
- CmdLineOptionInstance specifiedOption = getOption(args, option);
-
- // Check if we are currently loading subOptions.
- if (!groupOptions.isEmpty()) {
-
- CmdLineOptionInstance currentGroup = groupOptions.peek();
-
- // Check if option is 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 IOException(
- "Missing the following required subOptions for '"
- + currentGroup.getOption() + "': "
- + sortOptionsByRequiredStatus(requiredSubOptions));
-
- } else {
-
- // pop group and add to list of specified options.
- optionInstances.add(groupOptions.pop());
- }
- } else {
-
- // Add option to current group subOptions.
- currentGroup.addSubOption(specifiedOption);
- continue;
-
- }
- }
-
- if (option instanceof GroupCmdLineOption) {
-
- // Push group as current group.
- groupOptions.push(specifiedOption);
-
- } else {
-
- // Option good to go.
- optionInstances.add(specifiedOption);
- }
- } else {
- throw new IOException("Invalid argument: '" + arg + "'");
- }
- }
- while (!groupOptions.isEmpty()) {
- CmdLineOptionInstance currentGroup = groupOptions.pop();
- Set<CmdLineOption> requiredSubOptions = verifyGroupHasRequiredSubOptions(currentGroup);
- if (!requiredSubOptions.isEmpty()) {
- throw new IOException("Missing the following required subOptions for '"
- + currentGroup.getOption() + "': "
- + sortOptionsByRequiredStatus(requiredSubOptions));
-
- } else {
- optionInstances.add(currentGroup);
- }
- }
- return optionInstances;
- }
-
- @VisibleForTesting
- /* package */static Set<CmdLineOption> verifyGroupHasRequiredSubOptions(
- CmdLineOptionInstance group) {
- Validate.isTrue(group.isGroup());
-
- Set<CmdLineOption> missingSubOptions = new HashSet<CmdLineOption>();
- TOP: for (SubOption subOption : ((GroupCmdLineOption) group.getOption())
- .getSubOptions()) {
- if (subOption.isRequired()) {
- for (CmdLineOptionInstance specifiedSubOption : group.getSubOptions()) {
- if (specifiedSubOption.getOption().equals(subOption.getOption())) {
- continue TOP;
- }
- }
- missingSubOptions.add(subOption.getOption());
- }
- }
- return missingSubOptions;
- }
-
- @VisibleForTesting
- /* package */static CmdLineOptionInstance getOption(Args args,
- CmdLineOption option) throws IOException {
- CmdLineOptionInstance specifiedOption = new CmdLineOptionInstance();
- specifiedOption.setOption(option);
- List<String> values = getValues(args);
- if (option.hasArgs()) {
- if (!values.isEmpty()) {
- specifiedOption.setValues(values);
- } else if (!option.hasDefaultArgs()) {
- throw new IOException("Option " + option + " requires args");
- }
- } else if (!option.hasArgs() && !values.isEmpty()) {
- throw new IOException("Option " + option + " does not support args");
- }
- return specifiedOption;
- }
-
- @VisibleForTesting
- /* package */static List<String> getValues(Args args) {
- List<String> values = new ArrayList<String>();
- String nextValue = args.getCurrentArg();
- while (nextValue != null && !isOption(nextValue)) {
- values.add(nextValue);
- nextValue = args.incrementAndGet();
- }
- return values;
- }
-
- @VisibleForTesting
- /* package */static boolean isOption(String arg) {
- return (arg.startsWith("-"));
- }
-
- @VisibleForTesting
- /* package */static String getOptionName(String arg) {
- if (arg.startsWith("--")) {
- return arg.substring(2);
- } else if (arg.startsWith("-")) {
- return arg.substring(1);
- } else {
- return null;
- }
- }
+ public Set<CmdLineOptionInstance> parse(Args args,
+ Set<CmdLineOption> validOptions) throws IOException {
+ HashSet<CmdLineOptionInstance> optionInstances = new HashSet<CmdLineOptionInstance>();
+
+ CmdLineOption helpOption = findHelpOption(validOptions);
+ if (helpOption == null) {
+ throw new OptionHelpException(
+ "Must specify a help option in set of valid options");
+ }
+
+ if (args.numArgs() < 1) {
+ throw new OptionHelpException("Must specify options : type -"
+ + helpOption.getShortOption() + " or --"
+ + helpOption.getLongOption() + " for info");
+ }
+
+ Stack<CmdLineOptionInstance> groupOptions = new Stack<CmdLineOptionInstance>();
+ for (String arg : args) {
+
+ if (isOption(arg)) {
+
+ // check if option is a valid one
+ CmdLineOption option = getOptionByName(getOptionName(arg),
+ validOptions);
+ if (option == null) {
+ throw new IOException("Invalid option: '" + arg + "'");
+ }
+
+ // read found option
+ CmdLineOptionInstance specifiedOption = getOption(args, option);
+
+ // Check if we are currently loading subOptions.
+ if (!groupOptions.isEmpty()) {
+
+ CmdLineOptionInstance currentGroup = groupOptions.peek();
+
+ // Check if option is 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 IOException(
+ "Missing the following required subOptions for '"
+ + currentGroup.getOption()
+ + "': "
+ + sortOptionsByRequiredStatus(requiredSubOptions));
+
+ } else {
+
+ // pop group and add to list of specified options.
+ optionInstances.add(groupOptions.pop());
+ }
+ } else {
+
+ // Add option to current group subOptions.
+ currentGroup.addSubOption(specifiedOption);
+ continue;
+
+ }
+ }
+
+ if (option instanceof GroupCmdLineOption) {
+
+ // Push group as current group.
+ groupOptions.push(specifiedOption);
+
+ } else {
+
+ // Option good to go.
+ optionInstances.add(specifiedOption);
+ }
+ } else {
+ throw new IOException("Invalid argument: '" + arg + "'");
+ }
+ }
+ while (!groupOptions.isEmpty()) {
+ CmdLineOptionInstance currentGroup = groupOptions.pop();
+ Set<CmdLineOption> requiredSubOptions = verifyGroupHasRequiredSubOptions(currentGroup);
+ if (!requiredSubOptions.isEmpty()) {
+ throw new IOException(
+ "Missing the following required subOptions for '"
+ + currentGroup.getOption() + "': "
+ + sortOptionsByRequiredStatus(requiredSubOptions));
+
+ } else {
+ optionInstances.add(currentGroup);
+ }
+ }
+ return optionInstances;
+ }
+
+ @VisibleForTesting
+ /* package */static Set<CmdLineOption> verifyGroupHasRequiredSubOptions(
+ CmdLineOptionInstance group) {
+ Validate.isTrue(group.isGroup());
+
+ Set<CmdLineOption> missingSubOptions = new HashSet<CmdLineOption>();
+ TOP: for (SubOption subOption : ((GroupCmdLineOption) group.getOption())
+ .getSubOptions()) {
+ if (subOption.isRequired()) {
+ for (CmdLineOptionInstance specifiedSubOption : group
+ .getSubOptions()) {
+ if (specifiedSubOption.getOption().equals(subOption.getOption())) {
+ continue TOP;
+ }
+ }
+ missingSubOptions.add(subOption.getOption());
+ }
+ }
+ return missingSubOptions;
+ }
+
+ @VisibleForTesting
+ /* package */static CmdLineOptionInstance getOption(Args args,
+ CmdLineOption option) throws IOException {
+ CmdLineOptionInstance specifiedOption = new CmdLineOptionInstance();
+ specifiedOption.setOption(option);
+ List<String> values = getValues(args);
+ if (option.hasArgs()) {
+ if (!values.isEmpty()) {
+ specifiedOption.setValues(values);
+ } else if (!option.hasDefaultArgs()) {
+ throw new IOException("Option " + option + " requires args");
+ }
+ } else if (!option.hasArgs() && !values.isEmpty()) {
+ throw new IOException("Option " + option + " does not support args");
+ }
+ return specifiedOption;
+ }
+
+ @VisibleForTesting
+ /* package */static List<String> getValues(Args args) {
+ List<String> values = new ArrayList<String>();
+ String nextValue = args.getCurrentArg();
+ while (nextValue != null && !isOption(nextValue)) {
+ values.add(nextValue);
+ nextValue = args.incrementAndGet();
+ }
+ return values;
+ }
+
+ @VisibleForTesting
+ /* package */static boolean isOption(String arg) {
+ return (arg.startsWith("-"));
+ }
+
+ @VisibleForTesting
+ /* package */static String getOptionName(String arg) {
+ if (arg.startsWith("--")) {
+ return arg.substring(2);
+ } else if (arg.startsWith("-")) {
+ return arg.substring(1);
+ } else {
+ return null;
+ }
+ }
}
Modified: oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/util/Args.java
URL: http://svn.apache.org/viewvc/oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/util/Args.java?rev=1195292&r1=1195291&r2=1195292&view=diff
==============================================================================
--- oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/util/Args.java (original)
+++ oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/util/Args.java Mon Oct 31 01:01:18 2011
@@ -31,85 +31,85 @@ import org.apache.commons.lang.Validate;
* @author bfoster (Brian Foster)
*/
public class Args implements Iterable<String> {
- private int curIndex;
- private String[] args;
+ private int curIndex;
+ private String[] args;
- public Args(String[] args) {
- Validate.notNull(args);
+ public Args(String[] args) {
+ Validate.notNull(args);
- curIndex = 0;
- this.args = args;
- }
-
- public String[] getArgs() {
- return args;
- }
-
- public String[] getArgsLeft() {
- return Arrays.copyOfRange(args, curIndex, args.length);
- }
-
- public int getCurrentIndex() {
- return curIndex;
- }
-
- public void incrementIndex() {
- curIndex++;
- }
-
- public void descrementIndex() {
- curIndex--;
- }
-
- public String incrementAndGet() {
- incrementIndex();
- return getCurrentArg();
- }
-
- public String getAndIncrement() {
- String next = getCurrentArg();
- incrementIndex();
- return next;
- }
-
- public int numArgs() {
- return args.length;
- }
-
- public String getArg(int index) {
- return args[index];
- }
-
- public boolean hasNext() {
- return curIndex < args.length;
- }
-
- public String getCurrentArg() {
- if (hasNext()) {
- return args[curIndex];
- } else {
- return null;
- }
- }
-
- public Iterator<String> iterator() {
- return new Iterator<String>() {
-
- public boolean hasNext() {
- return Args.this.hasNext();
- }
-
- public String next() {
- if (!hasNext()) {
- throw new IndexOutOfBoundsException(curIndex + "");
- }
- return getAndIncrement();
- }
-
- public void remove() {
- // do nothing
- }
+ curIndex = 0;
+ this.args = args;
+ }
+
+ public String[] getArgs() {
+ return args;
+ }
+
+ public String[] getArgsLeft() {
+ return Arrays.copyOfRange(args, curIndex, args.length);
+ }
+
+ public int getCurrentIndex() {
+ return curIndex;
+ }
+
+ public void incrementIndex() {
+ curIndex++;
+ }
+
+ public void descrementIndex() {
+ curIndex--;
+ }
+
+ public String incrementAndGet() {
+ incrementIndex();
+ return getCurrentArg();
+ }
+
+ public String getAndIncrement() {
+ String next = getCurrentArg();
+ incrementIndex();
+ return next;
+ }
+
+ public int numArgs() {
+ return args.length;
+ }
+
+ public String getArg(int index) {
+ return args[index];
+ }
+
+ public boolean hasNext() {
+ return curIndex < args.length;
+ }
+
+ public String getCurrentArg() {
+ if (hasNext()) {
+ return args[curIndex];
+ } else {
+ return null;
+ }
+ }
+
+ public Iterator<String> iterator() {
+ return new Iterator<String>() {
+
+ public boolean hasNext() {
+ return Args.this.hasNext();
+ }
+
+ public String next() {
+ if (!hasNext()) {
+ throw new IndexOutOfBoundsException(curIndex + "");
+ }
+ return getAndIncrement();
+ }
+
+ public void remove() {
+ // do nothing
+ }
- };
- }
+ };
+ }
}