Index: lutincommandline/src/java/org/codelutin/option/def/DefinitionParserUtil.java diff -u lutincommandline/src/java/org/codelutin/option/def/DefinitionParserUtil.java:1.2 lutincommandline/src/java/org/codelutin/option/def/DefinitionParserUtil.java:1.3 --- lutincommandline/src/java/org/codelutin/option/def/DefinitionParserUtil.java:1.2 Sun Mar 16 03:49:49 2008 +++ lutincommandline/src/java/org/codelutin/option/def/DefinitionParserUtil.java Sun Mar 23 00:21:15 2008 @@ -42,47 +42,12 @@ public static final Character[] OPENING_CHARS = {'(', '{', '[', '<'}; public static final Character[] CLOSING_CHARS = {')', '}', ']', '>'}; - + final static String ODEFINITION_KEY_SUFFIX = ".option.definition"; final static String CDEFINITION_KEY_FACTOR = ".config.definition."; final static String CMODIFIERS_KEY_FACTOR = ".config.modifiers."; /** - * permet de définir le type de source pour lire les définitions à analyser. - *

- * Pour le moment seul le type {@link #properties} est implanté. - * - * @author chemit - */ - public enum TypeSource { - /** pour lire à partir d'un fichier de propriétés (mode par défaut). */ - properties(DefinitionParserFromProperties.class), - /** pour lire à partir d'un fichier xml (pas implanter). */ - xml(null), - /** pour lire depuis un InputReader (pas implanter) */ - console(null); - - private Class impl; - - TypeSource(Class aClass) { - this.impl = aClass; - } - - public DefinitionParser newParserInstance() { - if (impl == null) { - throw new IllegalArgumentException(_("lutinutil.parserdef.notimplemented.sourceType")); - } - try { - return impl.newInstance(); - } catch (InstantiationException e) { - throw new RuntimeException(e); - } catch (IllegalAccessException e) { - throw new RuntimeException(e); - } - } - } - - /** * Classe abstraite définissant un context de parser de définitions. * * @author tony @@ -129,7 +94,7 @@ private static final long serialVersionUID = -5430904379928407190L; String def; String mods; - //TODO use only one entry for a config property + //TODO use only one entry for a config property public ConfigDefEntry(String key, String value) { super(key, value); } @@ -138,7 +103,7 @@ static class OptionDefEntry extends AbstractMap.SimpleEntry { private static final long serialVersionUID = -5430904379928407190L; String def; - String mods; + String mods; public OptionDefEntry(String key, String value) { super(key, value); } @@ -162,8 +127,7 @@ for (int j = 0, j1 = option.getContexts().size(); j < j1; j++) { GroupContext group = option.getContexts().get(j); enterGroup(group, j); - for (int k = 0, k1 = group.getContexts().size(); k < k1; k++) - { + for (int k = 0, k1 = group.getContexts().size(); k < k1; k++) { enterArgument(group.getContexts().get(k), k); } exitGroup(group, j); Index: lutincommandline/src/java/org/codelutin/option/def/DefinitionParser.java diff -u lutincommandline/src/java/org/codelutin/option/def/DefinitionParser.java:1.3 lutincommandline/src/java/org/codelutin/option/def/DefinitionParser.java:1.4 --- lutincommandline/src/java/org/codelutin/option/def/DefinitionParser.java:1.3 Sun Mar 16 07:11:27 2008 +++ lutincommandline/src/java/org/codelutin/option/def/DefinitionParser.java Sun Mar 23 00:21:15 2008 @@ -25,17 +25,15 @@ import static org.codelutin.option.def.DefinitionParserContexts.ConfigContext; import static org.codelutin.option.def.DefinitionParserContexts.OptionContext; import static org.codelutin.option.def.DefinitionParserContexts.ParserContext; -import static org.codelutin.option.def.DefinitionParserUtil.TypeSource; import java.io.IOException; import java.io.Writer; -import java.util.Arrays; /** * Parseur de définitions. TODO Revoir javadoc non correcte *

* La classe contient une méthode statique publique : - * {@link #doParse(org.codelutin.option.def.DefinitionParserUtil.TypeSource ,Object)} + * {@link #doParse(Class,Object)} * pour lancer un parsing sur une source de définitions donnée. *

* Dans ce fichier chaque option est représentée par 1 entrée : @@ -51,36 +49,6 @@ protected static final Log log = LogFactory.getLog(DefinitionParser.class); /** - * les propriétés de configuration obligatoires. - * - * @author chemit - */ - public enum MandatoryConfigProperty { - configFileName("main", "java.io.File"), - version("main", "org.codelutin.util.VersionNumber"); - - private final String category; - private final String type; - - MandatoryConfigProperty(String type, String category) { - this.type = type; - this.category = category; - } - - public String category() { - return category; - } - - public String type() { - return type; - } - - public String getEntryKey() { - return category() + '.' + DefinitionParserUtil.CDEFINITION_KEY_FACTOR + name(); - } - } - - /** * Initialise le parser avec son context remplit avec les données de la source. * * @param source la source de donnée @@ -101,18 +69,20 @@ * @param type le type de source à traiter. * @param src la source contenant les définitions des options * @return le parseur après parsing du fichier - * @throws IOException if any problem when reading source + * @throws IOException if any problem when reading source + * @throws IllegalAccessException if pb while init + * @throws InstantiationException if pb while init */ - public static DefinitionParser doParse(TypeSource type, Object src) throws IOException { + public static

P doParse(Class

type, Object src) throws IOException, IllegalAccessException, InstantiationException { if (type == null) { - throw new IllegalArgumentException(_("lutinutil.parserdef.null.sourceType", type, Arrays.toString(TypeSource.values()))); + throw new IllegalArgumentException(_("lutinutil.parserdef.null.sourceType")); } if (src == null) { throw new IllegalArgumentException(_("lutinutil.parserdef.null.source")); } // obtain instance of implementation of parser - DefinitionParser parser = type.newParserInstance(); + P parser = type.newInstance(); // init parser parser : reading from source ParserContext context = parser.init(src); Index: lutincommandline/src/java/org/codelutin/option/def/MandatoryConfigProperty.java diff -u /dev/null lutincommandline/src/java/org/codelutin/option/def/MandatoryConfigProperty.java:1.1 --- /dev/null Sun Mar 23 00:21:21 2008 +++ lutincommandline/src/java/org/codelutin/option/def/MandatoryConfigProperty.java Sun Mar 23 00:21:15 2008 @@ -0,0 +1,72 @@ +/** + * # #% Copyright (C) 2008 Code Lutin, Tony Chemit + * This program is free software; you + * can redistribute it and/or modify it under the terms of the GNU General + * Public License as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. This program is + * distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A + * PARTICULAR PURPOSE. See the GNU General Public License for more details. You + * should have received a copy of the GNU General Public License along with this + * program; if not, write to the Free Software Foundation, Inc., 59 Temple Place + * - Suite 330, Boston, MA 02111-1307, USA. + * # #% + */ +package org.codelutin.option.def; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +/** + * les propriétés de configuration obligatoires. + * + * @author chemit + */ +public enum MandatoryConfigProperty { + + /** le nom du fichier de configuration de l'application */ + configFileName("java.io.File"), + + /** l'encoding a utiliser sur le systeme */ + encoding("java.lang.String"), + + /** la locale par default à utiliser */ + locale("java.util.Locale"), + + /** le nom du projet */ + projectName("java.lang.String"), + + /** la version du projet */ + version("org.codelutin.util.VersionNumber"); + + private final String type; + + private MandatoryConfigProperty(String type) { + this.type = type; + } + + public String category() { + return "main"; + } + + public String type() { + return type; + } + + public String getEntryKey() { + return category() + '.' + DefinitionParserUtil.CDEFINITION_KEY_FACTOR + name(); + } + + public static List getConfigPropertyKeys() { + List list = new ArrayList(); + if (!DefaultOptionAction.skipDefault) { + for (MandatoryConfigProperty option : MandatoryConfigProperty.values()) { + list.add(option.getEntryKey()); + } + Collections.sort(list); + } + return list; + } + +}