Index: lutinutil/src/java/org/codelutin/util/OptionDefinitionFactory.java diff -u lutinutil/src/java/org/codelutin/util/OptionDefinitionFactory.java:1.1 lutinutil/src/java/org/codelutin/util/OptionDefinitionFactory.java:1.2 --- lutinutil/src/java/org/codelutin/util/OptionDefinitionFactory.java:1.1 Mon Nov 19 19:53:30 2007 +++ lutinutil/src/java/org/codelutin/util/OptionDefinitionFactory.java Wed Nov 28 01:23:13 2007 @@ -1,25 +1,37 @@ +/* *##% +* Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007 Code Lutin, +* Cédric Pineau, Benjamin Poussin, +* +* +* 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.util; -import org.apache.commons.collections.map.ReferenceMap; -import static org.codelutin.i18n.I18n._; -import static org.codelutin.util.OptionDefinitionParser.LUTINUTIL_PARSERDEF_PRINT_DETAIL_OPTION_HEAD; - -import java.io.IOException; -import java.io.Writer; import java.util.ArrayList; -import java.util.Collections; import java.util.List; -import java.util.Map; /** - * Factory de définitions d'options. + * Usine de définitions d'options. *
- * Cette classe servira de super classe à la Factory generee par le parseur - * de définition, la genetation consiste a implanter la methode init pour - * initialiser la map d'option. + * Cette classe servira de super classe à l'usine générée par le plugin + *maven-commandline-plugin:generate.
+ * l'implantation consiste a implanter la methode init pour initialiser
+ * la map d'options et à ajouter comme constantes les clefs d'options utilisées.
*
- * Elle contient une méthode pour récupérer une factory initialisée à partir
- * de sa classe {@link #newFactory(Class)}.
+ * Elle contient une méthode publique statique pour récupérer une factory
+ * initialisée à partir de sa classe {@link #newFactory(String, ClassLoader)}.
*
* @author chemit
*/
@@ -27,78 +39,47 @@
public abstract class OptionDefinitionFactory {
/**
- * @param clazz class of the factory to get
+ * @param className fully qualified name of the factory class
+ * @param loader the class loader to use to find class
* @return an instance of the required factory, initialize.
- * @throws InstantiationException if error while instanciate factory
- * @throws IllegalAccessException if can not access class
*/
- public static OptionDefinitionFactory newFactory(
- Class extends OptionDefinitionFactory> clazz)
- throws InstantiationException, IllegalAccessException {
-
- // instanciate the factory
- OptionDefinitionFactory factor = clazz.newInstance();
-
- // init factory (this is the generated method)
- factor.init();
-
- return factor;
+ public static OptionDefinitionFactory newFactory(String className,
+ ClassLoader loader) {
+ try {
+ // get factory class
+ Class clazz = Class.forName(className, true, loader);
+ // instanciate the factory
+ OptionDefinitionFactory factor = (OptionDefinitionFactory) clazz.newInstance();
+ // init factory (this is the generated method)
+ factor.init();
+ // return factory
+ return factor;
+ } catch (ClassNotFoundException e) {
+ throw new IllegalArgumentException(e);
+ } catch (InstantiationException e) {
+ throw new IllegalArgumentException(e);
+ } catch (IllegalAccessException e) {
+ throw new IllegalArgumentException(e);
+ }
}
/**
* La methode a implanter pour initialiser la factory.
*
- * Il s'agit de remplir {@link #options} avec des {@link OptionDefinition}
+ * Il s'agit de remplir {@link #definitions} avec des
+ * {@link OptionDefinition}.
*/
public abstract void init();
- /** les options enregistrees dans la factory indexees par leur nom unique */
- protected final Map