Index: lutinutil/src/java/org/codelutin/util/OptionParser.java diff -u lutinutil/src/java/org/codelutin/util/OptionParser.java:1.3 lutinutil/src/java/org/codelutin/util/OptionParser.java:1.4 --- lutinutil/src/java/org/codelutin/util/OptionParser.java:1.3 Wed Nov 28 17:21:09 2007 +++ lutinutil/src/java/org/codelutin/util/OptionParser.java Wed Nov 28 20:02:12 2007 @@ -78,68 +78,73 @@ } } - public static OptionKeyFactory getKeyFactory() { - if (keyFactory == null) { - keyFactory = new OptionKeyFactory(); - } - return keyFactory; - } - final org.apache.commons.logging.Log log; - /** - * le context du parseur : contient tous les index nécessaires pendant le - * parsing. - */ + /** le context du parseur (contenant les données temporaires du parsing). */ protected final ParserContext context; - protected final InitialContext initialContext; + /** la liste des définitions d'options connues */ + protected final Map definitions; - protected static OptionKeyFactory keyFactory; + /** + * la liste des options, la cle est le nom de l'option, et la valeur + * est la liste des options qui ont été lues grâce à celle-ci. + */ + protected final HashMap> options; + + /** + * La liste des arguments qui ne sont pas des options insérés dans leur + * ordre d'apparition dans la ligne de commande + */ + protected final List arguments; public OptionParser() { // find the fullyQualifiedFactoryName via OptionParserA annotation OptionParserA def = getClass().getAnnotation(OptionParserA.class); if (def == null) { - //TODO - throw new IllegalArgumentException("could not found annotation " + OptionParserA.class + " in Parser " + this); + //TODO i18n + throw new IllegalArgumentException("could not found annotation " + + OptionParserA.class + " in Parser " + this); } log = LogFactory.getLog(getClass()); - getKeyFactory(); + this.definitions = new LinkedHashMap(); + this.arguments = new ArrayList(); + this.options = new HashMap>(); try { - Map map; + Map map; OptionDefinitionA defA; OptionDefinition definition; - map = new HashMap(); + map = new HashMap(); for (String key : def.keys()) { String fieldName = StringUtil.convertToConstantName(key); Field field = getClass().getField(fieldName); - OptionKeyFactory.OptionKey optionKey = (OptionKeyFactory.OptionKey) field.get(this); - defA = field.getAnnotation(OptionDefinitionA.class); definition = new OptionDefinition(defA); - map.put(optionKey, definition); + map.put(key, definition); } - - initialContext = new InitialContext(map); + List keys1 = new ArrayList(map.keySet()); + Collections.sort(keys1); + for (String key : keys1) { + this.definitions.put(key, map.get(key)); + } + keys1.clear(); + map.clear(); // create parser context - context = new ParserContext(); - + context = new ParserContext(this.definitions); + } catch (NoSuchFieldException e) { throw new IllegalArgumentException(e); - } catch (IllegalAccessException e) { - throw new IllegalArgumentException(e); } } - public OptionParser doParse(String... args) throws OptionParserException { + public void doParse(String... args) throws OptionParserException { if (args.length > 0) { // detect OptionContexts prepareContexts(args); @@ -157,38 +162,36 @@ //TODO Report errors from context before clear context context.clear(); - - // return parser - return this; } - public boolean isEnabled(OptionKeyFactory.OptionKey key) { - List