* \r
* @author pvtroshin\r
* \r
- * Date December 2009\r
+ * @version 1.0 December 2009\r
* @param <T>\r
* type of executable.\r
*/\r
@XmlAccessorType(XmlAccessType.FIELD)\r
public class PresetManager<T> {\r
\r
- @XmlElement(required = true)\r
- String runnerClassName;\r
-\r
- @XmlElement(required = true)\r
- List<Preset<T>> preset;\r
-\r
- public static final String LOCAL_ENGINE_LIMIT_PRESET = "# LocalEngineExecutionLimit #";\r
-\r
- public List<Preset<T>> getPresets() {\r
- return preset;\r
- }\r
-\r
- public void setPresets(List<Preset<T>> presets) {\r
- this.preset = presets;\r
- }\r
-\r
- /**\r
- * \r
- * @return fully qualified class name of type T\r
- */\r
- public String getRunnerClassName() {\r
- return runnerClassName;\r
- }\r
-\r
- public void setRunnerClassName(String runnerClassName) {\r
- this.runnerClassName = runnerClassName;\r
- }\r
-\r
- /**\r
- * \r
- * @param presetName\r
- * @return preset by its name, null if no preset found\r
- */\r
- public Preset<T> getPresetByName(String presetName) {\r
- for (Preset<T> p : preset) {\r
- if (p.getName().equalsIgnoreCase(presetName)) {\r
- return p;\r
- }\r
+ @XmlElement(required = true)\r
+ String runnerClassName;\r
+\r
+ @XmlElement(required = true)\r
+ List<Preset<T>> preset;\r
+\r
+ public static final String LOCAL_ENGINE_LIMIT_PRESET = "# LocalEngineExecutionLimit #";\r
+\r
+ public List<Preset<T>> getPresets() {\r
+ return preset;\r
}\r
- return null;\r
- }\r
-\r
- boolean isComposite(String value) {\r
- assert value != null;\r
- return value.contains(" ");\r
- }\r
-\r
- boolean containsValue(List<String> values, String value) {\r
- assert !Util.isEmpty(value);\r
- for (String v : values) {\r
- if (v.equals(value)) {\r
- return true;\r
- }\r
+\r
+ public void setPresets(List<Preset<T>> presets) {\r
+ this.preset = presets;\r
+ }\r
+\r
+ /**\r
+ * \r
+ * @return fully qualified class name of type T\r
+ */\r
+ public String getRunnerClassName() {\r
+ return runnerClassName;\r
}\r
- return false;\r
- }\r
-\r
- boolean isNumeric(String value) {\r
- assert value != null;\r
- try {\r
- Double.parseDouble(value);\r
- return true;\r
- } catch (NumberFormatException e) {\r
- // ignore\r
- return false;\r
+\r
+ public void setRunnerClassName(String runnerClassName) {\r
+ this.runnerClassName = runnerClassName;\r
}\r
- }\r
-\r
- /**\r
- * Checks whether preset option and parameter are defined in RunnerConfig\r
- * object.\r
- * \r
- * TODO handle parameters with values properly!\r
- * \r
- * @throws ValidationException\r
- * if preset is found to be invalid.\r
- * \r
- */\r
- public void validate(RunnerConfig<T> options) throws ValidationException {\r
- for (Preset<T> p : preset) {\r
- if (Util.isEmpty(p.name)) {\r
- throw new ValidationException("Preset name must not be empty!");\r
- }\r
- List<String> optionNames = p.getOptions();\r
- if (optionNames == null || optionNames.size() == 0) {\r
- throw new ValidationException(\r
- "At lease one option must be defined for a preset!");\r
- }\r
- for (String oName : optionNames) {\r
- if (isComposite(oName)) {\r
- String name = oName.split(" ")[0];\r
- Argument<T> arg = getArgument(options, name);\r
- String value = oName.split(" ")[1];\r
- // Ignore numeric values\r
- if (!isNumeric(value)\r
- && !containsValue(arg.getPossibleValues(), value)) {\r
- throw new ValidationException("Value " + value\r
- + " is not found in the option " + name);\r
- }\r
- } else {\r
- getArgument(options, oName);\r
+\r
+ /**\r
+ * \r
+ * @param presetName\r
+ * @return preset by its name, null if no preset found\r
+ */\r
+ public Preset<T> getPresetByName(String presetName) {\r
+ for (Preset<T> p : preset) {\r
+ if (p.getName().equalsIgnoreCase(presetName)) {\r
+ return p;\r
+ }\r
}\r
- }\r
+ return null;\r
+ }\r
+\r
+ boolean isComposite(String value) {\r
+ assert value != null;\r
+ return value.contains(" ");\r
}\r
- }\r
-\r
- Argument<T> getArgument(RunnerConfig<T> options, String optionName)\r
- throws ValidationException {\r
- Argument<T> arg = options.getArgumentByOptionName(optionName);\r
- if (arg == null) {\r
- throw new ValidationException(\r
- "Option "\r
- + optionName\r
- + " is not found in the option list (<RunnerName>Parameter.xml file)");\r
+\r
+ boolean containsValue(List<String> values, String value) {\r
+ assert !Util.isEmpty(value);\r
+ for (String v : values) {\r
+ if (v.equals(value)) {\r
+ return true;\r
+ }\r
+ }\r
+ return false;\r
}\r
- return arg;\r
- }\r
-\r
- @Override\r
- public String toString() {\r
- String value = "Runner: " + this.runnerClassName;\r
- for (Preset<T> p : preset) {\r
- value += p.toString() + "\n";\r
+\r
+ boolean isNumeric(String value) {\r
+ assert value != null;\r
+ try {\r
+ Double.parseDouble(value);\r
+ return true;\r
+ } catch (NumberFormatException e) {\r
+ // ignore\r
+ return false;\r
+ }\r
+ }\r
+\r
+ /**\r
+ * Checks whether preset option and parameter are defined in RunnerConfig\r
+ * object.\r
+ * \r
+ * TODO handle parameters with values properly!\r
+ * \r
+ * @throws ValidationException\r
+ * if preset is found to be invalid.\r
+ * \r
+ */\r
+ public void validate(RunnerConfig<T> options) throws ValidationException {\r
+ for (Preset<T> p : preset) {\r
+ if (Util.isEmpty(p.name)) {\r
+ throw new ValidationException("Preset name must not be empty!");\r
+ }\r
+ List<String> optionNames = p.getOptions();\r
+ if (optionNames == null || optionNames.size() == 0) {\r
+ throw new ValidationException(\r
+ "At lease one option must be defined for a preset!");\r
+ }\r
+ for (String oName : optionNames) {\r
+ if (isComposite(oName)) {\r
+ String name = oName.split(" ")[0];\r
+ Argument<T> arg = getArgument(options, name);\r
+ String value = oName.split(" ")[1];\r
+ // Ignore numeric values\r
+ if (!isNumeric(value)\r
+ && !containsValue(arg.getPossibleValues(), value)) {\r
+ throw new ValidationException("Value " + value\r
+ + " is not found in the option " + name);\r
+ }\r
+ } else {\r
+ getArgument(options, oName);\r
+ }\r
+ }\r
+ }\r
+ }\r
+\r
+ Argument<T> getArgument(RunnerConfig<T> options, String optionName)\r
+ throws ValidationException {\r
+ Argument<T> arg = options.getArgumentByOptionName(optionName);\r
+ if (arg == null) {\r
+ throw new ValidationException(\r
+ "Option "\r
+ + optionName\r
+ + " is not found in the option list (<RunnerName>Parameter.xml file)");\r
+ }\r
+ return arg;\r
+ }\r
+\r
+ @Override\r
+ public String toString() {\r
+ String value = "Runner: " + this.runnerClassName;\r
+ for (Preset<T> p : preset) {\r
+ value += p.toString() + "\n";\r
+ }\r
+ return value;\r
}\r
- return value;\r
- }\r
\r
}\r