Index: lutinutil/src/java/org/codelutin/option/OptionKey.java diff -u lutinutil/src/java/org/codelutin/option/OptionKey.java:1.1 lutinutil/src/java/org/codelutin/option/OptionKey.java:1.2 --- lutinutil/src/java/org/codelutin/option/OptionKey.java:1.1 Sun Dec 30 22:50:46 2007 +++ lutinutil/src/java/org/codelutin/option/OptionKey.java Mon Dec 31 05:26:36 2007 @@ -22,6 +22,7 @@ import java.lang.reflect.Constructor; import java.lang.reflect.Modifier; +import java.util.ArrayList; import java.util.List; /** @@ -58,6 +59,9 @@ /** la classe abstraite de l'action de l'option liée */ final protected Class abstractActionClass; + /** la liste des options instanciées lors du dernier parsing */ + final protected List options; + /** le constructeur d'option à utilisé */ protected Constructor optionConstructor; @@ -78,6 +82,7 @@ // we have a concrete action class actionClass = abstractActionClass; } + this.options = new ArrayList(); } public String getOptionKey() { @@ -108,24 +113,8 @@ return definition; } - /** - * Instanciate a new option - * - * @param alias the option alias - * @param args the arguments of the option - * @return the instanciated option - */ - public O newOption(String alias, List args) { - try { - if (optionConstructor == null) { - optionConstructor = optionClass.getConstructor(String.class, Argument[].class); - } - O result; - result = optionConstructor.newInstance(alias, args.toArray(new Argument[args.size()])); - return result; - } catch (Exception e) { - throw new RuntimeException(e); - } + public List getOptions() { + return options; } /** @@ -141,13 +130,23 @@ } } + protected void resetOptions() { + options.clear(); + } + + protected O addOption(String alias, List args) { + O o = newOption(alias, args); + options.add(o); + return o; + } + /** * Get the shared action linked with this key. * * @param parser the parser used * @return the share action's instance */ - public synchronized A getAction(P parser) { + protected A getAction(P parser) { if (action == null) { if (actionClass == null) { throw new IllegalStateException("no concrete action found for " + abstractActionClass); @@ -160,4 +159,24 @@ } return action; } + + /** + * Instanciate a new option + * + * @param alias the option alias + * @param args the arguments of the option + * @return the instanciated option + */ + protected O newOption(String alias, List args) { + try { + if (optionConstructor == null) { + optionConstructor = optionClass.getConstructor(String.class, Argument[].class); + } + O result; + result = optionConstructor.newInstance(alias, args.toArray(new Argument[args.size()])); + return result; + } catch (Exception e) { + throw new RuntimeException(e); + } + } }